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 "locale/japanese.h"
30 #include "main/sound-definitions-table.h"
31 #include "main/sound-of-music.h"
32 #include "object-hook/hook-magic.h"
33 #include "object/item-tester-hooker.h"
34 #include "object/item-use-flags.h"
35 #include "object/object-info.h"
36 #include "player-base/player-class.h"
37 #include "player-info/class-info.h"
38 #include "player-info/samurai-data-type.h"
39 #include "player-info/self-info.h"
40 #include "player-status/player-energy.h"
41 #include "player/attack-defense-types.h"
42 #include "player/eldritch-horror.h"
43 #include "player/player-damage.h"
44 #include "player/player-realm.h"
45 #include "player/player-skill.h"
46 #include "player/player-status.h"
47 #include "player/special-defense-types.h"
48 #include "realm/realm-names-table.h"
49 #include "spell-kind/spells-random.h"
50 #include "spell-kind/spells-sight.h"
51 #include "spell-realm/spells-hex.h"
52 #include "spell/range-calc.h"
53 #include "spell/spell-info.h"
54 #include "spell/spells-describer.h"
55 #include "spell/spells-execution.h"
56 #include "spell/spells-summon.h"
57 #include "spell/technic-info-table.h"
58 #include "status/action-setter.h"
59 #include "status/bad-status-setter.h"
60 #include "status/base-status.h"
61 #include "status/experience.h"
62 #include "system/floor-type-definition.h"
63 #include "system/object-type-definition.h"
64 #include "system/player-type-definition.h"
65 #include "term/screen-processor.h"
66 #include "util/bit-flags-calculator.h"
67 #include "util/buffer-shaper.h"
68 #include "util/int-char-converter.h"
69 #include "view/display-messages.h"
71 static const int extra_magic_gain_exp = 4;
73 concptr KWD_DAM = _("損傷:", "dam ");
74 concptr KWD_RANGE = _("射程:", "rng ");
75 concptr KWD_DURATION = _("期間:", "dur ");
76 concptr KWD_SPHERE = _("範囲:", "range ");
77 concptr KWD_HEAL = _("回復:", "heal ");
78 concptr KWD_MANA = _("MP回復:", "heal SP ");
79 concptr KWD_POWER _("効力:", "power ");
80 concptr KWD_RANDOM = _("ランダム", "random");
84 * Zangband uses this array instead of the spell flags table, as there
85 * are 5 realms of magic, each with 4 spellbooks and 8 spells per book -- TY
87 const uint32_t fake_spell_flags[4] = { 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 };
91 * 魔法の効果を「キャプション:ダイス+定数値」のフォーマットで出力する / Generate dice info string such as "foo 2d10"
96 * @return フォーマットに従い整形された文字列
98 concptr info_string_dice(concptr str, DICE_NUMBER dice, DICE_SID sides, int base)
102 return format("%s%d", str, base);
106 return format("%s%dd%d", str, dice, sides);
108 /* Dice plus base value */
110 return format("%s%dd%d%+d", str, dice, sides, base);
114 * @brief 魔法によるダメージを出力する / Generate damage-dice info string such as "dam 2d10"
118 * @return フォーマットに従い整形された文字列
120 concptr info_damage(DICE_NUMBER dice, DICE_SID sides, int base)
122 return info_string_dice(_("損傷:", "dam "), dice, sides, base);
126 * @brief 魔法の効果時間を出力する / Generate duration info string such as "dur 20+1d20"
129 * @return フォーマットに従い整形された文字列
131 concptr info_duration(int base, DICE_SID sides)
133 return format(_("期間:%d+1d%d", "dur %d+1d%d"), base, sides);
137 * @brief 魔法の効果範囲を出力する / Generate range info string such as "range 5"
139 * @return フォーマットに従い整形された文字列
141 concptr info_range(POSITION range)
143 return format(_("範囲:%d", "range %d"), range);
147 * @brief 魔法による回復量を出力する / Generate heal info string such as "heal 2d8"
151 * @return フォーマットに従い整形された文字列
153 concptr info_heal(DICE_NUMBER dice, DICE_SID sides, int base)
155 return info_string_dice(_("回復:", "heal "), dice, sides, base);
159 * @brief 魔法効果発動までの遅延ターンを出力する / Generate delay info string such as "delay 15+1d15"
162 * @return フォーマットに従い整形された文字列
164 concptr info_delay(int base, DICE_SID sides)
166 return format(_("遅延:%d+1d%d", "delay %d+1d%d"), base, sides);
170 * @brief 魔法によるダメージを出力する(固定値&複数回処理) / Generate multiple-damage info string such as "dam 25 each"
172 * @return フォーマットに従い整形された文字列
174 concptr info_multi_damage(HIT_POINT dam)
176 return format(_("損傷:各%d", "dam %d each"), dam);
180 * @brief 魔法によるダメージを出力する(ダイスのみ&複数回処理) / Generate multiple-damage-dice info string such as "dam 5d2 each"
183 * @return フォーマットに従い整形された文字列
185 concptr info_multi_damage_dice(DICE_NUMBER dice, DICE_SID sides)
187 return format(_("損傷:各%dd%d", "dam %dd%d each"), dice, sides);
191 * @brief 魔法による一般的な効力値を出力する(固定値) / Generate power info string such as "power 100"
193 * @return フォーマットに従い整形された文字列
195 concptr info_power(int power)
197 return format(_("効力:%d", "power %d"), power);
201 * @brief 魔法による一般的な効力値を出力する(ダイス値) / Generate power info string such as "power 100"
204 * @return フォーマットに従い整形された文字列
207 * Generate power info string such as "power 1d100"
209 concptr info_power_dice(DICE_NUMBER dice, DICE_SID sides)
211 return format(_("効力:%dd%d", "power %dd%d"), dice, sides);
215 * @brief 魔法の効果半径を出力する / Generate radius info string such as "rad 100"
217 * @return フォーマットに従い整形された文字列
219 concptr info_radius(POSITION rad)
221 return format(_("半径:%d", "rad %d"), rad);
225 * @brief 魔法効果の限界重量を出力する / Generate weight info string such as "max wgt 15"
227 * @return フォーマットに従い整形された文字列
229 concptr info_weight(WEIGHT weight)
232 return format("最大重量:%d.%dkg", lb_to_kg_integer(weight), lb_to_kg_fraction(weight));
234 return format("max wgt %d", weight / 10);
239 * @brief 魔法が利用可能かどうかを返す /
240 * Determine if a spell is "okay" for the player to cast or study
241 * The spell must be legible, not forgotten, and also, to cast,
242 * it must be known, and to study, it must not be known.
244 * @param learned 使用可能な判定ならばTRUE、学習可能かどうかの判定ならばFALSE
245 * @param study_pray 祈りの学習判定目的ならばTRUE
246 * @param use_realm 魔法領域ID
249 static bool spell_okay(PlayerType *player_ptr, int spell, bool learned, bool study_pray, int use_realm)
251 const magic_type *s_ptr;
253 /* Access the spell */
254 if (!is_magic(use_realm)) {
255 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
257 s_ptr = &mp_ptr->info[use_realm - 1][spell];
260 /* Spell is illegal */
261 if (s_ptr->slevel > player_ptr->lev)
264 /* Spell is forgotten */
265 if ((use_realm == player_ptr->realm2) ? (player_ptr->spell_forgotten2 & (1UL << spell)) : (player_ptr->spell_forgotten1 & (1UL << spell))) {
270 if (PlayerClass(player_ptr).is_every_magic()) {
274 /* Spell is learned */
275 if ((use_realm == player_ptr->realm2) ? (player_ptr->spell_learned2 & (1UL << spell)) : (player_ptr->spell_learned1 & (1UL << spell))) {
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(PlayerType *player_ptr, SPELL_IDX *sn, concptr prompt, OBJECT_SUBTYPE_VALUE sval, bool learned, int16_t 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(player_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(player_ptr, spells[i], learned, false, use_realm))
354 /* No "okay" spells */
358 PlayerClass pc(player_ptr);
359 auto is_every_magic = pc.is_every_magic();
360 if (((use_realm) != player_ptr->realm1) && ((use_realm) != player_ptr->realm2) && !is_every_magic)
362 if (is_every_magic && !is_magic(use_realm))
364 if (pc.equals(PlayerClassType::RED_MAGE) && ((use_realm) != REALM_ARCANE) && (sval > 1))
367 /* Assume cancelled */
373 player_ptr->window_flags |= (PW_SPELL);
374 handle_stuff(player_ptr);
376 /* Build a prompt (accept all spells) */
378 jverb(prompt, jverb_buf, JVERB_AND);
379 (void)strnfmt(out_val, 78, "(%^s:%c-%c, '*'で一覧, ESCで中断) どの%sを%^sますか? ", p, I2A(0), I2A(num - 1), p, jverb_buf);
381 (void)strnfmt(out_val, 78, "(%^ss %c-%c, *=List, ESC=exit) %^s which %s? ", p, I2A(0), I2A(num - 1), prompt, p);
384 choice = (always_show_list || use_menu) ? ESCAPE : 1;
386 if (choice == ESCAPE)
388 else if (!get_com(out_val, &choice, true))
391 if (use_menu && choice != ' ') {
401 menu_line += (num - 1);
423 /* Display a list of spells */
424 print_spells(player_ptr, menu_line, spells, num, 1, 15, use_realm);
429 if ((choice == ' ') || (choice == '*') || (choice == '?')) {
435 /* Display a list of spells */
436 print_spells(player_ptr, menu_line, spells, num, 1, 15, use_realm);
454 ask = (isupper(choice));
458 choice = (char)tolower(choice);
460 /* Extract request */
461 i = (islower(choice) ? A2I(choice) : -1);
464 /* Totally Illegal */
465 if ((i < 0) || (i >= num)) {
470 /* Save the spell index */
473 /* Require "okay" spells */
474 if (!spell_okay(player_ptr, spell, learned, false, use_realm)) {
477 msg_format("その%sを%sことはできません。", p, prompt);
479 msg_format("You may not %s that %s.", prompt, p);
489 /* Access the spell */
490 if (!is_magic(use_realm)) {
491 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
493 s_ptr = &mp_ptr->info[use_realm - 1][spell];
496 /* Extract mana consumption rate */
497 if (use_realm == REALM_HISSATSU) {
498 need_mana = s_ptr->smana;
500 need_mana = mod_need_mana(player_ptr, s_ptr->smana, spell, use_realm);
505 jverb(prompt, jverb_buf, JVERB_AND);
507 (void)strnfmt(tmp_val, 78, "%s(MP%d, 失敗率%d%%)を%sますか? ", exe_spell(player_ptr, use_realm, spell, SpellProcessType::NAME), need_mana,
508 spell_chance(player_ptr, spell, use_realm), jverb_buf);
510 (void)strnfmt(tmp_val, 78, "%^s %s (%d mana, %d%% fail)? ", prompt, exe_spell(player_ptr, use_realm, spell, SpellProcessType::NAME), need_mana,
511 spell_chance(player_ptr, spell, use_realm));
514 /* Belay that order */
515 if (!get_check(tmp_val))
526 player_ptr->window_flags |= (PW_SPELL);
527 handle_stuff(player_ptr);
529 /* Abort if needed */
533 /* Save the choice */
536 repeat_push((COMMAND_CODE)spell);
543 * @brief プレイヤーの職業が練気術師の時、領域魔法と練気術を切り換える処理のインターフェイス
544 * @param browse_only 魔法と技能の閲覧を行うならばTRUE
545 * @return 魔道書を一冊も持っていないならTRUEを返す
547 static void confirm_use_force(PlayerType *player_ptr, bool browse_only)
552 /* Get the item index */
553 if (repeat_pull(&code) && (code == INVEN_FORCE)) {
554 browse_only ? do_cmd_mind_browse(player_ptr) : do_cmd_mind(player_ptr);
558 /* Show the prompt */
559 prt(_("('w'練気術, ESC) 'w'かESCを押してください。 ", "(w for the Force, ESC) Hit 'w' or ESC. "), 0, 0);
567 else if (which == 'w') {
568 repeat_push(INVEN_FORCE);
573 /* Clear the prompt line */
577 browse_only ? do_cmd_mind_browse(player_ptr) : do_cmd_mind(player_ptr);
581 static FuncItemTester get_castable_spellbook_tester(PlayerType *player_ptr)
583 return FuncItemTester([](auto p_ptr, auto o_ptr) { return check_book_realm(p_ptr, o_ptr->tval, o_ptr->sval); }, player_ptr);
586 static FuncItemTester get_learnable_spellbook_tester(PlayerType *player_ptr)
588 if (player_ptr->realm2 == REALM_NONE) {
589 return get_castable_spellbook_tester(player_ptr);
591 return FuncItemTester(item_tester_learn_spell, player_ptr);
596 * @brief プレイヤーの魔法と技能を閲覧するコマンドのメインルーチン /
597 * Peruse the spells/prayers in a book
600 * Note that *all* spells in the book are listed
602 * Note that browsing is allowed while confused or blind,
603 * and in the dark, primarily to allow browsing in stores.
606 void do_cmd_browse(PlayerType *player_ptr)
609 OBJECT_SUBTYPE_VALUE sval;
610 int16_t use_realm = 0;
612 SPELL_IDX spell = -1;
615 SPELL_IDX spells[64];
622 /* Warriors are illiterate */
623 PlayerClass pc(player_ptr);
624 if (!(player_ptr->realm1 || player_ptr->realm2) && !pc.is_every_magic()) {
625 msg_print(_("本を読むことができない!", "You cannot read books!"));
629 pc.break_samurai_stance({ SamuraiStanceType::MUSOU });
631 if (pc.equals(PlayerClassType::FORCETRAINER)) {
632 if (player_has_no_spellbooks(player_ptr)) {
633 confirm_use_force(player_ptr, true);
638 /* Restrict choices to "useful" books */
639 auto item_tester = get_learnable_spellbook_tester(player_ptr);
641 q = _("どの本を読みますか? ", "Browse which book? ");
642 s = _("読める本がない。", "You have no books that you can read.");
644 o_ptr = choose_object(player_ptr, &item, q, s, USE_INVEN | USE_FLOOR | (pc.equals(PlayerClassType::FORCETRAINER) ? USE_FORCE : 0), item_tester);
647 if (item == INVEN_FORCE) /* the_force */
649 do_cmd_mind_browse(player_ptr);
655 /* Access the item's sval */
658 use_realm = tval2realm(o_ptr->tval);
660 /* Track the object kind */
661 object_kind_track(player_ptr, o_ptr->k_idx);
662 handle_stuff(player_ptr);
665 for (spell = 0; spell < 32; spell++) {
666 /* Check for this spell */
667 if ((fake_spell_flags[sval] & (1UL << spell))) {
668 /* Collect this spell */
669 spells[num++] = spell;
676 /* Keep browsing spells. Exit browsing on cancel. */
678 /* Ask for a spell, allow cancel */
679 if (!get_spell(player_ptr, &spell, _("読む", "browse"), o_ptr->sval, true, use_realm)) {
680 /* If cancelled, leave immediately. */
684 /* Display a list of spells */
685 print_spells(player_ptr, 0, spells, num, 1, 15, use_realm);
687 /* Notify that there's nothing to see, and wait. */
688 if (use_realm == REALM_HISSATSU)
689 prt(_("読める技がない。", "No techniques to browse."), 0, 0);
691 prt(_("読める呪文がない。", "No spells to browse."), 0, 0);
699 /* Clear lines, position cursor (really should use strlen here) */
700 term_erase(14, 14, 255);
701 term_erase(14, 13, 255);
702 term_erase(14, 12, 255);
703 term_erase(14, 11, 255);
705 shape_buffer(exe_spell(player_ptr, use_realm, spell, SpellProcessType::DESCRIPTION), 62, temp, sizeof(temp));
707 for (j = 0, line = 11; temp[j]; j += 1 + strlen(&temp[j])) {
708 prt(&temp[j], line, 15);
716 * @brief プレイヤーの第二魔法領域を変更する /
717 * @param player_ptr プレイヤーへの参照ポインタ
718 * @param next_realm 変更先の魔法領域ID
720 static void change_realm2(PlayerType *player_ptr, int16_t next_realm)
725 for (i = 0; i < 64; i++) {
726 player_ptr->spell_order[j] = player_ptr->spell_order[i];
727 if (player_ptr->spell_order[i] < 32)
731 player_ptr->spell_order[j] = 99;
733 for (i = 32; i < 64; i++) {
734 player_ptr->spell_exp[i] = PlayerSkill::spell_exp_at(PlayerSkillRank::UNSKILLED);
736 player_ptr->spell_learned2 = 0L;
737 player_ptr->spell_worked2 = 0L;
738 player_ptr->spell_forgotten2 = 0L;
740 sprintf(tmp, _("魔法の領域を%sから%sに変更した。", "changed magic realm from %s to %s."), realm_names[player_ptr->realm2], realm_names[next_realm]);
741 exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, tmp);
742 player_ptr->old_realm |= 1U << (player_ptr->realm2 - 1);
743 player_ptr->realm2 = next_realm;
745 player_ptr->update |= (PU_REORDER);
746 player_ptr->update |= (PU_SPELLS);
747 handle_stuff(player_ptr);
749 /* Load an autopick preference file */
750 autopick_load_pref(player_ptr, false);
754 * @brief 魔法を学習するコマンドのメインルーチン /
755 * Study a book to gain a new spell/prayer
757 void do_cmd_study(PlayerType *player_ptr)
761 OBJECT_SUBTYPE_VALUE sval;
763 bool learned = false;
765 /* Spells of realm2 will have an increment of +32 */
766 SPELL_IDX spell = -1;
767 concptr p = spell_category_name(mp_ptr->spell_book);
771 if (!player_ptr->realm1) {
772 msg_print(_("本を読むことができない!", "You cannot read books!"));
776 if (cmd_limit_blind(player_ptr))
778 if (cmd_limit_confused(player_ptr))
781 if (!(player_ptr->new_spells)) {
782 msg_format(_("新しい%sを覚えることはできない!", "You cannot learn any new %ss!"), p);
786 PlayerClass(player_ptr).break_samurai_stance({ SamuraiStanceType::MUSOU });
789 if (player_ptr->new_spells < 10) {
790 msg_format("あと %d つの%sを学べる。", player_ptr->new_spells, p);
792 msg_format("あと %d 個の%sを学べる。", player_ptr->new_spells, p);
795 msg_format("You can learn %d new %s%s.", player_ptr->new_spells, p, (player_ptr->new_spells == 1 ? "" : "s"));
800 /* Restrict choices to "useful" books */
801 auto item_tester = get_learnable_spellbook_tester(player_ptr);
803 q = _("どの本から学びますか? ", "Study which book? ");
804 s = _("読める本がない。", "You have no books that you can read.");
806 o_ptr = choose_object(player_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), item_tester);
811 /* Access the item's sval */
814 if (o_ptr->tval == get_realm2_book(player_ptr)) {
816 } else if (o_ptr->tval != get_realm1_book(player_ptr)) {
817 if (!get_check(_("本当に魔法の領域を変更しますか?", "Really, change magic realm? ")))
819 change_realm2(player_ptr, tval2realm(o_ptr->tval));
823 /* Track the object kind */
824 object_kind_track(player_ptr, o_ptr->k_idx);
825 handle_stuff(player_ptr);
827 /* Mage -- Learn a selected spell */
828 if (mp_ptr->spell_book != ItemKindType::LIFE_BOOK) {
829 /* Ask for a spell, allow cancel */
830 if (!get_spell(player_ptr, &spell, _("学ぶ", "study"), sval, false, tval2realm(o_ptr->tval)) && (spell == -1))
834 /* Priest -- Learn a random prayer */
840 for (spell = 0; spell < 32; spell++) {
841 /* Check spells in the book */
842 if ((fake_spell_flags[sval] & (1UL << spell))) {
843 /* Skip non "okay" prayers */
844 if (!spell_okay(player_ptr, spell, false, true, (increment ? player_ptr->realm2 : player_ptr->realm1)))
847 /* Hack -- Prepare the randomizer */
850 /* Hack -- Apply the randomizer */
860 /* Nothing to study */
862 msg_format(_("その本には学ぶべき%sがない。", "You cannot learn any %ss in that book."), p);
871 /* Learn the spell */
873 if (player_ptr->spell_learned1 & (1UL << spell))
876 player_ptr->spell_learned1 |= (1UL << spell);
878 if (player_ptr->spell_learned2 & (1UL << (spell - 32)))
881 player_ptr->spell_learned2 |= (1UL << (spell - 32));
885 auto max_exp = PlayerSkill::spell_exp_at((spell < 32) ? PlayerSkillRank::MASTER : PlayerSkillRank::EXPERT);
886 int old_exp = player_ptr->spell_exp[spell];
887 concptr name = exe_spell(player_ptr, increment ? player_ptr->realm2 : player_ptr->realm1, spell % 32, SpellProcessType::NAME);
889 if (old_exp >= max_exp) {
890 msg_format(_("その%sは完全に使いこなせるので学ぶ必要はない。", "You don't need to study this %s anymore."), p);
894 if (!get_check(format("%sの%sをさらに学びます。よろしいですか?", name, p)))
896 if (!get_check(format("You will study a %s of %s again. Are you sure? ", p, name)))
902 auto new_rank = PlayerSkill(player_ptr).gain_spell_skill_exp_over_learning(spell);
903 auto new_rank_str = PlayerSkill::skill_rank_str(new_rank);
904 msg_format(_("%sの熟練度が%sに上がった。", "Your proficiency of %s is now %s rank."), name, new_rank_str);
906 /* Find the next open entry in "player_ptr->spell_order[]" */
907 for (i = 0; i < 64; i++) {
908 /* Stop at the first empty space */
909 if (player_ptr->spell_order[i] == 99)
913 /* Add the spell to the known list */
914 player_ptr->spell_order[i++] = spell;
916 /* Mention the result */
919 if (mp_ptr->spell_book == ItemKindType::MUSIC_BOOK) {
920 msg_format("%sを学んだ。", exe_spell(player_ptr, increment ? player_ptr->realm2 : player_ptr->realm1, spell % 32, SpellProcessType::NAME));
922 msg_format("%sの%sを学んだ。", exe_spell(player_ptr, increment ? player_ptr->realm2 : player_ptr->realm1, spell % 32, SpellProcessType::NAME), p);
925 msg_format("You have learned the %s of %s.", p, exe_spell(player_ptr, increment ? player_ptr->realm2 : player_ptr->realm1, spell % 32, SpellProcessType::NAME));
929 PlayerEnergy(player_ptr).set_player_turn_energy(100);
931 switch (mp_ptr->spell_book) {
932 case ItemKindType::LIFE_BOOK:
933 chg_virtue(player_ptr, V_FAITH, 1);
935 case ItemKindType::DEATH_BOOK:
936 chg_virtue(player_ptr, V_UNLIFE, 1);
938 case ItemKindType::NATURE_BOOK:
939 chg_virtue(player_ptr, V_NATURE, 1);
942 chg_virtue(player_ptr, V_KNOWLEDGE, 1);
948 /* One less spell available */
949 player_ptr->learned_spells++;
952 player_ptr->update |= (PU_SPELLS);
953 update_creature(player_ptr);
955 /* Redraw object recall */
956 player_ptr->window_flags |= (PW_OBJECT);
960 * @brief 魔法を詠唱するコマンドのメインルーチン /
962 * @param player_ptr プレイヤーへの参照ポインタ
965 bool do_cmd_cast(PlayerType *player_ptr)
968 OBJECT_SUBTYPE_VALUE sval;
974 MANA_POINT need_mana;
978 const magic_type *s_ptr;
981 bool over_exerted = false;
983 /* Require spell ability */
984 PlayerClass pc(player_ptr);
985 auto is_every_magic = pc.is_every_magic();
986 if (!player_ptr->realm1 && !is_every_magic) {
987 msg_print(_("呪文を唱えられない!", "You cannot cast spells!"));
991 if (player_ptr->blind || no_lite(player_ptr)) {
992 if (pc.equals(PlayerClassType::FORCETRAINER))
993 confirm_use_force(player_ptr, false);
995 msg_print(_("目が見えない!", "You cannot see!"));
1001 if (cmd_limit_confused(player_ptr))
1004 if (player_ptr->realm1 == REALM_HEX) {
1005 if (SpellHex(player_ptr).is_casting_full_capacity()) {
1007 msg_print(_("これ以上新しい呪文を詠唱することはできない。", "Can not cast more spells."));
1009 if (player_ptr->lev >= 35) {
1010 flag = SpellHex(player_ptr).stop_spells_with_selection();
1019 if (pc.equals(PlayerClassType::FORCETRAINER)) {
1020 if (player_has_no_spellbooks(player_ptr)) {
1021 confirm_use_force(player_ptr, false);
1022 return true; //!< 錬気キャンセル時の処理がない
1026 prayer = spell_category_name(mp_ptr->spell_book);
1028 q = _("どの呪文書を使いますか? ", "Use which book? ");
1029 s = _("呪文書がない!", "You have no spell books!");
1031 auto item_tester = get_castable_spellbook_tester(player_ptr);
1033 o_ptr = choose_object(player_ptr, &item, q, s, USE_INVEN | USE_FLOOR | (pc.equals(PlayerClassType::FORCETRAINER) ? USE_FORCE : 0), item_tester);
1035 if (item == INVEN_FORCE) /* the_force */
1037 do_cmd_mind(player_ptr);
1038 return true; //!< 錬気キャンセル時の処理がない
1043 /* Access the item's sval */
1046 if (!is_every_magic && (o_ptr->tval == get_realm2_book(player_ptr)))
1049 /* Track the object kind */
1050 object_kind_track(player_ptr, o_ptr->k_idx);
1051 handle_stuff(player_ptr);
1054 realm = tval2realm(o_ptr->tval);
1056 realm = player_ptr->realm2;
1058 realm = player_ptr->realm1;
1060 /* Ask for a spell */
1062 if (!get_spell(player_ptr, &spell,
1063 ((mp_ptr->spell_book == ItemKindType::LIFE_BOOK) ? "詠唱する"
1064 : (mp_ptr->spell_book == ItemKindType::MUSIC_BOOK) ? "歌う"
1066 sval, true, realm)) {
1068 msg_format("その本には知っている%sがない。", prayer);
1072 if (!get_spell(player_ptr, &spell, ((mp_ptr->spell_book == ItemKindType::LIFE_BOOK) ? "recite" : "cast"), sval, true, realm)) {
1074 msg_format("You don't know any %ss in that book.", prayer);
1079 use_realm = tval2realm(o_ptr->tval);
1080 if (use_realm == REALM_HEX) {
1081 if (SpellHex(player_ptr).is_spelling_specific(spell)) {
1082 msg_print(_("その呪文はすでに詠唱中だ。", "You are already casting it."));
1087 if (!is_magic(use_realm)) {
1088 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
1090 s_ptr = &mp_ptr->info[realm - 1][spell];
1093 /* Extract mana consumption rate */
1094 need_mana = mod_need_mana(player_ptr, s_ptr->smana, spell, realm);
1096 /* Verify "dangerous" spells */
1097 if (need_mana > player_ptr->csp) {
1103 msg_format("その%sを%sのに十分なマジックポイントがない。", prayer,
1104 ((mp_ptr->spell_book == ItemKindType::LIFE_BOOK) ? "詠唱する"
1105 : (mp_ptr->spell_book == ItemKindType::LIFE_BOOK) ? "歌う"
1108 msg_format("You do not have enough mana to %s this %s.", ((mp_ptr->spell_book == ItemKindType::LIFE_BOOK) ? "recite" : "cast"), prayer);
1115 if (!get_check_strict(player_ptr, _("それでも挑戦しますか? ", "Attempt it anyway? "), CHECK_OKAY_CANCEL))
1119 /* Spell failure chance */
1120 chance = spell_chance(player_ptr, spell, use_realm);
1123 if (randint0(100) < chance) {
1127 msg_format(_("%sをうまく唱えられなかった!", "You failed to get the %s off!"), prayer);
1132 if (randint1(100) < chance)
1133 chg_virtue(player_ptr, V_VITALITY, -1);
1136 if (randint1(100) < chance)
1137 chg_virtue(player_ptr, V_UNLIFE, -1);
1140 if (randint1(100) < chance)
1141 chg_virtue(player_ptr, V_NATURE, -1);
1144 if (randint1(100) < chance)
1145 chg_virtue(player_ptr, V_JUSTICE, 1);
1148 if (randint1(100) < chance)
1149 chg_virtue(player_ptr, V_JUSTICE, -1);
1152 if (randint1(100) < chance)
1153 chg_virtue(player_ptr, V_COMPASSION, -1);
1156 if (randint1(100) < chance)
1157 chg_virtue(player_ptr, V_KNOWLEDGE, -1);
1161 /* Failure casting may activate some side effect */
1162 exe_spell(player_ptr, realm, spell, SpellProcessType::FAIL);
1164 if ((o_ptr->tval == ItemKindType::CHAOS_BOOK) && (randint1(100) < spell)) {
1165 msg_print(_("カオス的な効果を発生した!", "You produce a chaotic effect!"));
1166 wild_magic(player_ptr, spell);
1167 } else if ((o_ptr->tval == ItemKindType::DEATH_BOOK) && (randint1(100) < spell)) {
1168 if ((sval == 3) && one_in_(2)) {
1169 sanity_blast(player_ptr, 0, true);
1171 msg_print(_("痛い!", "It hurts!"));
1172 take_hit(player_ptr, DAMAGE_LOSELIFE, damroll(o_ptr->sval + 1, 6), _("暗黒魔法の逆流", "a miscast Death spell"));
1174 if ((spell > 15) && one_in_(6) && !player_ptr->hold_exp)
1175 lose_exp(player_ptr, spell * 250);
1177 } else if ((o_ptr->tval == ItemKindType::MUSIC_BOOK) && (randint1(200) < spell)) {
1178 msg_print(_("いやな音が響いた", "An infernal sound echoed."));
1179 aggravate_monsters(player_ptr, 0);
1181 if (randint1(100) >= chance)
1182 chg_virtue(player_ptr, V_CHANCE, -1);
1187 /* Canceled spells cost neither a turn nor mana */
1188 if (!exe_spell(player_ptr, realm, spell, SpellProcessType::CAST))
1191 if (randint1(100) < chance)
1192 chg_virtue(player_ptr, V_CHANCE, 1);
1194 /* A spell was cast */
1195 if (!(increment ? (player_ptr->spell_worked2 & (1UL << spell)) : (player_ptr->spell_worked1 & (1UL << spell))) && !is_every_magic) {
1196 int e = s_ptr->sexp;
1198 /* The spell worked */
1199 if (realm == player_ptr->realm1) {
1200 player_ptr->spell_worked1 |= (1UL << spell);
1202 player_ptr->spell_worked2 |= (1UL << spell);
1205 gain_exp(player_ptr, e * s_ptr->slevel);
1206 player_ptr->window_flags |= (PW_OBJECT);
1210 chg_virtue(player_ptr, V_TEMPERANCE, 1);
1211 chg_virtue(player_ptr, V_COMPASSION, 1);
1212 chg_virtue(player_ptr, V_VITALITY, 1);
1213 chg_virtue(player_ptr, V_DILIGENCE, 1);
1216 chg_virtue(player_ptr, V_UNLIFE, 1);
1217 chg_virtue(player_ptr, V_JUSTICE, -1);
1218 chg_virtue(player_ptr, V_FAITH, -1);
1219 chg_virtue(player_ptr, V_VITALITY, -1);
1222 chg_virtue(player_ptr, V_JUSTICE, -1);
1223 chg_virtue(player_ptr, V_FAITH, -1);
1224 chg_virtue(player_ptr, V_HONOUR, -1);
1225 chg_virtue(player_ptr, V_TEMPERANCE, -1);
1228 chg_virtue(player_ptr, V_FAITH, 1);
1229 chg_virtue(player_ptr, V_JUSTICE, 1);
1230 chg_virtue(player_ptr, V_SACRIFICE, 1);
1231 chg_virtue(player_ptr, V_HONOUR, 1);
1234 chg_virtue(player_ptr, V_NATURE, 1);
1235 chg_virtue(player_ptr, V_HARMONY, 1);
1238 chg_virtue(player_ptr, V_JUSTICE, -1);
1239 chg_virtue(player_ptr, V_FAITH, -1);
1240 chg_virtue(player_ptr, V_HONOUR, -1);
1241 chg_virtue(player_ptr, V_COMPASSION, -1);
1244 chg_virtue(player_ptr, V_KNOWLEDGE, 1);
1250 if (randint1(100 + player_ptr->lev) < need_mana)
1251 chg_virtue(player_ptr, V_TEMPERANCE, 1);
1252 if (randint1(100 + player_ptr->lev) < need_mana)
1253 chg_virtue(player_ptr, V_COMPASSION, 1);
1254 if (randint1(100 + player_ptr->lev) < need_mana)
1255 chg_virtue(player_ptr, V_VITALITY, 1);
1256 if (randint1(100 + player_ptr->lev) < need_mana)
1257 chg_virtue(player_ptr, V_DILIGENCE, 1);
1260 if (randint1(100 + player_ptr->lev) < need_mana)
1261 chg_virtue(player_ptr, V_UNLIFE, 1);
1262 if (randint1(100 + player_ptr->lev) < need_mana)
1263 chg_virtue(player_ptr, V_JUSTICE, -1);
1264 if (randint1(100 + player_ptr->lev) < need_mana)
1265 chg_virtue(player_ptr, V_FAITH, -1);
1266 if (randint1(100 + player_ptr->lev) < need_mana)
1267 chg_virtue(player_ptr, V_VITALITY, -1);
1270 if (randint1(100 + player_ptr->lev) < need_mana)
1271 chg_virtue(player_ptr, V_JUSTICE, -1);
1272 if (randint1(100 + player_ptr->lev) < need_mana)
1273 chg_virtue(player_ptr, V_FAITH, -1);
1274 if (randint1(100 + player_ptr->lev) < need_mana)
1275 chg_virtue(player_ptr, V_HONOUR, -1);
1276 if (randint1(100 + player_ptr->lev) < need_mana)
1277 chg_virtue(player_ptr, V_TEMPERANCE, -1);
1280 if (randint1(100 + player_ptr->lev) < need_mana)
1281 chg_virtue(player_ptr, V_FAITH, 1);
1282 if (randint1(100 + player_ptr->lev) < need_mana)
1283 chg_virtue(player_ptr, V_JUSTICE, 1);
1284 if (randint1(100 + player_ptr->lev) < need_mana)
1285 chg_virtue(player_ptr, V_SACRIFICE, 1);
1286 if (randint1(100 + player_ptr->lev) < need_mana)
1287 chg_virtue(player_ptr, V_HONOUR, 1);
1290 if (randint1(100 + player_ptr->lev) < need_mana)
1291 chg_virtue(player_ptr, V_NATURE, 1);
1292 if (randint1(100 + player_ptr->lev) < need_mana)
1293 chg_virtue(player_ptr, V_HARMONY, 1);
1296 if (randint1(100 + player_ptr->lev) < need_mana)
1297 chg_virtue(player_ptr, V_JUSTICE, -1);
1298 if (randint1(100 + player_ptr->lev) < need_mana)
1299 chg_virtue(player_ptr, V_FAITH, -1);
1300 if (randint1(100 + player_ptr->lev) < need_mana)
1301 chg_virtue(player_ptr, V_HONOUR, -1);
1302 if (randint1(100 + player_ptr->lev) < need_mana)
1303 chg_virtue(player_ptr, V_COMPASSION, -1);
1306 if (any_bits(mp_ptr->spell_xtra, extra_magic_gain_exp)) {
1307 PlayerSkill(player_ptr).gain_spell_skill_exp(realm, spell);
1311 PlayerEnergy(player_ptr).set_player_turn_energy(100);
1313 /* Sufficient mana */
1314 if (need_mana <= player_ptr->csp) {
1316 player_ptr->csp -= need_mana;
1318 over_exerted = true;
1319 player_ptr->redraw |= (PR_MANA);
1321 /* Over-exert the player */
1323 int oops = need_mana;
1324 player_ptr->csp = 0;
1325 player_ptr->csp_frac = 0;
1326 msg_print(_("精神を集中しすぎて気を失ってしまった!", "You faint from the effort!"));
1327 (void)BadStatusSetter(player_ptr).mod_paralysis(randint1(5 * oops + 1));
1330 chg_virtue(player_ptr, V_VITALITY, -10);
1333 chg_virtue(player_ptr, V_UNLIFE, -10);
1336 chg_virtue(player_ptr, V_JUSTICE, 10);
1339 chg_virtue(player_ptr, V_NATURE, -10);
1342 chg_virtue(player_ptr, V_JUSTICE, -10);
1345 chg_virtue(player_ptr, V_COMPASSION, 10);
1348 chg_virtue(player_ptr, V_KNOWLEDGE, -10);
1352 /* Damage CON (possibly permanently) */
1353 if (randint0(100) < 50) {
1354 bool perm = (randint0(100) < 25);
1356 msg_print(_("体を悪くしてしまった!", "You have damaged your health!"));
1358 /* Reduce constitution */
1359 (void)dec_stat(player_ptr, A_CON, 15 + randint1(10), perm);
1363 player_ptr->window_flags |= (PW_PLAYER);
1364 player_ptr->window_flags |= (PW_SPELL);
1366 return true; //!< @note 詠唱した