2 * @brief プレイヤーのアイテムに関するコマンドの実装2 / Spell/Prayer commands
6 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
7 * This software may be copied and distributed for educational, research,
8 * and not for profit purposes provided that this copyright and statement
9 * are included in all such copies. Other copyrights may also apply.
10 * 2014 Deskull rearranged comment for Doxygen.\n
14 * This file includes code for eating food, drinking potions,
15 * reading scrolls, aiming wands, using staffs, zapping rods,
16 * and activating artifacts.
18 * In all cases, if the player becomes "aware" of the item's use
19 * by testing it, mark it as "aware" and reward some experience
20 * based on the object's level, always rounding up. If the player
21 * remains "unaware", mark that object "kind" as "tried".
23 * This code now correctly handles the unstacking of wands, staffs,
24 * and rods. Note the overly paranoid warning about potential pack
25 * overflow, which allows the player to use and drop a stacked item.
27 * In all "unstacking" scenarios, the "used" object is "carried" as if
28 * the player had just picked it up. In particular, this means that if
29 * the use of an item induces pack overflow, that item will be dropped.
31 * For simplicity, these routines induce a full "pack reorganization"
32 * which not only combines similar items, but also reorganizes various
33 * items to obey the current "sorting" method. This may require about
34 * 400 item comparisons, but only occasionally.
36 * There may be a BIG problem with any "effect" that can cause "changes"
37 * to the inventory. For example, a "scroll of recharging" can cause
38 * a wand/staff to "disappear", moving the inventory up. Luckily, the
39 * scrolls all appear BEFORE the staffs/wands, so this is not a problem.
40 * But, for example, a "staff of recharging" could cause MAJOR problems.
41 * In such a case, it will be best to either (1) "postpone" the effect
42 * until the end of the function, or (2) "change" the effect, say, into
43 * giving a staff "negative" charges, or "turning a staff into a stick".
44 * It seems as though a "rod of recharging" might in fact cause problems.
45 * The basic problem is that the act of recharging (and destroying) an
46 * item causes the inducer of that action to "move", causing "o_ptr" to
47 * no longer point at the correct item, with horrifying results.
49 * Note that food/potions/scrolls no longer use bit-flags for effects,
50 * but instead use the "sval" (which is also used to sort the objects).
54 #include "cmd-item/cmd-magiceat.h"
55 #include "action/action-limited.h"
56 #include "cmd-item/cmd-usestaff.h"
57 #include "cmd-item/cmd-zaprod.h"
58 #include "cmd-item/cmd-zapwand.h"
59 #include "core/asking-player.h"
60 #include "game-option/disturbance-options.h"
61 #include "game-option/text-display-options.h"
62 #include "io/command-repeater.h"
63 #include "io/input-key-acceptor.h"
64 #include "io/input-key-requester.h"
65 #include "main/sound-definitions-table.h"
66 #include "main/sound-of-music.h"
67 #include "object/object-kind-hook.h"
68 #include "object/object-kind.h"
69 #include "sv-definition/sv-other-types.h"
70 #include "sv-definition/sv-rod-types.h"
71 #include "player-info/avatar.h"
72 #include "player/player-class.h"
73 #include "player/player-status.h"
74 #include "spell/spell-info.h"
75 #include "target/target-getter.h"
76 #include "term/screen-processor.h"
77 #include "term/term-color-types.h"
78 #include "util/buffer-shaper.h"
79 #include "util/int-char-converter.h"
80 #include "view/display-messages.h"
83 * @brief 魔道具術師の取り込んだ魔力一覧から選択/閲覧する /
84 * @param only_browse 閲覧するだけならばTRUE
85 * @return 選択した魔力のID、キャンセルならば-1を返す
87 static OBJECT_SUBTYPE_VALUE select_magic_eater(player_type *creature_ptr, bool only_browse)
89 OBJECT_SUBTYPE_VALUE ext = 0;
91 bool flag, request_list;
94 OBJECT_SUBTYPE_VALUE i = 0;
97 int menu_line = (use_menu ? 1 : 0);
100 if (repeat_pull(&sn))
102 /* Verify the spell */
103 if (sn >= EATER_EXT*2 && !(creature_ptr->magic_num1[sn] > k_info[lookup_kind(TV_ROD, sn-EATER_EXT*2)].pval * (creature_ptr->magic_num2[sn] - 1) * EATER_ROD_CHARGE))
105 else if (sn < EATER_EXT*2 && !(creature_ptr->magic_num1[sn] < EATER_CHARGE))
109 for (i = 0; i < MAX_SPELLS; i++)
111 if (creature_ptr->magic_num2[i]) break;
116 msg_print(_("魔法を覚えていない!", "You don't have any magic!"));
127 prt(format(" %s 杖", (menu_line == 1) ? "》" : " "), 2, 14);
128 prt(format(" %s 魔法棒", (menu_line == 2) ? "》" : " "), 3, 14);
129 prt(format(" %s ロッド", (menu_line == 3) ? "》" : " "), 4, 14);
131 prt(format(" %s staff", (menu_line == 1) ? "> " : " "), 2, 14);
132 prt(format(" %s wand", (menu_line == 2) ? "> " : " "), 3, 14);
133 prt(format(" %s rod", (menu_line == 3) ? "> " : " "), 4, 14);
136 if (only_browse) prt(_("どの種類の魔法を見ますか?", "Which type of magic do you browse?"), 0, 0);
137 else prt(_("どの種類の魔法を使いますか?", "Which type of magic do you use?"), 0, 0);
160 ext = (menu_line-1)*EATER_EXT;
161 if (menu_line == 1) tval = TV_STAFF;
162 else if (menu_line == 2) tval = TV_WAND;
166 if (menu_line > 3) menu_line -= 3;
174 if (!get_com(_("[A] 杖, [B] 魔法棒, [C] ロッド:", "[A] staff, [B] wand, [C] rod:"), &choice, TRUE))
178 if (choice == 'A' || choice == 'a')
184 if (choice == 'B' || choice == 'b')
190 if (choice == 'C' || choice == 'c')
198 for (i = ext; i < ext + EATER_EXT; i++)
200 if (creature_ptr->magic_num2[i])
202 if (use_menu) menu_line = i-ext+1;
206 if (i == ext+EATER_EXT)
208 msg_print(_("その種類の魔法は覚えていない!", "You don't have that type of magic!"));
212 /* Nothing chosen yet */
215 if (only_browse) strnfmt(out_val, 78, _("('*'で一覧, ESCで中断) どの魔力を見ますか?",
216 "(*=List, ESC=exit) Browse which power? "));
217 else strnfmt(out_val, 78, _("('*'で一覧, ESCで中断) どの魔力を使いますか?",
218 "(*=List, ESC=exit) Use which power? "));
221 request_list = always_show_list;
226 if (request_list || use_menu)
229 OBJECT_SUBTYPE_VALUE ctr;
231 KIND_OBJECT_IDX k_idx;
239 for (y = 1; y < 20; y++)
244 /* Print header(s) */
246 prt(format(" %s 失率 %s 失率", (tval == TV_ROD ? " 状態 " : "使用回数"), (tval == TV_ROD ? " 状態 " : "使用回数")), y++, x);
248 prt(format(" %s Fail %s Fail", (tval == TV_ROD ? " Stat " : " Charges"), (tval == TV_ROD ? " Stat " : " Charges")), y++, x);
252 for (ctr = 0; ctr < EATER_EXT; ctr++)
254 if (!creature_ptr->magic_num2[ctr+ext]) continue;
256 k_idx = lookup_kind(tval, ctr);
260 if (ctr == (menu_line-1))
261 strcpy(dummy, _("》", "> "));
265 /* letter/number for power selection */
272 letter = '0' + ctr - 26;
273 sprintf(dummy, "%c)",letter);
275 x1 = ((ctr < EATER_EXT/2) ? x : x + 40);
276 y1 = ((ctr < EATER_EXT/2) ? y + ctr : y + ctr - EATER_EXT/2);
277 level = (tval == TV_ROD ? k_info[k_idx].level * 5 / 6 - 5 : k_info[k_idx].level);
278 chance = level * 4 / 5 + 20;
279 chance -= 3 * (adj_mag_stat[creature_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
281 if (creature_ptr->lev > level)
283 chance -= 3 * (creature_ptr->lev - level);
285 chance = mod_spell_chance_1(creature_ptr, chance);
286 chance = MAX(chance, adj_mag_fail[creature_ptr->stat_ind[mp_ptr->spell_stat]]);
287 /* Stunning makes spells harder */
288 if (creature_ptr->stun > 50) chance += 25;
289 else if (creature_ptr->stun) chance += 15;
291 if (chance > 95) chance = 95;
293 chance = mod_spell_chance_2(creature_ptr, chance);
301 strcat(dummy, format(
302 _(" %-22.22s 充填:%2d/%2d%3d%%", " %-22.22s (%2d/%2d) %3d%%"),
303 k_name + k_info[k_idx].name,
304 creature_ptr->magic_num1[ctr+ext] ?
305 (creature_ptr->magic_num1[ctr+ext] - 1) / (EATER_ROD_CHARGE * k_info[k_idx].pval) +1 : 0,
306 creature_ptr->magic_num2[ctr+ext], chance));
307 if (creature_ptr->magic_num1[ctr+ext] > k_info[k_idx].pval * (creature_ptr->magic_num2[ctr+ext]-1) * EATER_ROD_CHARGE) col = TERM_RED;
311 strcat(dummy, format(" %-22.22s %2d/%2d %3d%%", k_name + k_info[k_idx].name, (s16b)(creature_ptr->magic_num1[ctr+ext]/EATER_CHARGE), creature_ptr->magic_num2[ctr+ext], chance));
312 if (creature_ptr->magic_num1[ctr+ext] < EATER_CHARGE) col = TERM_RED;
317 c_prt(col, dummy, y1, x1);
321 if (!get_com(out_val, &choice, FALSE)) break;
323 if (use_menu && choice != ' ')
339 menu_line += EATER_EXT - 1;
340 if (menu_line > EATER_EXT) menu_line -= EATER_EXT;
341 } while(!creature_ptr->magic_num2[menu_line+ext-1]);
352 if (menu_line > EATER_EXT) menu_line -= EATER_EXT;
353 } while(!creature_ptr->magic_num2[menu_line+ext-1]);
364 bool reverse = FALSE;
365 if ((choice == '4') || (choice == 'h') || (choice == 'H')) reverse = TRUE;
366 if (menu_line > EATER_EXT/2)
368 menu_line -= EATER_EXT/2;
371 else menu_line+=EATER_EXT/2;
372 while(!creature_ptr->magic_num2[menu_line+ext-1])
377 if (menu_line < 2) reverse = FALSE;
382 if (menu_line > EATER_EXT-1) reverse = TRUE;
400 if (use_menu && ask) continue;
403 if (!use_menu && ((choice == ' ') || (choice == '*') || (choice == '?')))
409 request_list = FALSE;
425 ask = (isupper(choice));
428 if (ask) choice = (char)tolower(choice);
430 /* Extract request */
431 i = (islower(choice) ? A2I(choice) : -1);
435 ask = FALSE; /* Can't uppercase digits */
437 i = choice - '0' + 26;
441 /* Totally Illegal */
442 if ((i < 0) || (i > EATER_EXT) || !creature_ptr->magic_num2[i+ext])
456 (void) strnfmt(tmp_val, 78, _("%sを使いますか? ", "Use %s?"), k_name + k_info[lookup_kind(tval ,i)].name);
458 /* Belay that order */
459 if (!get_check(tmp_val)) continue;
463 if (creature_ptr->magic_num1[ext+i] > k_info[lookup_kind(tval, i)].pval * (creature_ptr->magic_num2[ext+i] - 1) * EATER_ROD_CHARGE)
465 msg_print(_("その魔法はまだ充填している最中だ。", "The magic is still charging."));
467 if (use_menu) ask = TRUE;
473 if (creature_ptr->magic_num1[ext+i] < EATER_CHARGE)
475 msg_print(_("その魔法は使用回数が切れている。", "The magic has no charges left."));
477 if (use_menu) ask = TRUE;
489 /* Clear lines, position cursor (really should use strlen here) */
490 term_erase(7, 23, 255);
491 term_erase(7, 22, 255);
492 term_erase(7, 21, 255);
493 term_erase(7, 20, 255);
495 shape_buffer(k_text + k_info[lookup_kind(tval, i)].text, 62, temp, sizeof(temp));
496 for (j = 0, line = 21; temp[j]; j += 1 + strlen(&temp[j]))
498 prt(&temp[j], line, 10);
510 if (!flag) return -1;
518 * @brief 取り込んだ魔力を利用するコマンドのメインルーチン /
519 * Use eaten rod, wand or staff
520 * @param only_browse 閲覧するだけならばTRUE
521 * @param powerful 強力発動中の処理ならばTRUE
522 * @return 実際にコマンドを実行したならばTRUEを返す。
524 bool do_cmd_magic_eater(player_type *creature_ptr, bool only_browse, bool powerful)
526 OBJECT_SUBTYPE_VALUE item;
529 KIND_OBJECT_IDX k_idx;
531 OBJECT_SUBTYPE_VALUE sval;
532 bool use_charge = TRUE;
534 if (cmd_limit_confused(creature_ptr)) return FALSE;
536 item = select_magic_eater(creature_ptr, only_browse);
539 free_turn(creature_ptr);
542 if (item >= EATER_EXT*2) {tval = TV_ROD;sval = item - EATER_EXT*2;}
543 else if (item >= EATER_EXT) {tval = TV_WAND;sval = item - EATER_EXT;}
544 else {tval = TV_STAFF; sval = item;}
545 k_idx = lookup_kind(tval, sval);
547 level = (tval == TV_ROD ? k_info[k_idx].level * 5 / 6 - 5 : k_info[k_idx].level);
548 chance = level * 4 / 5 + 20;
549 chance -= 3 * (adj_mag_stat[creature_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
551 if (creature_ptr->lev > level)
553 chance -= 3 * (creature_ptr->lev - level);
555 chance = mod_spell_chance_1(creature_ptr, chance);
556 chance = MAX(chance, adj_mag_fail[creature_ptr->stat_ind[mp_ptr->spell_stat]]);
557 /* Stunning makes spells harder */
558 if (creature_ptr->stun > 50) chance += 25;
559 else if (creature_ptr->stun) chance += 15;
561 if (chance > 95) chance = 95;
563 chance = mod_spell_chance_2(creature_ptr, chance);
565 if (randint0(100) < chance)
567 if (flush_failure) flush();
569 msg_print(_("呪文をうまく唱えられなかった!", "You failed to get the magic off!"));
571 if (randint1(100) >= chance)
572 chg_virtue(creature_ptr, V_CHANCE,-1);
573 take_turn(creature_ptr, 100);
583 if ((sval >= SV_ROD_MIN_DIRECTION) && (sval != SV_ROD_HAVOC) && (sval != SV_ROD_AGGRAVATE) && (sval != SV_ROD_PESTICIDE))
584 if (!get_aim_dir(creature_ptr, &dir)) return FALSE;
585 rod_effect(creature_ptr, sval, dir, &use_charge, powerful, TRUE);
586 if (!use_charge) return FALSE;
588 else if (tval == TV_WAND)
590 if (!get_aim_dir(creature_ptr, &dir)) return FALSE;
591 wand_effect(creature_ptr, sval, dir, powerful, TRUE);
595 staff_effect(creature_ptr, sval, &use_charge, powerful, TRUE, TRUE);
596 if (!use_charge) return FALSE;
598 if (randint1(100) < chance)
599 chg_virtue(creature_ptr, V_CHANCE,1);
601 take_turn(creature_ptr, 100);
602 if (tval == TV_ROD) creature_ptr->magic_num1[item] += k_info[k_idx].pval * EATER_ROD_CHARGE;
603 else creature_ptr->magic_num1[item] -= EATER_CHARGE;