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 (player_ptr->pclass == PlayerClassType::SORCERER)
272 if (player_ptr->pclass == PlayerClassType::RED_MAGE)
275 /* Spell is learned */
276 if ((use_realm == player_ptr->realm2) ? (player_ptr->spell_learned2 & (1UL << spell)) : (player_ptr->spell_learned1 & (1UL << spell))) {
278 return (!study_pray);
281 /* Okay to study, not to cast */
286 * @brief 領域魔法の閲覧、学習、使用選択するインターフェイス処理
287 * Allow user to choose a spell/prayer from the given book.
288 * @param sn 選択した魔法IDを返す参照ポインタ
289 * @param prompt 魔法を利用する際の動詞表記
290 * @param sval 魔道書のsval
291 * @param learned 閲覧/使用選択ならばTRUE、学習処理ならFALSE
292 * @param use_realm 魔法領域ID
295 * If a valid spell is chosen, saves it in '*sn' and returns TRUE
296 * If the user hits escape, returns FALSE, and set '*sn' to -1
297 * If there are no legal choices, returns FALSE, and sets '*sn' to -2
298 * The "prompt" should be "cast", "recite", or "study"
299 * The "known" should be TRUE for cast/pray, FALSE for study
302 static int get_spell(PlayerType *player_ptr, SPELL_IDX *sn, concptr prompt, OBJECT_SUBTYPE_VALUE sval, bool learned, int16_t use_realm)
305 SPELL_IDX spell = -1;
308 MANA_POINT need_mana;
309 SPELL_IDX spells[64];
310 bool flag, redraw, okay;
312 const magic_type *s_ptr;
319 int menu_line = (use_menu ? 1 : 0);
321 /* Get the spell, if available */
322 if (repeat_pull(&code)) {
323 *sn = (SPELL_IDX)code;
324 /* Verify the spell */
325 if (spell_okay(player_ptr, *sn, learned, false, use_realm)) {
331 p = spell_category_name(mp_ptr->spell_book);
334 for (spell = 0; spell < 32; spell++) {
335 /* Check for this spell */
336 if ((fake_spell_flags[sval] & (1UL << spell))) {
337 /* Collect this spell */
338 spells[num++] = spell;
342 /* Assume no usable spells */
345 /* Assume no spells available */
348 /* Check for "okay" spells */
349 for (i = 0; i < num; i++) {
350 /* Look for "okay" spells */
351 if (spell_okay(player_ptr, spells[i], learned, false, use_realm))
355 /* No "okay" spells */
358 if (((use_realm) != player_ptr->realm1) && ((use_realm) != player_ptr->realm2) && (player_ptr->pclass != PlayerClassType::SORCERER) && (player_ptr->pclass != PlayerClassType::RED_MAGE))
360 if (((player_ptr->pclass == PlayerClassType::SORCERER) || (player_ptr->pclass == PlayerClassType::RED_MAGE)) && !is_magic(use_realm))
362 if ((player_ptr->pclass == PlayerClassType::RED_MAGE) && ((use_realm) != REALM_ARCANE) && (sval > 1))
365 /* Assume cancelled */
371 player_ptr->window_flags |= (PW_SPELL);
372 handle_stuff(player_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(player_ptr, menu_line, spells, num, 1, 15, use_realm);
427 if ((choice == ' ') || (choice == '*') || (choice == '?')) {
433 /* Display a list of spells */
434 print_spells(player_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(player_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(player_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(player_ptr, use_realm, spell, SpellProcessType::NAME), need_mana,
506 spell_chance(player_ptr, spell, use_realm), jverb_buf);
508 (void)strnfmt(tmp_val, 78, "%^s %s (%d mana, %d%% fail)? ", prompt, exe_spell(player_ptr, use_realm, spell, SpellProcessType::NAME), need_mana,
509 spell_chance(player_ptr, spell, use_realm));
512 /* Belay that order */
513 if (!get_check(tmp_val))
524 player_ptr->window_flags |= (PW_SPELL);
525 handle_stuff(player_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(PlayerType *player_ptr, bool browse_only)
550 /* Get the item index */
551 if (repeat_pull(&code) && (code == INVEN_FORCE)) {
552 browse_only ? do_cmd_mind_browse(player_ptr) : do_cmd_mind(player_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(player_ptr) : do_cmd_mind(player_ptr);
579 static FuncItemTester get_castable_spellbook_tester(PlayerType *player_ptr)
581 return FuncItemTester([](auto p_ptr, auto o_ptr) { return check_book_realm(p_ptr, o_ptr->tval, o_ptr->sval); }, player_ptr);
584 static FuncItemTester get_learnable_spellbook_tester(PlayerType *player_ptr)
586 if (player_ptr->realm2 == REALM_NONE) {
587 return get_castable_spellbook_tester(player_ptr);
589 return FuncItemTester(item_tester_learn_spell, player_ptr);
594 * @brief プレイヤーの魔法と技能を閲覧するコマンドのメインルーチン /
595 * Peruse the spells/prayers in a book
598 * Note that *all* spells in the book are listed
600 * Note that browsing is allowed while confused or blind,
601 * and in the dark, primarily to allow browsing in stores.
604 void do_cmd_browse(PlayerType *player_ptr)
607 OBJECT_SUBTYPE_VALUE sval;
608 int16_t use_realm = 0;
610 SPELL_IDX spell = -1;
613 SPELL_IDX spells[64];
620 /* Warriors are illiterate */
621 if (!(player_ptr->realm1 || player_ptr->realm2) && (player_ptr->pclass != PlayerClassType::SORCERER) && (player_ptr->pclass != PlayerClassType::RED_MAGE)) {
622 msg_print(_("本を読むことができない!", "You cannot read books!"));
626 PlayerClass(player_ptr).break_samurai_stance({ SamuraiStanceType::MUSOU });
628 if (player_ptr->pclass == PlayerClassType::FORCETRAINER) {
629 if (player_has_no_spellbooks(player_ptr)) {
630 confirm_use_force(player_ptr, true);
635 /* Restrict choices to "useful" books */
636 auto item_tester = get_learnable_spellbook_tester(player_ptr);
638 q = _("どの本を読みますか? ", "Browse which book? ");
639 s = _("読める本がない。", "You have no books that you can read.");
641 o_ptr = choose_object(player_ptr, &item, q, s, (USE_INVEN | USE_FLOOR | (player_ptr->pclass == PlayerClassType::FORCETRAINER ? USE_FORCE : 0)), item_tester);
644 if (item == INVEN_FORCE) /* the_force */
646 do_cmd_mind_browse(player_ptr);
652 /* Access the item's sval */
655 use_realm = tval2realm(o_ptr->tval);
657 /* Track the object kind */
658 object_kind_track(player_ptr, o_ptr->k_idx);
659 handle_stuff(player_ptr);
662 for (spell = 0; spell < 32; spell++) {
663 /* Check for this spell */
664 if ((fake_spell_flags[sval] & (1UL << spell))) {
665 /* Collect this spell */
666 spells[num++] = spell;
673 /* Keep browsing spells. Exit browsing on cancel. */
675 /* Ask for a spell, allow cancel */
676 if (!get_spell(player_ptr, &spell, _("読む", "browse"), o_ptr->sval, true, use_realm)) {
677 /* If cancelled, leave immediately. */
681 /* Display a list of spells */
682 print_spells(player_ptr, 0, spells, num, 1, 15, use_realm);
684 /* Notify that there's nothing to see, and wait. */
685 if (use_realm == REALM_HISSATSU)
686 prt(_("読める技がない。", "No techniques to browse."), 0, 0);
688 prt(_("読める呪文がない。", "No spells to browse."), 0, 0);
696 /* Clear lines, position cursor (really should use strlen here) */
697 term_erase(14, 14, 255);
698 term_erase(14, 13, 255);
699 term_erase(14, 12, 255);
700 term_erase(14, 11, 255);
702 shape_buffer(exe_spell(player_ptr, use_realm, spell, SpellProcessType::DESCRIPTION), 62, temp, sizeof(temp));
704 for (j = 0, line = 11; temp[j]; j += 1 + strlen(&temp[j])) {
705 prt(&temp[j], line, 15);
713 * @brief プレイヤーの第二魔法領域を変更する /
714 * @param player_ptr プレイヤーへの参照ポインタ
715 * @param next_realm 変更先の魔法領域ID
717 static void change_realm2(PlayerType *player_ptr, int16_t next_realm)
722 for (i = 0; i < 64; i++) {
723 player_ptr->spell_order[j] = player_ptr->spell_order[i];
724 if (player_ptr->spell_order[i] < 32)
728 player_ptr->spell_order[j] = 99;
730 for (i = 32; i < 64; i++) {
731 player_ptr->spell_exp[i] = PlayerSkill::spell_exp_at(PlayerSkillRank::UNSKILLED);
733 player_ptr->spell_learned2 = 0L;
734 player_ptr->spell_worked2 = 0L;
735 player_ptr->spell_forgotten2 = 0L;
737 sprintf(tmp, _("魔法の領域を%sから%sに変更した。", "changed magic realm from %s to %s."), realm_names[player_ptr->realm2], realm_names[next_realm]);
738 exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, tmp);
739 player_ptr->old_realm |= 1U << (player_ptr->realm2 - 1);
740 player_ptr->realm2 = next_realm;
742 player_ptr->update |= (PU_REORDER);
743 player_ptr->update |= (PU_SPELLS);
744 handle_stuff(player_ptr);
746 /* Load an autopick preference file */
747 autopick_load_pref(player_ptr, false);
751 * @brief 魔法を学習するコマンドのメインルーチン /
752 * Study a book to gain a new spell/prayer
754 void do_cmd_study(PlayerType *player_ptr)
758 OBJECT_SUBTYPE_VALUE sval;
760 bool learned = false;
762 /* Spells of realm2 will have an increment of +32 */
763 SPELL_IDX spell = -1;
764 concptr p = spell_category_name(mp_ptr->spell_book);
768 if (!player_ptr->realm1) {
769 msg_print(_("本を読むことができない!", "You cannot read books!"));
773 if (cmd_limit_blind(player_ptr))
775 if (cmd_limit_confused(player_ptr))
778 if (!(player_ptr->new_spells)) {
779 msg_format(_("新しい%sを覚えることはできない!", "You cannot learn any new %ss!"), p);
783 PlayerClass(player_ptr).break_samurai_stance({ SamuraiStanceType::MUSOU });
786 if (player_ptr->new_spells < 10) {
787 msg_format("あと %d つの%sを学べる。", player_ptr->new_spells, p);
789 msg_format("あと %d 個の%sを学べる。", player_ptr->new_spells, p);
792 msg_format("You can learn %d new %s%s.", player_ptr->new_spells, p, (player_ptr->new_spells == 1 ? "" : "s"));
797 /* Restrict choices to "useful" books */
798 auto item_tester = get_learnable_spellbook_tester(player_ptr);
800 q = _("どの本から学びますか? ", "Study which book? ");
801 s = _("読める本がない。", "You have no books that you can read.");
803 o_ptr = choose_object(player_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), item_tester);
808 /* Access the item's sval */
811 if (o_ptr->tval == get_realm2_book(player_ptr)) {
813 } else if (o_ptr->tval != get_realm1_book(player_ptr)) {
814 if (!get_check(_("本当に魔法の領域を変更しますか?", "Really, change magic realm? ")))
816 change_realm2(player_ptr, tval2realm(o_ptr->tval));
820 /* Track the object kind */
821 object_kind_track(player_ptr, o_ptr->k_idx);
822 handle_stuff(player_ptr);
824 /* Mage -- Learn a selected spell */
825 if (mp_ptr->spell_book != ItemKindType::LIFE_BOOK) {
826 /* Ask for a spell, allow cancel */
827 if (!get_spell(player_ptr, &spell, _("学ぶ", "study"), sval, false, tval2realm(o_ptr->tval)) && (spell == -1))
831 /* Priest -- Learn a random prayer */
837 for (spell = 0; spell < 32; spell++) {
838 /* Check spells in the book */
839 if ((fake_spell_flags[sval] & (1UL << spell))) {
840 /* Skip non "okay" prayers */
841 if (!spell_okay(player_ptr, spell, false, true, (increment ? player_ptr->realm2 : player_ptr->realm1)))
844 /* Hack -- Prepare the randomizer */
847 /* Hack -- Apply the randomizer */
857 /* Nothing to study */
859 msg_format(_("その本には学ぶべき%sがない。", "You cannot learn any %ss in that book."), p);
868 /* Learn the spell */
870 if (player_ptr->spell_learned1 & (1UL << spell))
873 player_ptr->spell_learned1 |= (1UL << spell);
875 if (player_ptr->spell_learned2 & (1UL << (spell - 32)))
878 player_ptr->spell_learned2 |= (1UL << (spell - 32));
882 auto max_exp = PlayerSkill::spell_exp_at((spell < 32) ? PlayerSkillRank::MASTER : PlayerSkillRank::EXPERT);
883 int old_exp = player_ptr->spell_exp[spell];
884 concptr name = exe_spell(player_ptr, increment ? player_ptr->realm2 : player_ptr->realm1, spell % 32, SpellProcessType::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)))
899 auto new_rank = PlayerSkill(player_ptr).gain_spell_skill_exp_over_learning(spell);
900 auto new_rank_str = PlayerSkill::skill_rank_str(new_rank);
901 msg_format(_("%sの熟練度が%sに上がった。", "Your proficiency of %s is now %s rank."), name, new_rank_str);
903 /* Find the next open entry in "player_ptr->spell_order[]" */
904 for (i = 0; i < 64; i++) {
905 /* Stop at the first empty space */
906 if (player_ptr->spell_order[i] == 99)
910 /* Add the spell to the known list */
911 player_ptr->spell_order[i++] = spell;
913 /* Mention the result */
916 if (mp_ptr->spell_book == ItemKindType::MUSIC_BOOK) {
917 msg_format("%sを学んだ。", exe_spell(player_ptr, increment ? player_ptr->realm2 : player_ptr->realm1, spell % 32, SpellProcessType::NAME));
919 msg_format("%sの%sを学んだ。", exe_spell(player_ptr, increment ? player_ptr->realm2 : player_ptr->realm1, spell % 32, SpellProcessType::NAME), p);
922 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));
926 PlayerEnergy(player_ptr).set_player_turn_energy(100);
928 switch (mp_ptr->spell_book) {
929 case ItemKindType::LIFE_BOOK:
930 chg_virtue(player_ptr, V_FAITH, 1);
932 case ItemKindType::DEATH_BOOK:
933 chg_virtue(player_ptr, V_UNLIFE, 1);
935 case ItemKindType::NATURE_BOOK:
936 chg_virtue(player_ptr, V_NATURE, 1);
939 chg_virtue(player_ptr, V_KNOWLEDGE, 1);
945 /* One less spell available */
946 player_ptr->learned_spells++;
949 player_ptr->update |= (PU_SPELLS);
950 update_creature(player_ptr);
952 /* Redraw object recall */
953 player_ptr->window_flags |= (PW_OBJECT);
957 * @brief 魔法を詠唱するコマンドのメインルーチン /
959 * @param player_ptr プレイヤーへの参照ポインタ
962 bool do_cmd_cast(PlayerType *player_ptr)
965 OBJECT_SUBTYPE_VALUE sval;
971 MANA_POINT need_mana;
975 const magic_type *s_ptr;
978 bool over_exerted = false;
980 /* Require spell ability */
981 if (!player_ptr->realm1 && (player_ptr->pclass != PlayerClassType::SORCERER) && (player_ptr->pclass != PlayerClassType::RED_MAGE)) {
982 msg_print(_("呪文を唱えられない!", "You cannot cast spells!"));
986 if (player_ptr->blind || no_lite(player_ptr)) {
987 if (player_ptr->pclass == PlayerClassType::FORCETRAINER)
988 confirm_use_force(player_ptr, false);
990 msg_print(_("目が見えない!", "You cannot see!"));
996 if (cmd_limit_confused(player_ptr))
999 if (player_ptr->realm1 == REALM_HEX) {
1000 if (SpellHex(player_ptr).is_casting_full_capacity()) {
1002 msg_print(_("これ以上新しい呪文を詠唱することはできない。", "Can not cast more spells."));
1004 if (player_ptr->lev >= 35) {
1005 flag = SpellHex(player_ptr).stop_spells_with_selection();
1014 if (player_ptr->pclass == PlayerClassType::FORCETRAINER) {
1015 if (player_has_no_spellbooks(player_ptr)) {
1016 confirm_use_force(player_ptr, false);
1017 return true; //!< 錬気キャンセル時の処理がない
1021 prayer = spell_category_name(mp_ptr->spell_book);
1023 q = _("どの呪文書を使いますか? ", "Use which book? ");
1024 s = _("呪文書がない!", "You have no spell books!");
1026 auto item_tester = get_castable_spellbook_tester(player_ptr);
1028 o_ptr = choose_object(player_ptr, &item, q, s, (USE_INVEN | USE_FLOOR | (player_ptr->pclass == PlayerClassType::FORCETRAINER ? USE_FORCE : 0)), item_tester);
1030 if (item == INVEN_FORCE) /* the_force */
1032 do_cmd_mind(player_ptr);
1033 return true; //!< 錬気キャンセル時の処理がない
1038 /* Access the item's sval */
1041 if ((player_ptr->pclass != PlayerClassType::SORCERER) && (player_ptr->pclass != PlayerClassType::RED_MAGE) && (o_ptr->tval == get_realm2_book(player_ptr)))
1044 /* Track the object kind */
1045 object_kind_track(player_ptr, o_ptr->k_idx);
1046 handle_stuff(player_ptr);
1048 if ((player_ptr->pclass == PlayerClassType::SORCERER) || (player_ptr->pclass == PlayerClassType::RED_MAGE))
1049 realm = tval2realm(o_ptr->tval);
1051 realm = player_ptr->realm2;
1053 realm = player_ptr->realm1;
1055 /* Ask for a spell */
1057 if (!get_spell(player_ptr, &spell,
1058 ((mp_ptr->spell_book == ItemKindType::LIFE_BOOK) ? "詠唱する"
1059 : (mp_ptr->spell_book == ItemKindType::MUSIC_BOOK) ? "歌う"
1061 sval, true, realm)) {
1063 msg_format("その本には知っている%sがない。", prayer);
1067 if (!get_spell(player_ptr, &spell, ((mp_ptr->spell_book == ItemKindType::LIFE_BOOK) ? "recite" : "cast"), sval, true, realm)) {
1069 msg_format("You don't know any %ss in that book.", prayer);
1074 use_realm = tval2realm(o_ptr->tval);
1075 if (use_realm == REALM_HEX) {
1076 if (SpellHex(player_ptr).is_spelling_specific(spell)) {
1077 msg_print(_("その呪文はすでに詠唱中だ。", "You are already casting it."));
1082 if (!is_magic(use_realm)) {
1083 s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
1085 s_ptr = &mp_ptr->info[realm - 1][spell];
1088 /* Extract mana consumption rate */
1089 need_mana = mod_need_mana(player_ptr, s_ptr->smana, spell, realm);
1091 /* Verify "dangerous" spells */
1092 if (need_mana > player_ptr->csp) {
1098 msg_format("その%sを%sのに十分なマジックポイントがない。", prayer,
1099 ((mp_ptr->spell_book == ItemKindType::LIFE_BOOK) ? "詠唱する"
1100 : (mp_ptr->spell_book == ItemKindType::LIFE_BOOK) ? "歌う"
1103 msg_format("You do not have enough mana to %s this %s.", ((mp_ptr->spell_book == ItemKindType::LIFE_BOOK) ? "recite" : "cast"), prayer);
1110 if (!get_check_strict(player_ptr, _("それでも挑戦しますか? ", "Attempt it anyway? "), CHECK_OKAY_CANCEL))
1114 /* Spell failure chance */
1115 chance = spell_chance(player_ptr, spell, use_realm);
1118 if (randint0(100) < chance) {
1122 msg_format(_("%sをうまく唱えられなかった!", "You failed to get the %s off!"), prayer);
1127 if (randint1(100) < chance)
1128 chg_virtue(player_ptr, V_VITALITY, -1);
1131 if (randint1(100) < chance)
1132 chg_virtue(player_ptr, V_UNLIFE, -1);
1135 if (randint1(100) < chance)
1136 chg_virtue(player_ptr, V_NATURE, -1);
1139 if (randint1(100) < chance)
1140 chg_virtue(player_ptr, V_JUSTICE, 1);
1143 if (randint1(100) < chance)
1144 chg_virtue(player_ptr, V_JUSTICE, -1);
1147 if (randint1(100) < chance)
1148 chg_virtue(player_ptr, V_COMPASSION, -1);
1151 if (randint1(100) < chance)
1152 chg_virtue(player_ptr, V_KNOWLEDGE, -1);
1156 /* Failure casting may activate some side effect */
1157 exe_spell(player_ptr, realm, spell, SpellProcessType::FAIL);
1159 if ((o_ptr->tval == ItemKindType::CHAOS_BOOK) && (randint1(100) < spell)) {
1160 msg_print(_("カオス的な効果を発生した!", "You produce a chaotic effect!"));
1161 wild_magic(player_ptr, spell);
1162 } else if ((o_ptr->tval == ItemKindType::DEATH_BOOK) && (randint1(100) < spell)) {
1163 if ((sval == 3) && one_in_(2)) {
1164 sanity_blast(player_ptr, 0, true);
1166 msg_print(_("痛い!", "It hurts!"));
1167 take_hit(player_ptr, DAMAGE_LOSELIFE, damroll(o_ptr->sval + 1, 6), _("暗黒魔法の逆流", "a miscast Death spell"));
1169 if ((spell > 15) && one_in_(6) && !player_ptr->hold_exp)
1170 lose_exp(player_ptr, spell * 250);
1172 } else if ((o_ptr->tval == ItemKindType::MUSIC_BOOK) && (randint1(200) < spell)) {
1173 msg_print(_("いやな音が響いた", "An infernal sound echoed."));
1174 aggravate_monsters(player_ptr, 0);
1176 if (randint1(100) >= chance)
1177 chg_virtue(player_ptr, V_CHANCE, -1);
1182 /* Canceled spells cost neither a turn nor mana */
1183 if (!exe_spell(player_ptr, realm, spell, SpellProcessType::CAST))
1186 if (randint1(100) < chance)
1187 chg_virtue(player_ptr, V_CHANCE, 1);
1189 /* A spell was cast */
1190 if (!(increment ? (player_ptr->spell_worked2 & (1UL << spell)) : (player_ptr->spell_worked1 & (1UL << spell))) && (player_ptr->pclass != PlayerClassType::SORCERER) && (player_ptr->pclass != PlayerClassType::RED_MAGE)) {
1191 int e = s_ptr->sexp;
1193 /* The spell worked */
1194 if (realm == player_ptr->realm1) {
1195 player_ptr->spell_worked1 |= (1UL << spell);
1197 player_ptr->spell_worked2 |= (1UL << spell);
1200 gain_exp(player_ptr, e * s_ptr->slevel);
1201 player_ptr->window_flags |= (PW_OBJECT);
1205 chg_virtue(player_ptr, V_TEMPERANCE, 1);
1206 chg_virtue(player_ptr, V_COMPASSION, 1);
1207 chg_virtue(player_ptr, V_VITALITY, 1);
1208 chg_virtue(player_ptr, V_DILIGENCE, 1);
1211 chg_virtue(player_ptr, V_UNLIFE, 1);
1212 chg_virtue(player_ptr, V_JUSTICE, -1);
1213 chg_virtue(player_ptr, V_FAITH, -1);
1214 chg_virtue(player_ptr, V_VITALITY, -1);
1217 chg_virtue(player_ptr, V_JUSTICE, -1);
1218 chg_virtue(player_ptr, V_FAITH, -1);
1219 chg_virtue(player_ptr, V_HONOUR, -1);
1220 chg_virtue(player_ptr, V_TEMPERANCE, -1);
1223 chg_virtue(player_ptr, V_FAITH, 1);
1224 chg_virtue(player_ptr, V_JUSTICE, 1);
1225 chg_virtue(player_ptr, V_SACRIFICE, 1);
1226 chg_virtue(player_ptr, V_HONOUR, 1);
1229 chg_virtue(player_ptr, V_NATURE, 1);
1230 chg_virtue(player_ptr, V_HARMONY, 1);
1233 chg_virtue(player_ptr, V_JUSTICE, -1);
1234 chg_virtue(player_ptr, V_FAITH, -1);
1235 chg_virtue(player_ptr, V_HONOUR, -1);
1236 chg_virtue(player_ptr, V_COMPASSION, -1);
1239 chg_virtue(player_ptr, V_KNOWLEDGE, 1);
1245 if (randint1(100 + player_ptr->lev) < need_mana)
1246 chg_virtue(player_ptr, V_TEMPERANCE, 1);
1247 if (randint1(100 + player_ptr->lev) < need_mana)
1248 chg_virtue(player_ptr, V_COMPASSION, 1);
1249 if (randint1(100 + player_ptr->lev) < need_mana)
1250 chg_virtue(player_ptr, V_VITALITY, 1);
1251 if (randint1(100 + player_ptr->lev) < need_mana)
1252 chg_virtue(player_ptr, V_DILIGENCE, 1);
1255 if (randint1(100 + player_ptr->lev) < need_mana)
1256 chg_virtue(player_ptr, V_UNLIFE, 1);
1257 if (randint1(100 + player_ptr->lev) < need_mana)
1258 chg_virtue(player_ptr, V_JUSTICE, -1);
1259 if (randint1(100 + player_ptr->lev) < need_mana)
1260 chg_virtue(player_ptr, V_FAITH, -1);
1261 if (randint1(100 + player_ptr->lev) < need_mana)
1262 chg_virtue(player_ptr, V_VITALITY, -1);
1265 if (randint1(100 + player_ptr->lev) < need_mana)
1266 chg_virtue(player_ptr, V_JUSTICE, -1);
1267 if (randint1(100 + player_ptr->lev) < need_mana)
1268 chg_virtue(player_ptr, V_FAITH, -1);
1269 if (randint1(100 + player_ptr->lev) < need_mana)
1270 chg_virtue(player_ptr, V_HONOUR, -1);
1271 if (randint1(100 + player_ptr->lev) < need_mana)
1272 chg_virtue(player_ptr, V_TEMPERANCE, -1);
1275 if (randint1(100 + player_ptr->lev) < need_mana)
1276 chg_virtue(player_ptr, V_FAITH, 1);
1277 if (randint1(100 + player_ptr->lev) < need_mana)
1278 chg_virtue(player_ptr, V_JUSTICE, 1);
1279 if (randint1(100 + player_ptr->lev) < need_mana)
1280 chg_virtue(player_ptr, V_SACRIFICE, 1);
1281 if (randint1(100 + player_ptr->lev) < need_mana)
1282 chg_virtue(player_ptr, V_HONOUR, 1);
1285 if (randint1(100 + player_ptr->lev) < need_mana)
1286 chg_virtue(player_ptr, V_NATURE, 1);
1287 if (randint1(100 + player_ptr->lev) < need_mana)
1288 chg_virtue(player_ptr, V_HARMONY, 1);
1291 if (randint1(100 + player_ptr->lev) < need_mana)
1292 chg_virtue(player_ptr, V_JUSTICE, -1);
1293 if (randint1(100 + player_ptr->lev) < need_mana)
1294 chg_virtue(player_ptr, V_FAITH, -1);
1295 if (randint1(100 + player_ptr->lev) < need_mana)
1296 chg_virtue(player_ptr, V_HONOUR, -1);
1297 if (randint1(100 + player_ptr->lev) < need_mana)
1298 chg_virtue(player_ptr, V_COMPASSION, -1);
1301 if (any_bits(mp_ptr->spell_xtra, extra_magic_gain_exp)) {
1302 PlayerSkill(player_ptr).gain_spell_skill_exp(realm, spell);
1306 PlayerEnergy(player_ptr).set_player_turn_energy(100);
1308 /* Sufficient mana */
1309 if (need_mana <= player_ptr->csp) {
1311 player_ptr->csp -= need_mana;
1313 over_exerted = true;
1314 player_ptr->redraw |= (PR_MANA);
1316 /* Over-exert the player */
1318 int oops = need_mana;
1319 player_ptr->csp = 0;
1320 player_ptr->csp_frac = 0;
1321 msg_print(_("精神を集中しすぎて気を失ってしまった!", "You faint from the effort!"));
1322 (void)BadStatusSetter(player_ptr).mod_paralysis(randint1(5 * oops + 1));
1325 chg_virtue(player_ptr, V_VITALITY, -10);
1328 chg_virtue(player_ptr, V_UNLIFE, -10);
1331 chg_virtue(player_ptr, V_JUSTICE, 10);
1334 chg_virtue(player_ptr, V_NATURE, -10);
1337 chg_virtue(player_ptr, V_JUSTICE, -10);
1340 chg_virtue(player_ptr, V_COMPASSION, 10);
1343 chg_virtue(player_ptr, V_KNOWLEDGE, -10);
1347 /* Damage CON (possibly permanently) */
1348 if (randint0(100) < 50) {
1349 bool perm = (randint0(100) < 25);
1351 msg_print(_("体を悪くしてしまった!", "You have damaged your health!"));
1353 /* Reduce constitution */
1354 (void)dec_stat(player_ptr, A_CON, 15 + randint1(10), perm);
1358 player_ptr->window_flags |= (PW_PLAYER);
1359 player_ptr->window_flags |= (PW_SPELL);
1361 return true; //!< @note 詠唱した