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 "status/action-setter.h"
58 #include "status/bad-status-setter.h"
59 #include "status/base-status.h"
60 #include "status/experience.h"
61 #include "system/baseitem-info.h"
62 #include "system/floor-type-definition.h"
63 #include "system/item-entity.h"
64 #include "system/player-type-definition.h"
65 #include "system/redrawing-flags-updater.h"
66 #include "term/screen-processor.h"
67 #include "term/z-form.h"
68 #include "timed-effect/player-blindness.h"
69 #include "timed-effect/timed-effects.h"
70 #include "util/bit-flags-calculator.h"
71 #include "util/int-char-converter.h"
72 #include "view/display-messages.h"
73 #include "view/display-util.h"
75 static const int extra_magic_gain_exp = 4;
77 concptr KWD_DAM = _("損傷:", "dam ");
78 concptr KWD_RANGE = _("射程:", "rng ");
79 concptr KWD_DURATION = _("期間:", "dur ");
80 concptr KWD_SPHERE = _("範囲:", "range ");
81 concptr KWD_HEAL = _("回復:", "heal ");
82 concptr KWD_MANA = _("MP回復:", "heal SP ");
83 concptr KWD_POWER _("効力:", "power ");
84 concptr KWD_RANDOM = _("ランダム", "random");
88 * Zangband uses this array instead of the spell flags table, as there
89 * are 5 realms of magic, each with 4 spellbooks and 8 spells per book -- TY
91 const uint32_t fake_spell_flags[4] = { 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 };
95 * 魔法の効果を「キャプション:ダイス+定数値」のフォーマットで出力する / Generate dice info string such as "foo 2d10"
100 * @return フォーマットに従い整形された文字列
102 std::string info_string_dice(concptr str, DICE_NUMBER dice, DICE_SID sides, int base)
106 return format("%s%d", str, base);
111 return format("%s%dd%d", str, dice, sides);
114 /* Dice plus base value */
116 return format("%s%dd%d%+d", str, dice, sides, base);
121 * @brief 魔法によるダメージを出力する / Generate damage-dice info string such as "dam 2d10"
125 * @return フォーマットに従い整形された文字列
127 std::string info_damage(DICE_NUMBER dice, DICE_SID sides, int base)
129 return info_string_dice(_("損傷:", "dam "), dice, sides, base);
133 * @brief 魔法の効果時間を出力する / Generate duration info string such as "dur 20+1d20"
136 * @return フォーマットに従い整形された文字列
138 std::string info_duration(int base, DICE_SID sides)
140 return format(_("期間:%d+1d%d", "dur %d+1d%d"), base, sides);
144 * @brief 魔法の効果範囲を出力する / Generate range info string such as "range 5"
146 * @return フォーマットに従い整形された文字列
148 std::string info_range(POSITION range)
150 return format(_("範囲:%d", "range %d"), range);
154 * @brief 魔法による回復量を出力する / Generate heal info string such as "heal 2d8"
158 * @return フォーマットに従い整形された文字列
160 std::string info_heal(DICE_NUMBER dice, DICE_SID sides, int base)
162 return info_string_dice(_("回復:", "heal "), dice, sides, base);
166 * @brief 魔法効果発動までの遅延ターンを出力する / Generate delay info string such as "delay 15+1d15"
169 * @return フォーマットに従い整形された文字列
171 std::string info_delay(int base, DICE_SID sides)
173 return format(_("遅延:%d+1d%d", "delay %d+1d%d"), base, sides);
177 * @brief 魔法によるダメージを出力する(固定値&複数回処理) / Generate multiple-damage info string such as "dam 25 each"
179 * @return フォーマットに従い整形された文字列
181 std::string info_multi_damage(int dam)
183 return format(_("損傷:各%d", "dam %d each"), dam);
187 * @brief 魔法によるダメージを出力する(ダイスのみ&複数回処理) / Generate multiple-damage-dice info string such as "dam 5d2 each"
190 * @return フォーマットに従い整形された文字列
192 std::string info_multi_damage_dice(DICE_NUMBER dice, DICE_SID sides)
194 return format(_("損傷:各%dd%d", "dam %dd%d each"), dice, sides);
198 * @brief 魔法による一般的な効力値を出力する(固定値) / Generate power info string such as "power 100"
200 * @return フォーマットに従い整形された文字列
202 std::string info_power(int power)
204 return format(_("効力:%d", "power %d"), power);
208 * @brief 魔法による一般的な効力値を出力する(ダイス値) / Generate power info string such as "power 100"
211 * @return フォーマットに従い整形された文字列
214 * Generate power info string such as "power 1d100"
216 std::string info_power_dice(DICE_NUMBER dice, DICE_SID sides)
218 return format(_("効力:%dd%d", "power %dd%d"), dice, sides);
222 * @brief 魔法の効果半径を出力する / Generate radius info string such as "rad 100"
224 * @return フォーマットに従い整形された文字列
226 std::string info_radius(POSITION rad)
228 return format(_("半径:%d", "rad %d"), rad);
232 * @brief 魔法効果の限界重量を出力する / Generate weight info string such as "max wgt 15"
234 * @return フォーマットに従い整形された文字列
236 std::string info_weight(WEIGHT weight)
239 return format("最大重量:%d.%dkg", lb_to_kg_integer(weight), lb_to_kg_fraction(weight));
241 return format("max wgt %d", weight / 10);
246 * @brief 魔法が利用可能かどうかを返す /
247 * Determine if a spell is "okay" for the player to cast or study
248 * The spell must be legible, not forgotten, and also, to cast,
249 * it must be known, and to study, it must not be known.
251 * @param learned 使用可能な判定ならばTRUE、学習可能かどうかの判定ならばFALSE
252 * @param study_pray 祈りの学習判定目的ならばTRUE
253 * @param use_realm 魔法領域ID
256 static bool spell_okay(PlayerType *player_ptr, int spell, bool learned, bool study_pray, int use_realm)
258 const magic_type *s_ptr;
260 /* Access the spell */
261 if (!is_magic(use_realm)) {
262 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
264 s_ptr = &mp_ptr->info[use_realm - 1][spell];
267 /* Spell is illegal */
268 if (s_ptr->slevel > player_ptr->lev) {
272 /* Spell is forgotten */
273 if ((use_realm == player_ptr->realm2) ? (player_ptr->spell_forgotten2 & (1UL << spell)) : (player_ptr->spell_forgotten1 & (1UL << spell))) {
278 if (PlayerClass(player_ptr).is_every_magic()) {
282 /* Spell is learned */
283 if ((use_realm == player_ptr->realm2) ? (player_ptr->spell_learned2 & (1UL << spell)) : (player_ptr->spell_learned1 & (1UL << spell))) {
288 /* Okay to study, not to cast */
293 * @brief 領域魔法の閲覧、学習、使用選択するインターフェイス処理
294 * Allow user to choose a spell/prayer from the given book.
295 * @param sn 選択した魔法IDを返す参照ポインタ
296 * @param prompt 魔法を利用する際の動詞表記
297 * @param sval 魔道書のsval
298 * @param learned 閲覧/使用選択ならばTRUE、学習処理ならFALSE
299 * @param use_realm 魔法領域ID
302 * If a valid spell is chosen, saves it in '*sn' and returns TRUE
303 * If the user hits escape, returns FALSE, and set '*sn' to -1
304 * If there are no legal choices, returns FALSE, and sets '*sn' to -2
305 * The "prompt" should be "cast", "recite", or "study"
306 * The "known" should be TRUE for cast/pray, FALSE for study
309 static int get_spell(PlayerType *player_ptr, SPELL_IDX *sn, concptr prompt, OBJECT_SUBTYPE_VALUE sval, bool learned, int16_t use_realm)
312 SPELL_IDX spell = -1;
314 SPELL_IDX spells[64];
315 bool flag, redraw, okay;
320 int menu_line = (use_menu ? 1 : 0);
322 /* Get the spell, if available */
323 if (repeat_pull(&code)) {
324 *sn = (SPELL_IDX)code;
325 /* Verify the spell */
326 if (spell_okay(player_ptr, *sn, learned, false, use_realm)) {
332 p = spell_category_name(mp_ptr->spell_book);
335 for (spell = 0; spell < 32; spell++) {
336 /* Check for this spell */
337 if ((fake_spell_flags[sval] & (1UL << spell))) {
338 /* Collect this spell */
339 spells[num++] = spell;
343 /* Assume no usable spells */
346 /* Assume no spells available */
349 /* Check for "okay" spells */
350 for (i = 0; i < num; i++) {
351 /* Look for "okay" spells */
352 if (spell_okay(player_ptr, spells[i], learned, false, use_realm)) {
357 /* No "okay" spells */
362 PlayerClass pc(player_ptr);
363 auto is_every_magic = pc.is_every_magic();
364 if (((use_realm) != player_ptr->realm1) && ((use_realm) != player_ptr->realm2) && !is_every_magic) {
367 if (is_every_magic && !is_magic(use_realm)) {
370 if (pc.equals(PlayerClassType::RED_MAGE) && ((use_realm) != REALM_ARCANE) && (sval > 1)) {
374 /* Assume cancelled */
380 player_ptr->window_flags |= (PW_SPELL);
381 handle_stuff(player_ptr);
383 /* Build a prompt (accept all spells) */
385 const auto verb = conjugate_jverb(prompt, JVerbConjugationType::AND);
386 (void)strnfmt(out_val, 78, "(%s^:%c-%c, '*'で一覧, ESCで中断) どの%sを%s^ますか? ", p, I2A(0), I2A(num - 1), p, verb.data());
388 (void)strnfmt(out_val, 78, "(%s^s %c-%c, *=List, ESC=exit) %s^ which %s? ", p, I2A(0), I2A(num - 1), prompt, p);
391 choice = (always_show_list || use_menu) ? ESCAPE : 1;
393 if (choice == ESCAPE) {
395 } else if (!get_com(out_val, &choice, true)) {
399 auto should_redraw_cursor = true;
400 if (use_menu && choice != ' ') {
410 menu_line += (num - 1);
426 should_redraw_cursor = false;
430 if (menu_line > num) {
433 /* Display a list of spells */
434 print_spells(player_ptr, menu_line, spells, num, 1, 15, use_realm);
435 if (should_redraw_cursor) {
440 if ((choice == ' ') || (choice == '*') || (choice == '?')) {
446 /* Display a list of spells */
447 print_spells(player_ptr, menu_line, spells, num, 1, 15, use_realm);
468 /* Totally Illegal */
469 if ((i < 0) || (i >= num)) {
474 /* Save the spell index */
477 /* Require "okay" spells */
478 if (!spell_okay(player_ptr, spell, learned, false, use_realm)) {
481 msg_format("その%sを%sことはできません。", p, prompt);
483 msg_format("You may not %s that %s.", prompt, p);
497 player_ptr->window_flags |= (PW_SPELL);
498 handle_stuff(player_ptr);
500 /* Abort if needed */
505 /* Save the choice */
508 repeat_push((COMMAND_CODE)spell);
515 * @brief プレイヤーの職業が練気術師の時、領域魔法と練気術を切り換える処理のインターフェイス
516 * @param browse_only 魔法と技能の閲覧を行うならばTRUE
517 * @return 魔道書を一冊も持っていないならTRUEを返す
519 static void confirm_use_force(PlayerType *player_ptr, bool browse_only)
524 /* Get the item index */
525 if (repeat_pull(&code) && (code == INVEN_FORCE)) {
526 browse_only ? do_cmd_mind_browse(player_ptr) : do_cmd_mind(player_ptr);
530 /* Show the prompt */
531 prt(_("('w'練気術, ESC) 'w'かESCを押してください。 ", "(w for the Force, ESC) Hit 'w' or ESC. "), 0, 0);
537 if (which == ESCAPE) {
539 } else if (which == 'w') {
540 repeat_push(INVEN_FORCE);
545 /* Clear the prompt line */
549 browse_only ? do_cmd_mind_browse(player_ptr) : do_cmd_mind(player_ptr);
553 static FuncItemTester get_castable_spellbook_tester(PlayerType *player_ptr)
555 return FuncItemTester([](auto p_ptr, auto o_ptr) { return check_book_realm(p_ptr, o_ptr->bi_key); }, player_ptr);
558 static FuncItemTester get_learnable_spellbook_tester(PlayerType *player_ptr)
560 if (player_ptr->realm2 == REALM_NONE) {
561 return get_castable_spellbook_tester(player_ptr);
563 return FuncItemTester(item_tester_learn_spell, player_ptr);
568 * @brief プレイヤーの魔法と技能を閲覧するコマンドのメインルーチン /
569 * Peruse the spells/prayers in a book
572 * Note that *all* spells in the book are listed
574 * Note that browsing is allowed while confused or blind,
575 * and in the dark, primarily to allow browsing in stores.
578 void do_cmd_browse(PlayerType *player_ptr)
581 SPELL_IDX spell = -1;
584 SPELL_IDX spells[64];
586 /* Warriors are illiterate */
587 PlayerClass pc(player_ptr);
588 if (!(player_ptr->realm1 || player_ptr->realm2) && !pc.is_every_magic()) {
589 msg_print(_("本を読むことができない!", "You cannot read books!"));
593 pc.break_samurai_stance({ SamuraiStanceType::MUSOU });
595 if (pc.equals(PlayerClassType::FORCETRAINER)) {
596 if (player_has_no_spellbooks(player_ptr)) {
597 confirm_use_force(player_ptr, true);
602 /* Restrict choices to "useful" books */
603 auto item_tester = get_learnable_spellbook_tester(player_ptr);
605 constexpr auto q = _("どの本を読みますか? ", "Browse which book? ");
606 constexpr auto s = _("読める本がない。", "You have no books that you can read.");
607 constexpr auto options = USE_INVEN | USE_FLOOR;
608 const auto *o_ptr = choose_object(player_ptr, &item, q, s, options | (pc.equals(PlayerClassType::FORCETRAINER) ? USE_FORCE : 0), item_tester);
609 if (o_ptr == nullptr) {
610 if (item == INVEN_FORCE) /* the_force */
612 do_cmd_mind_browse(player_ptr);
618 /* Access the item's sval */
619 const auto tval = o_ptr->bi_key.tval();
620 const auto sval = o_ptr->bi_key.sval().value();
621 short use_realm = tval2realm(tval);
623 /* Track the object kind */
624 object_kind_track(player_ptr, o_ptr->bi_id);
625 handle_stuff(player_ptr);
628 for (spell = 0; spell < 32; spell++) {
629 /* Check for this spell */
630 if ((fake_spell_flags[sval] & (1UL << spell))) {
631 /* Collect this spell */
632 spells[num++] = spell;
639 /* Keep browsing spells. Exit browsing on cancel. */
641 /* Ask for a spell, allow cancel */
642 if (!get_spell(player_ptr, &spell, _("読む", "browse"), sval, true, use_realm)) {
643 /* If cancelled, leave immediately. */
648 /* Display a list of spells */
649 print_spells(player_ptr, 0, spells, num, 1, 15, use_realm);
651 /* Notify that there's nothing to see, and wait. */
652 if (use_realm == REALM_HISSATSU) {
653 prt(_("読める技がない。", "No techniques to browse."), 0, 0);
655 prt(_("読める呪文がない。", "No spells to browse."), 0, 0);
664 /* Clear lines, position cursor (really should use strlen here) */
665 term_erase(14, 14, 255);
666 term_erase(14, 13, 255);
667 term_erase(14, 12, 255);
668 term_erase(14, 11, 255);
670 const auto spell_desc = exe_spell(player_ptr, use_realm, spell, SpellProcessType::DESCRIPTION);
671 display_wrap_around(spell_desc.value(), 62, 11, 15);
677 * @brief プレイヤーの第二魔法領域を変更する /
678 * @param player_ptr プレイヤーへの参照ポインタ
679 * @param next_realm 変更先の魔法領域ID
681 static void change_realm2(PlayerType *player_ptr, int16_t next_realm)
686 for (i = 0; i < 64; i++) {
687 player_ptr->spell_order[j] = player_ptr->spell_order[i];
688 if (player_ptr->spell_order[i] < 32) {
692 for (; j < 64; j++) {
693 player_ptr->spell_order[j] = 99;
696 for (i = 32; i < 64; i++) {
697 player_ptr->spell_exp[i] = PlayerSkill::spell_exp_at(PlayerSkillRank::UNSKILLED);
699 player_ptr->spell_learned2 = 0L;
700 player_ptr->spell_worked2 = 0L;
701 player_ptr->spell_forgotten2 = 0L;
703 constexpr auto mes = _("魔法の領域を%sから%sに変更した。", "changed magic realm from %s to %s.");
704 strnfmt(tmp, sizeof(tmp), mes, realm_names[player_ptr->realm2], realm_names[next_realm]);
705 exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, tmp);
706 player_ptr->old_realm |= 1U << (player_ptr->realm2 - 1);
707 player_ptr->realm2 = next_realm;
710 StatusRedrawingFlag::REORDER,
711 StatusRedrawingFlag::SPELLS,
713 RedrawingFlagsUpdater::get_instance().set_flags(flags);
714 handle_stuff(player_ptr);
716 /* Load an autopick preference file */
717 autopick_load_pref(player_ptr, false);
721 * @brief 魔法を学習するコマンドのメインルーチン /
722 * Study a book to gain a new spell/prayer
724 void do_cmd_study(PlayerType *player_ptr)
727 auto learned = false;
729 /* Spells of realm2 will have an increment of +32 */
730 SPELL_IDX spell = -1;
731 const auto p = spell_category_name(mp_ptr->spell_book);
732 if (!player_ptr->realm1) {
733 msg_print(_("本を読むことができない!", "You cannot read books!"));
737 if (cmd_limit_blind(player_ptr) || cmd_limit_confused(player_ptr)) {
741 if (player_ptr->new_spells == 0) {
742 msg_format(_("新しい%sを覚えることはできない!", "You cannot learn any new %ss!"), p);
746 PlayerClass(player_ptr).break_samurai_stance({ SamuraiStanceType::MUSOU });
749 if (player_ptr->new_spells < 10) {
750 msg_format("あと %d つの%sを学べる。", player_ptr->new_spells, p);
752 msg_format("あと %d 個の%sを学べる。", player_ptr->new_spells, p);
755 msg_format("You can learn %d new %s%s.", player_ptr->new_spells, p, (player_ptr->new_spells == 1 ? "" : "s"));
760 /* Restrict choices to "useful" books */
761 auto item_tester = get_learnable_spellbook_tester(player_ptr);
763 const auto q = _("どの本から学びますか? ", "Study which book? ");
764 const auto s = _("読める本がない。", "You have no books that you can read.");
767 const auto *o_ptr = choose_object(player_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), item_tester);
768 if (o_ptr == nullptr) {
772 const auto tval = o_ptr->bi_key.tval();
773 const auto sval = o_ptr->bi_key.sval().value();
774 if (tval == get_realm2_book(player_ptr)) {
776 } else if (tval != get_realm1_book(player_ptr)) {
777 if (!get_check(_("本当に魔法の領域を変更しますか?", "Really, change magic realm? "))) {
781 change_realm2(player_ptr, tval2realm(tval));
785 /* Track the object kind */
786 object_kind_track(player_ptr, o_ptr->bi_id);
787 handle_stuff(player_ptr);
789 /* Mage -- Learn a selected spell */
790 if (mp_ptr->spell_book != ItemKindType::LIFE_BOOK) {
791 /* Ask for a spell, allow cancel */
792 if (!get_spell(player_ptr, &spell, _("学ぶ", "study"), sval, false, tval2realm(tval)) && (spell == -1)) {
797 /* Priest -- Learn a random prayer */
803 for (spell = 0; spell < 32; spell++) {
804 /* Check spells in the book */
805 if ((fake_spell_flags[sval] & (1UL << spell))) {
806 /* Skip non "okay" prayers */
807 if (!spell_okay(player_ptr, spell, false, true, (increment ? player_ptr->realm2 : player_ptr->realm1))) {
811 /* Hack -- Prepare the randomizer */
814 /* Hack -- Apply the randomizer */
825 /* Nothing to study */
827 msg_format(_("その本には学ぶべき%sがない。", "You cannot learn any %ss in that book."), p);
837 /* Learn the spell */
839 if (player_ptr->spell_learned1 & (1UL << spell)) {
842 player_ptr->spell_learned1 |= (1UL << spell);
845 if (player_ptr->spell_learned2 & (1UL << (spell - 32))) {
848 player_ptr->spell_learned2 |= (1UL << (spell - 32));
853 auto max_exp = PlayerSkill::spell_exp_at((spell < 32) ? PlayerSkillRank::MASTER : PlayerSkillRank::EXPERT);
854 const auto old_exp = player_ptr->spell_exp[spell];
855 const auto realm = increment ? player_ptr->realm2 : player_ptr->realm1;
856 const auto spell_name = exe_spell(player_ptr, realm, spell % 32, SpellProcessType::NAME);
858 if (old_exp >= max_exp) {
859 msg_format(_("その%sは完全に使いこなせるので学ぶ必要はない。", "You don't need to study this %s anymore."), p);
863 if (!get_check(format("%sの%sをさらに学びます。よろしいですか?", spell_name->data(), p)))
865 if (!get_check(format("You will study a %s of %s again. Are you sure? ", p, spell_name->data())))
871 auto new_rank = PlayerSkill(player_ptr).gain_spell_skill_exp_over_learning(spell);
872 auto new_rank_str = PlayerSkill::skill_rank_str(new_rank);
873 msg_format(_("%sの熟練度が%sに上がった。", "Your proficiency of %s is now %s rank."), spell_name->data(), new_rank_str);
875 /* Find the next open entry in "player_ptr->spell_order[]" */
877 for (i = 0; i < 64; i++) {
878 /* Stop at the first empty space */
879 if (player_ptr->spell_order[i] == 99) {
884 /* Add the spell to the known list */
885 player_ptr->spell_order[i++] = spell;
887 /* Mention the result */
888 const auto realm = increment ? player_ptr->realm2 : player_ptr->realm1;
889 const auto spell_name = exe_spell(player_ptr, realm, spell % 32, SpellProcessType::NAME);
891 if (mp_ptr->spell_book == ItemKindType::MUSIC_BOOK) {
892 msg_format("%sを学んだ。", spell_name->data());
894 msg_format("%sの%sを学んだ。", spell_name->data(), p);
897 msg_format("You have learned the %s of %s.", p, spell_name->data());
901 PlayerEnergy(player_ptr).set_player_turn_energy(100);
903 switch (mp_ptr->spell_book) {
904 case ItemKindType::LIFE_BOOK:
905 chg_virtue(player_ptr, Virtue::FAITH, 1);
907 case ItemKindType::DEATH_BOOK:
908 chg_virtue(player_ptr, Virtue::UNLIFE, 1);
910 case ItemKindType::NATURE_BOOK:
911 chg_virtue(player_ptr, Virtue::NATURE, 1);
914 chg_virtue(player_ptr, Virtue::KNOWLEDGE, 1);
920 /* One less spell available */
921 player_ptr->learned_spells++;
923 auto &rfu = RedrawingFlagsUpdater::get_instance();
924 rfu.set_flag(StatusRedrawingFlag::SPELLS);
925 update_creature(player_ptr);
927 /* Redraw object recall */
928 player_ptr->window_flags |= (PW_ITEM_KNOWLEDGTE);
932 * @brief 魔法を詠唱するコマンドのメインルーチン /
934 * @param player_ptr プレイヤーへの参照ポインタ
937 bool do_cmd_cast(PlayerType *player_ptr)
944 MANA_POINT need_mana;
946 const magic_type *s_ptr;
947 auto over_exerted = false;
949 /* Require spell ability */
950 PlayerClass pc(player_ptr);
951 auto is_every_magic = pc.is_every_magic();
952 if (!player_ptr->realm1 && !is_every_magic) {
953 msg_print(_("呪文を唱えられない!", "You cannot cast spells!"));
957 if (player_ptr->effects()->blindness()->is_blind() || no_lite(player_ptr)) {
958 if (pc.equals(PlayerClassType::FORCETRAINER)) {
959 confirm_use_force(player_ptr, false);
961 msg_print(_("目が見えない!", "You cannot see!"));
968 if (cmd_limit_confused(player_ptr)) {
972 if (player_ptr->realm1 == REALM_HEX) {
973 if (SpellHex(player_ptr).is_casting_full_capacity()) {
975 msg_print(_("これ以上新しい呪文を詠唱することはできない。", "Can not cast more spells."));
977 if (player_ptr->lev >= 35) {
978 flag = SpellHex(player_ptr).stop_spells_with_selection();
987 if (pc.equals(PlayerClassType::FORCETRAINER)) {
988 if (player_has_no_spellbooks(player_ptr)) {
989 confirm_use_force(player_ptr, false);
990 return true; //!< 錬気キャンセル時の処理がない
994 const auto prayer = spell_category_name(mp_ptr->spell_book);
995 const auto q = _("どの呪文書を使いますか? ", "Use which book? ");
996 const auto s = _("呪文書がない!", "You have no spell books!");
997 auto item_tester = get_castable_spellbook_tester(player_ptr);
998 const auto options = USE_INVEN | USE_FLOOR | (pc.equals(PlayerClassType::FORCETRAINER) ? USE_FORCE : 0);
1000 const auto *o_ptr = choose_object(player_ptr, &item, q, s, options, item_tester);
1001 if (o_ptr == nullptr) {
1002 if (item == INVEN_FORCE) {
1003 do_cmd_mind(player_ptr);
1004 return true; //!< 錬気キャンセル時の処理がない
1010 const auto tval = o_ptr->bi_key.tval();
1011 const auto sval = o_ptr->bi_key.sval().value();
1012 if (!is_every_magic && (tval == get_realm2_book(player_ptr))) {
1016 /* Track the object kind */
1017 object_kind_track(player_ptr, o_ptr->bi_id);
1018 handle_stuff(player_ptr);
1020 if (is_every_magic) {
1021 realm = tval2realm(tval);
1022 } else if (increment) {
1023 realm = player_ptr->realm2;
1025 realm = player_ptr->realm1;
1028 /* Ask for a spell */
1030 if (!get_spell(player_ptr, &spell,
1031 ((mp_ptr->spell_book == ItemKindType::LIFE_BOOK) ? "詠唱する"
1032 : (mp_ptr->spell_book == ItemKindType::MUSIC_BOOK) ? "歌う"
1034 sval, true, realm)) {
1036 msg_format("その本には知っている%sがない。", prayer);
1041 if (!get_spell(player_ptr, &spell, ((mp_ptr->spell_book == ItemKindType::LIFE_BOOK) ? "recite" : "cast"), sval, true, realm)) {
1043 msg_format("You don't know any %ss in that book.", prayer);
1049 use_realm = tval2realm(tval);
1050 if (use_realm == REALM_HEX) {
1051 if (SpellHex(player_ptr).is_spelling_specific(spell)) {
1052 msg_print(_("その呪文はすでに詠唱中だ。", "You are already casting it."));
1057 if (!is_magic(use_realm)) {
1058 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
1060 s_ptr = &mp_ptr->info[realm - 1][spell];
1063 /* Extract mana consumption rate */
1064 need_mana = mod_need_mana(player_ptr, s_ptr->smana, spell, realm);
1066 /* Verify "dangerous" spells */
1067 if (need_mana > player_ptr->csp) {
1068 if (flush_failure) {
1074 msg_format("その%sを%sのに十分なマジックポイントがない。", prayer,
1075 ((mp_ptr->spell_book == ItemKindType::LIFE_BOOK) ? "詠唱する"
1076 : (mp_ptr->spell_book == ItemKindType::LIFE_BOOK) ? "歌う"
1079 msg_format("You do not have enough mana to %s this %s.", ((mp_ptr->spell_book == ItemKindType::LIFE_BOOK) ? "recite" : "cast"), prayer);
1087 if (!get_check_strict(player_ptr, _("それでも挑戦しますか? ", "Attempt it anyway? "), CHECK_OKAY_CANCEL)) {
1092 /* Spell failure chance */
1093 chance = spell_chance(player_ptr, spell, use_realm);
1096 if (randint0(100) < chance) {
1097 if (flush_failure) {
1101 msg_format(_("%sをうまく唱えられなかった!", "You failed to get the %s off!"), prayer);
1106 if (randint1(100) < chance) {
1107 chg_virtue(player_ptr, Virtue::VITALITY, -1);
1111 if (randint1(100) < chance) {
1112 chg_virtue(player_ptr, Virtue::UNLIFE, -1);
1116 if (randint1(100) < chance) {
1117 chg_virtue(player_ptr, Virtue::NATURE, -1);
1121 if (randint1(100) < chance) {
1122 chg_virtue(player_ptr, Virtue::JUSTICE, 1);
1126 if (randint1(100) < chance) {
1127 chg_virtue(player_ptr, Virtue::JUSTICE, -1);
1131 if (randint1(100) < chance) {
1132 chg_virtue(player_ptr, Virtue::COMPASSION, -1);
1136 if (randint1(100) < chance) {
1137 chg_virtue(player_ptr, Virtue::KNOWLEDGE, -1);
1142 /* Failure casting may activate some side effect */
1143 exe_spell(player_ptr, realm, spell, SpellProcessType::FAIL);
1145 if ((tval == ItemKindType::CHAOS_BOOK) && (randint1(100) < spell)) {
1146 msg_print(_("カオス的な効果を発生した!", "You produce a chaotic effect!"));
1147 wild_magic(player_ptr, spell);
1148 } else if ((tval == ItemKindType::DEATH_BOOK) && (randint1(100) < spell)) {
1149 if ((sval == 3) && one_in_(2)) {
1150 sanity_blast(player_ptr, 0, true);
1152 msg_print(_("痛い!", "It hurts!"));
1153 take_hit(player_ptr, DAMAGE_LOSELIFE, damroll(sval + 1, 6), _("暗黒魔法の逆流", "a miscast Death spell"));
1155 if ((spell > 15) && one_in_(6) && !player_ptr->hold_exp) {
1156 lose_exp(player_ptr, spell * 250);
1159 } else if ((tval == ItemKindType::MUSIC_BOOK) && (randint1(200) < spell)) {
1160 msg_print(_("いやな音が響いた", "An infernal sound echoed."));
1161 aggravate_monsters(player_ptr, 0);
1163 if (randint1(100) >= chance) {
1164 chg_virtue(player_ptr, Virtue::CHANCE, -1);
1170 /* Canceled spells cost neither a turn nor mana */
1171 if (!exe_spell(player_ptr, realm, spell, SpellProcessType::CAST)) {
1175 if (randint1(100) < chance) {
1176 chg_virtue(player_ptr, Virtue::CHANCE, 1);
1179 /* A spell was cast */
1180 if (!(increment ? (player_ptr->spell_worked2 & (1UL << spell)) : (player_ptr->spell_worked1 & (1UL << spell))) && !is_every_magic) {
1181 int e = s_ptr->sexp;
1183 /* The spell worked */
1184 if (realm == player_ptr->realm1) {
1185 player_ptr->spell_worked1 |= (1UL << spell);
1187 player_ptr->spell_worked2 |= (1UL << spell);
1190 gain_exp(player_ptr, e * s_ptr->slevel);
1191 player_ptr->window_flags |= (PW_ITEM_KNOWLEDGTE);
1195 chg_virtue(player_ptr, Virtue::TEMPERANCE, 1);
1196 chg_virtue(player_ptr, Virtue::COMPASSION, 1);
1197 chg_virtue(player_ptr, Virtue::VITALITY, 1);
1198 chg_virtue(player_ptr, Virtue::DILIGENCE, 1);
1201 chg_virtue(player_ptr, Virtue::UNLIFE, 1);
1202 chg_virtue(player_ptr, Virtue::JUSTICE, -1);
1203 chg_virtue(player_ptr, Virtue::FAITH, -1);
1204 chg_virtue(player_ptr, Virtue::VITALITY, -1);
1207 chg_virtue(player_ptr, Virtue::JUSTICE, -1);
1208 chg_virtue(player_ptr, Virtue::FAITH, -1);
1209 chg_virtue(player_ptr, Virtue::HONOUR, -1);
1210 chg_virtue(player_ptr, Virtue::TEMPERANCE, -1);
1213 chg_virtue(player_ptr, Virtue::FAITH, 1);
1214 chg_virtue(player_ptr, Virtue::JUSTICE, 1);
1215 chg_virtue(player_ptr, Virtue::SACRIFICE, 1);
1216 chg_virtue(player_ptr, Virtue::HONOUR, 1);
1219 chg_virtue(player_ptr, Virtue::NATURE, 1);
1220 chg_virtue(player_ptr, Virtue::HARMONY, 1);
1223 chg_virtue(player_ptr, Virtue::JUSTICE, -1);
1224 chg_virtue(player_ptr, Virtue::FAITH, -1);
1225 chg_virtue(player_ptr, Virtue::HONOUR, -1);
1226 chg_virtue(player_ptr, Virtue::COMPASSION, -1);
1229 chg_virtue(player_ptr, Virtue::KNOWLEDGE, 1);
1235 if (randint1(100 + player_ptr->lev) < need_mana) {
1236 chg_virtue(player_ptr, Virtue::TEMPERANCE, 1);
1238 if (randint1(100 + player_ptr->lev) < need_mana) {
1239 chg_virtue(player_ptr, Virtue::COMPASSION, 1);
1241 if (randint1(100 + player_ptr->lev) < need_mana) {
1242 chg_virtue(player_ptr, Virtue::VITALITY, 1);
1244 if (randint1(100 + player_ptr->lev) < need_mana) {
1245 chg_virtue(player_ptr, Virtue::DILIGENCE, 1);
1249 if (randint1(100 + player_ptr->lev) < need_mana) {
1250 chg_virtue(player_ptr, Virtue::UNLIFE, 1);
1252 if (randint1(100 + player_ptr->lev) < need_mana) {
1253 chg_virtue(player_ptr, Virtue::JUSTICE, -1);
1255 if (randint1(100 + player_ptr->lev) < need_mana) {
1256 chg_virtue(player_ptr, Virtue::FAITH, -1);
1258 if (randint1(100 + player_ptr->lev) < need_mana) {
1259 chg_virtue(player_ptr, Virtue::VITALITY, -1);
1263 if (randint1(100 + player_ptr->lev) < need_mana) {
1264 chg_virtue(player_ptr, Virtue::JUSTICE, -1);
1266 if (randint1(100 + player_ptr->lev) < need_mana) {
1267 chg_virtue(player_ptr, Virtue::FAITH, -1);
1269 if (randint1(100 + player_ptr->lev) < need_mana) {
1270 chg_virtue(player_ptr, Virtue::HONOUR, -1);
1272 if (randint1(100 + player_ptr->lev) < need_mana) {
1273 chg_virtue(player_ptr, Virtue::TEMPERANCE, -1);
1277 if (randint1(100 + player_ptr->lev) < need_mana) {
1278 chg_virtue(player_ptr, Virtue::FAITH, 1);
1280 if (randint1(100 + player_ptr->lev) < need_mana) {
1281 chg_virtue(player_ptr, Virtue::JUSTICE, 1);
1283 if (randint1(100 + player_ptr->lev) < need_mana) {
1284 chg_virtue(player_ptr, Virtue::SACRIFICE, 1);
1286 if (randint1(100 + player_ptr->lev) < need_mana) {
1287 chg_virtue(player_ptr, Virtue::HONOUR, 1);
1291 if (randint1(100 + player_ptr->lev) < need_mana) {
1292 chg_virtue(player_ptr, Virtue::NATURE, 1);
1294 if (randint1(100 + player_ptr->lev) < need_mana) {
1295 chg_virtue(player_ptr, Virtue::HARMONY, 1);
1299 if (randint1(100 + player_ptr->lev) < need_mana) {
1300 chg_virtue(player_ptr, Virtue::JUSTICE, -1);
1302 if (randint1(100 + player_ptr->lev) < need_mana) {
1303 chg_virtue(player_ptr, Virtue::FAITH, -1);
1305 if (randint1(100 + player_ptr->lev) < need_mana) {
1306 chg_virtue(player_ptr, Virtue::HONOUR, -1);
1308 if (randint1(100 + player_ptr->lev) < need_mana) {
1309 chg_virtue(player_ptr, Virtue::COMPASSION, -1);
1313 if (any_bits(mp_ptr->spell_xtra, extra_magic_gain_exp)) {
1314 PlayerSkill(player_ptr).gain_spell_skill_exp(realm, spell);
1318 PlayerEnergy(player_ptr).set_player_turn_energy(100);
1320 /* Sufficient mana */
1321 if (need_mana <= player_ptr->csp) {
1323 player_ptr->csp -= need_mana;
1325 over_exerted = true;
1327 player_ptr->redraw |= (PR_MP);
1329 /* Over-exert the player */
1331 int oops = need_mana;
1332 player_ptr->csp = 0;
1333 player_ptr->csp_frac = 0;
1334 msg_print(_("精神を集中しすぎて気を失ってしまった!", "You faint from the effort!"));
1335 (void)BadStatusSetter(player_ptr).mod_paralysis(randint1(5 * oops + 1));
1338 chg_virtue(player_ptr, Virtue::VITALITY, -10);
1341 chg_virtue(player_ptr, Virtue::UNLIFE, -10);
1344 chg_virtue(player_ptr, Virtue::JUSTICE, 10);
1347 chg_virtue(player_ptr, Virtue::NATURE, -10);
1350 chg_virtue(player_ptr, Virtue::JUSTICE, -10);
1353 chg_virtue(player_ptr, Virtue::COMPASSION, 10);
1356 chg_virtue(player_ptr, Virtue::KNOWLEDGE, -10);
1360 /* Damage CON (possibly permanently) */
1361 if (randint0(100) < 50) {
1362 bool perm = (randint0(100) < 25);
1364 msg_print(_("体を悪くしてしまった!", "You have damaged your health!"));
1366 /* Reduce constitution */
1367 (void)dec_stat(player_ptr, A_CON, 15 + randint1(10), perm);
1371 player_ptr->window_flags |= (PW_PLAYER);
1372 player_ptr->window_flags |= (PW_SPELL);
1374 return true; //!< @note 詠唱した