1 #include "wizard/wizard-item-modifier.h"
2 #include "artifact/fixed-art-generator.h"
3 #include "artifact/random-art-effects.h"
4 #include "artifact/random-art-generator.h"
5 #include "core/asking-player.h"
6 #include "core/show-file.h"
7 #include "core/player-update-types.h"
8 #include "core/window-redrawer.h"
9 #include "core/stuff-handler.h"
10 #include "flavor/flavor-describer.h"
11 #include "flavor/object-flavor-types.h"
12 #include "floor/floor-object.h"
13 #include "game-option/cheat-options.h"
14 #include "inventory/inventory-slot-types.h"
15 #include "io/input-key-acceptor.h"
16 #include "io/input-key-requester.h"
17 #include "object-enchant/apply-magic.h"
18 #include "object-enchant/item-apply-magic.h"
19 #include "object-enchant/object-ego.h"
20 #include "object-enchant/special-object-flags.h"
21 #include "object-enchant/tr-types.h"
22 #include "object/item-use-flags.h"
23 #include "object/object-flags.h"
24 #include "object/object-info.h"
25 #include "object/object-kind.h"
26 #include "object/object-kind-hook.h"
27 #include "object/object-mark-types.h"
28 #include "object/object-value.h"
29 #include "util/bit-flags-calculator.h"
30 #include "util/string-processor.h"
31 #include "spell-kind/spells-perception.h"
32 #include "spell/spells-object.h"
33 #include "system/alloc-entries.h"
34 #include "system/artifact-type-definition.h"
35 #include "system/floor-type-definition.h"
36 #include "system/object-type-definition.h"
37 #include "system/player-type-definition.h"
38 #include "system/system-variables.h"
39 #include "term/screen-processor.h"
40 #include "term/term-color-types.h"
41 #include "view/display-messages.h"
42 #include "util/bit-flags-calculator.h"
43 #include "util/int-char-converter.h"
44 #include "wizard/wizard-special-process.h"
45 #include "world/world.h"
51 #define K_MAX_DEPTH 110 /*!< アイテムの階層毎生成率を表示する最大階 */
55 * @brief アイテム設定コマンド一覧表
57 std::vector<std::vector<std::string>> wizard_sub_menu_table = {
58 { "a", _("アーティファクト出現フラグリセット", "Restore aware flag of fixed artifact") },
59 { "A", _("アーティファクトを出現済みにする", "Make a fixed artifact awared") },
60 { "e", _("高級品獲得ドロップ", "Drop excellent object") },
61 { "f", _("*鑑定*", "*Idenfity*") },
62 { "i", _("鑑定", "Idenfity") },
63 { "I", _("インベントリ全*鑑定*", "Idenfity all objects fully in inventory") },
64 { "l", _("指定アイテム番号まで一括鑑定", "Make objects awared to target object id") },
65 { "g", _("上質なアイテムドロップ", "Drop good object") },
66 { "s", _("特別品獲得ドロップ", "Drop special object") },
67 { "w", _("願い", "Wishing") },
68 { "U", _("発動を変更する", "Modify item activation") },
72 * @brief ゲーム設定コマンドの一覧を表示する
74 void display_wizard_sub_menu()
76 for (size_t y = 1; y <= wizard_sub_menu_table.size(); y++)
77 term_erase(14, y, 64);
81 int sz = wizard_sub_menu_table.size();
82 for (int i = 0; i < sz; i++) {
84 ss << wizard_sub_menu_table[i][0] << ") " << wizard_sub_menu_table[i][1];
85 put_str(ss.str().c_str(), r++, c);
91 * @brief キャスト先の型の最小値、最大値でclampする。
96 return static_cast<T>(std::clamp(val,
97 static_cast<int>(std::numeric_limits<T>::min()),
98 static_cast<int>(std::numeric_limits<T>::max())));
101 void wiz_restore_aware_flag_of_fixed_arfifact(ARTIFACT_IDX a_idx, bool aware = false);
102 void wiz_modify_item_activation(player_type *player_ptr);
103 void wiz_identify_full_inventory(player_type *player_ptr);
106 * @brief ゲーム設定コマンドの入力を受け付ける
107 * @param player_ptr プレイヤーの情報へのポインタ
109 void wizard_item_modifier(player_type *player_ptr)
112 display_wizard_sub_menu();
115 get_com("Player Command: ", &cmd, false);
125 wiz_restore_aware_flag_of_fixed_arfifact(command_arg);
128 wiz_restore_aware_flag_of_fixed_arfifact(command_arg, true);
131 if (command_arg <= 0)
134 acquirement(player_ptr, player_ptr->y, player_ptr->x, command_arg, true, false, true);
137 identify_fully(player_ptr, false);
140 if (command_arg <= 0)
143 acquirement(player_ptr, player_ptr->y, player_ptr->x, command_arg, false, false, true);
146 (void)ident_spell(player_ptr, false);
149 wiz_identify_full_inventory(player_ptr);
152 wiz_learn_items_all(player_ptr);
155 if (command_arg <= 0)
158 acquirement(player_ptr, player_ptr->y, player_ptr->x, command_arg, true, true, true);
161 wiz_modify_item_activation(player_ptr);
164 do_cmd_wishing(player_ptr, -1, true, true, true);
170 * @brief 固定アーティファクトの出現フラグをリセットする
171 * @param a_idx 指定したアーティファクトID
173 void wiz_restore_aware_flag_of_fixed_arfifact(ARTIFACT_IDX a_idx, bool aware)
177 sprintf(tmp, "Artifact ID (1-%d): ", max_a_idx - 1);
178 char tmp_val[10] = "";
179 if (!get_string(tmp, tmp_val, 3))
182 a_idx = (ARTIFACT_IDX)atoi(tmp_val);
185 if (a_idx <= 0 || a_idx >= max_a_idx) {
186 msg_format(_("番号は1から%dの間で指定して下さい。", "ID must be between 1 to %d."), max_a_idx - 1);
190 auto *a_ptr = &a_info[a_idx];
191 a_ptr->cur_num = aware ? 1 : 0;
192 msg_print(aware ? "Modified." : "Restored.");
196 * @brief オブジェクトに発動を追加する/変更する
197 * @param catser_ptr プレイヤー情報への参照ポインタ
199 void wiz_modify_item_activation(player_type *player_ptr)
201 concptr q = "Which object? ";
202 concptr s = "Nothing to do with.";
204 auto *o_ptr = choose_object(player_ptr, &item, q, s, USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT);
210 sprintf(tmp, "Artifact ID (1-%d): ", ACT_MAX);
211 char tmp_val[10] = "";
212 if (!get_string(tmp, tmp_val, 3))
215 act_idx = (XTRA16)atoi(tmp_val);
217 if (act_idx <= 0 || act_idx > ACT_MAX) {
218 msg_format(_("番号は1から%dの間で指定して下さい。", "ID must be between 1 to %d."), ACT_MAX - 1);
222 o_ptr->art_flags.set(TR_ACTIVATE);
223 o_ptr->xtra2 = act_idx;
227 * @brief インベントリ内のアイテムを全て*鑑定*済みにする
228 * @param catser_ptr プレイヤー情報への参照ポインタ
230 void wiz_identify_full_inventory(player_type *player_ptr)
232 for (int i = 0; i < INVEN_TOTAL; i++) {
233 object_type *o_ptr = &player_ptr->inventory_list[i];
237 auto k_ptr = &k_info[o_ptr->k_idx];
238 k_ptr->aware = true; //!< @note 記録には残さないためTRUEを立てるのみ
239 set_bits(o_ptr->ident, IDENT_KNOWN | IDENT_FULL_KNOWN);
240 set_bits(o_ptr->marked, OM_TOUCHED);
243 /* Refrect item informaiton onto subwindows without updating inventory */
244 reset_bits(player_ptr->update, PU_COMBINE | PU_REORDER);
245 handle_stuff(player_ptr);
246 set_bits(player_ptr->update, PU_COMBINE | PU_REORDER);
247 set_bits(player_ptr->window_flags, PW_INVEN | PW_EQUIP);
251 * @brief アイテムの階層毎生成率を表示する / Output a rarity graph for a type of object.
252 * @param tval ベースアイテムの大項目ID
253 * @param sval ベースアイテムの小項目ID
257 static void prt_alloc(tval_type tval, OBJECT_SUBTYPE_VALUE sval, TERM_LEN row, TERM_LEN col)
259 uint32_t rarity[K_MAX_DEPTH];
260 (void)C_WIPE(rarity, K_MAX_DEPTH, uint32_t);
261 uint32_t total[K_MAX_DEPTH];
262 (void)C_WIPE(total, K_MAX_DEPTH, uint32_t);
264 (void)C_WIPE(display, 22, int32_t);
267 for (int i = 0; i < K_MAX_DEPTH; i++) {
270 alloc_entry *table = alloc_kind_table;
271 for (int j = 0; j < alloc_kind_size; j++) {
274 if (table[j].level <= i) {
275 prob = table[j].prob1 * GREAT_OBJ * K_MAX_DEPTH;
276 } else if (table[j].level - 1 > 0) {
277 prob = table[j].prob1 * i * K_MAX_DEPTH / (table[j].level - 1);
280 k_ptr = &k_info[table[j].index];
282 total[i] += prob / (GREAT_OBJ * K_MAX_DEPTH);
283 total_frac += prob % (GREAT_OBJ * K_MAX_DEPTH);
285 if ((k_ptr->tval == tval) && (k_ptr->sval == sval)) {
287 rarity[i] += prob / (GREAT_OBJ * K_MAX_DEPTH);
291 total[i] += total_frac / (GREAT_OBJ * K_MAX_DEPTH);
294 for (int i = 0; i < 22; i++) {
296 for (int j = i * K_MAX_DEPTH / 22; j < (i + 1) * K_MAX_DEPTH / 22; j++)
297 possibility += rarity[j] * 100000 / total[j];
299 display[i] = possibility / 5;
302 for (int i = 0; i < 22; i++) {
303 term_putch(col, row + i + 1, TERM_WHITE, '|');
304 prt(format("%2dF", (i * 5)), row + i + 1, col);
305 if ((i * K_MAX_DEPTH / 22 <= home) && (home < (i + 1) * K_MAX_DEPTH / 22))
306 c_prt(TERM_RED, format("%3d.%04d%%", display[i] / 1000, display[i] % 1000), row + i + 1, col + 3);
308 c_prt(TERM_WHITE, format("%3d.%04d%%", display[i] / 1000, display[i] % 1000), row + i + 1, col + 3);
311 concptr r = "+---Rate---+";
316 * @brief 32ビット変数のビット配列を並べて描画する / Output a long int in binary format.
318 static void prt_binary(BIT_FLAGS flags, const int row, int col)
321 for (int i = bitmask = 1; i <= 32; i++, bitmask *= 2)
323 term_putch(col++, row, TERM_BLUE, '*');
325 term_putch(col++, row, TERM_WHITE, '-');
329 * @brief アイテムの詳細ステータスを表示する /
330 * Change various "permanent" player variables.
331 * @param player_ptr プレイヤーへの参照ポインタ
332 * @param o_ptr 詳細を表示するアイテム情報の参照ポインタ
334 static void wiz_display_item(player_type *player_ptr, object_type *o_ptr)
336 auto flgs = object_flags(o_ptr);
337 auto get_seq_32bits = [](const TrFlags &flgs, uint start) {
338 BIT_FLAGS result = 0U;
339 for (auto i = 0U; i < 32 && start + i < flgs.size(); i++) {
340 if (flgs.has(i2enum<tr_type>(start + i))) {
347 for (int i = 1; i <= 23; i++)
350 prt_alloc(o_ptr->tval, o_ptr->sval, 1, 0);
352 describe_flavor(player_ptr, buf, o_ptr, OD_STORE);
354 prt(format("kind = %-5d level = %-4d tval = %-5d sval = %-5d", o_ptr->k_idx, k_info[o_ptr->k_idx].level, o_ptr->tval, o_ptr->sval), 4, j);
355 prt(format("number = %-3d wgt = %-6d ac = %-5d damage = %dd%d", o_ptr->number, o_ptr->weight, o_ptr->ac, o_ptr->dd, o_ptr->ds), 5, j);
356 prt(format("pval = %-5d toac = %-5d tohit = %-4d todam = %-4d", o_ptr->pval, o_ptr->to_a, o_ptr->to_h, o_ptr->to_d), 6, j);
357 prt(format("name1 = %-4d name2 = %-4d cost = %ld", o_ptr->name1, o_ptr->name2, (long)object_value_real(o_ptr)), 7, j);
358 prt(format("ident = %04x xtra1 = %-4d xtra2 = %-4d timeout = %-d", o_ptr->ident, o_ptr->xtra1, o_ptr->xtra2, o_ptr->timeout), 8, j);
359 prt(format("xtra3 = %-4d xtra4 = %-4d xtra5 = %-4d cursed = %-d", o_ptr->xtra3, o_ptr->xtra4, o_ptr->xtra5, o_ptr->curse_flags), 9, j);
361 prt("+------------FLAGS1------------+", 10, j);
362 prt("AFFECT........SLAY........BRAND.", 11, j);
363 prt(" mf cvae xsqpaefc", 12, j);
364 prt("siwdccsossidsahanvudotgddhuoclio", 13, j);
365 prt("tnieohtctrnipttmiinmrrnrrraiierl", 14, j);
366 prt("rtsxnarelcfgdkcpmldncltggpksdced", 15, j);
367 prt_binary(get_seq_32bits(flgs, 32 * 0), 16, j);
369 prt("+------------FLAGS2------------+", 17, j);
370 prt("SUST....IMMUN.RESIST............", 18, j);
371 prt(" reaefctrpsaefcpfldbc sn ", 19, j);
372 prt("siwdcciaclioheatcliooeialoshtncd", 20, j);
373 prt("tnieohdsierlrfraierliatrnnnrhehi", 21, j);
374 prt("rtsxnaeydcedwlatdcedsrekdfddrxss", 22, j);
375 prt_binary(get_seq_32bits(flgs, 32 * 1), 23, j);
377 prt("+------------FLAGS3------------+", 10, j + 32);
378 prt("fe cnn t stdrmsiiii d ab ", 11, j + 32);
379 prt("aa aoomywhs lleeieihgggg rtgl ", 12, j + 32);
380 prt("uu utmacaih eielgggonnnnaaere ", 13, j + 32);
381 prt("rr reanurdo vtieeehtrrrrcilas ", 14, j + 32);
382 prt("aa algarnew ienpsntsaefctnevs ", 15, j + 32);
383 prt_binary(get_seq_32bits(flgs, 32 * 2), 16, j + 32);
385 prt("+------------FLAGS4------------+", 17, j + 32);
386 prt("KILL....ESP......... ", 18, j + 32);
387 prt("aeud tghaud tgdhegnu ", 19, j + 32);
388 prt("nvneoriunneoriruvoon ", 20, j + 32);
389 prt("iidmroamidmroagmionq ", 21, j + 32);
390 prt("mlenclnmmenclnnnldlu ", 22, j + 32);
391 prt_binary(get_seq_32bits(flgs, 32 * 3), 23, j + 32);
395 * @brief 検査対象のアイテムを基準とした生成テストを行う /
396 * Try to create an item again. Output some statistics. -Bernd-
397 * @param player_ptr プレイヤーへの参照ポインタ
398 * @param o_ptr 生成テストの基準となるアイテム情報の参照ポインタ
399 * The statistics are correct now. We acquire a clean grid, and then
400 * repeatedly place an object in this grid, copying it into an item
401 * holder, and then deleting the object. We fiddle with the artifact
402 * counter flags to prevent weirdness. We use the items to collect
403 * statistics on item creation relative to the initial item.
405 static void wiz_statistics(player_type *player_ptr, object_type *o_ptr)
407 concptr q = "Rolls: %ld Correct: %ld Matches: %ld Better: %ld Worse: %ld Other: %ld";
408 concptr p = "Enter number of items to roll: ";
411 if (o_ptr->is_fixed_artifact())
412 a_info[o_ptr->name1].cur_num = 0;
414 uint32_t i, matches, better, worse, other, correct;
415 uint32_t test_roll = 1000000;
420 concptr pmt = "Roll for [n]ormal, [g]ood, or [e]xcellent treasure? ";
421 wiz_display_item(player_ptr, o_ptr);
422 if (!get_com(pmt, &ch, false))
425 if (ch == 'n' || ch == 'N') {
428 } else if (ch == 'g' || ch == 'G') {
431 } else if (ch == 'e' || ch == 'E') {
432 mode = AM_GOOD | AM_GREAT;
433 quality = "excellent";
438 sprintf(tmp_val, "%ld", (long int)test_roll);
439 if (get_string(p, tmp_val, 10))
440 test_roll = atol(tmp_val);
441 test_roll = MAX(1, test_roll);
442 msg_format("Creating a lot of %s items. Base level = %d.", quality, player_ptr->current_floor_ptr->dun_level);
445 correct = matches = better = worse = other = 0;
446 for (i = 0; i <= test_roll; i++) {
447 if ((i < 100) || (i % 100 == 0)) {
451 break; // stop rolling
454 prt(format(q, i, correct, matches, better, worse, other), 0, 0);
459 object_type *q_ptr = &forge;
461 make_object(player_ptr, q_ptr, mode);
462 if (q_ptr->is_fixed_artifact())
463 a_info[q_ptr->name1].cur_num = 0;
465 if ((o_ptr->tval != q_ptr->tval) || (o_ptr->sval != q_ptr->sval))
469 if ((q_ptr->pval == o_ptr->pval) && (q_ptr->to_a == o_ptr->to_a) && (q_ptr->to_h == o_ptr->to_h) && (q_ptr->to_d == o_ptr->to_d)
470 && (q_ptr->name1 == o_ptr->name1)) {
472 } else if ((q_ptr->pval >= o_ptr->pval) && (q_ptr->to_a >= o_ptr->to_a) && (q_ptr->to_h >= o_ptr->to_h) && (q_ptr->to_d >= o_ptr->to_d)) {
474 } else if ((q_ptr->pval <= o_ptr->pval) && (q_ptr->to_a <= o_ptr->to_a) && (q_ptr->to_h <= o_ptr->to_h) && (q_ptr->to_d <= o_ptr->to_d)) {
481 msg_format(q, i, correct, matches, better, worse, other);
485 if (o_ptr->is_fixed_artifact())
486 a_info[o_ptr->name1].cur_num = 1;
490 * @brief アイテムの質を選択して再生成する /
491 * Apply magic to an item or turn it into an artifact. -Bernd-
492 * @param o_ptr 再生成の対象となるアイテム情報の参照ポインタ
494 static void wiz_reroll_item(player_type *player_ptr, object_type *o_ptr)
496 if (o_ptr->is_artifact())
502 q_ptr->copy_from(o_ptr);
505 bool changed = false;
507 wiz_display_item(player_ptr, q_ptr);
508 if (!get_com("[a]ccept, [w]orthless, [c]ursed, [n]ormal, [g]ood, [e]xcellent, [s]pecial? ", &ch, false)) {
509 if (q_ptr->is_fixed_artifact()) {
510 a_info[q_ptr->name1].cur_num = 0;
518 if (ch == 'A' || ch == 'a') {
523 if (q_ptr->is_fixed_artifact()) {
524 a_info[q_ptr->name1].cur_num = 0;
528 switch (tolower(ch)) {
529 /* Apply bad magic, but first clear object */
531 q_ptr->prep(o_ptr->k_idx);
532 apply_magic_to_object(player_ptr, q_ptr, player_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD | AM_GREAT | AM_CURSED);
534 /* Apply bad magic, but first clear object */
536 q_ptr->prep(o_ptr->k_idx);
537 apply_magic_to_object(player_ptr, q_ptr, player_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD | AM_CURSED);
539 /* Apply normal magic, but first clear object */
541 q_ptr->prep(o_ptr->k_idx);
542 apply_magic_to_object(player_ptr, q_ptr, player_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART);
544 /* Apply good magic, but first clear object */
546 q_ptr->prep(o_ptr->k_idx);
547 apply_magic_to_object(player_ptr, q_ptr, player_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD);
549 /* Apply great magic, but first clear object */
551 q_ptr->prep(o_ptr->k_idx);
552 apply_magic_to_object(player_ptr, q_ptr, player_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD | AM_GREAT);
554 /* Apply special magic, but first clear object */
556 q_ptr->prep(o_ptr->k_idx);
557 apply_magic_to_object(player_ptr, q_ptr, player_ptr->current_floor_ptr->dun_level, AM_GOOD | AM_GREAT | AM_SPECIAL);
558 if (!q_ptr->is_artifact())
559 become_random_artifact(player_ptr, q_ptr, false);
566 q_ptr->iy = o_ptr->iy;
567 q_ptr->ix = o_ptr->ix;
568 q_ptr->marked = o_ptr->marked;
574 o_ptr->copy_from(q_ptr);
575 set_bits(player_ptr->update, PU_BONUS | PU_COMBINE | PU_REORDER);
576 set_bits(player_ptr->window_flags, PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER | PW_FLOOR_ITEM_LIST);
580 * @briefアイテムの基礎能力値を調整する / Tweak an item
581 * @param player_ptr プレイヤーへの参照ポインタ
582 * @param o_ptr 調整するアイテムの参照ポインタ
584 static void wiz_tweak_item(player_type *player_ptr, object_type *o_ptr)
586 if (o_ptr->is_artifact())
589 concptr p = "Enter new 'pval' setting: ";
591 sprintf(tmp_val, "%d", o_ptr->pval);
592 if (!get_string(p, tmp_val, 5))
595 o_ptr->pval = clamp_cast<int16_t>(atoi(tmp_val));
596 wiz_display_item(player_ptr, o_ptr);
597 p = "Enter new 'to_a' setting: ";
598 sprintf(tmp_val, "%d", o_ptr->to_a);
599 if (!get_string(p, tmp_val, 5))
602 o_ptr->to_a = clamp_cast<int16_t>(atoi(tmp_val));
603 wiz_display_item(player_ptr, o_ptr);
604 p = "Enter new 'to_h' setting: ";
605 sprintf(tmp_val, "%d", o_ptr->to_h);
606 if (!get_string(p, tmp_val, 5))
609 o_ptr->to_h = clamp_cast<int16_t>(atoi(tmp_val));
610 wiz_display_item(player_ptr, o_ptr);
611 p = "Enter new 'to_d' setting: ";
612 sprintf(tmp_val, "%d", (int)o_ptr->to_d);
613 if (!get_string(p, tmp_val, 5))
616 o_ptr->to_d = clamp_cast<int16_t>(atoi(tmp_val));
617 wiz_display_item(player_ptr, o_ptr);
621 * @brief 検査対象のアイテムの数を変更する /
622 * Change the quantity of a the item
623 * @param player_ptr プレイヤーへの参照ポインタ
624 * @param o_ptr 変更するアイテム情報構造体の参照ポインタ
626 static void wiz_quantity_item(object_type *o_ptr)
628 if (o_ptr->is_artifact())
631 int tmp_qnt = o_ptr->number;
633 sprintf(tmp_val, "%d", (int)o_ptr->number);
634 if (get_string("Quantity: ", tmp_val, 2)) {
635 int tmp_int = atoi(tmp_val);
642 o_ptr->number = (byte)tmp_int;
645 if (o_ptr->tval == TV_ROD)
646 o_ptr->pval = o_ptr->pval * o_ptr->number / tmp_qnt;
650 * @brief アイテムを弄るデバッグコマンド
651 * Play with an item. Options include:
653 * - Output statistics (via wiz_roll_item)<br>
654 * - Reroll item (via wiz_reroll_item)<br>
655 * - Change properties (via wiz_tweak_item)<br>
656 * - Change the number of items (via wiz_quantity_item)<br>
658 void wiz_modify_item(player_type *player_ptr)
660 concptr q = "Play with which object? ";
661 concptr s = "You have nothing to play with.";
664 o_ptr = choose_object(player_ptr, &item, q, s, USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT);
673 q_ptr->copy_from(o_ptr);
675 bool changed = false;
677 wiz_display_item(player_ptr, q_ptr);
678 if (!get_com("[a]ccept [s]tatistics [r]eroll [t]weak [q]uantity? ", &ch, false)) {
683 if (ch == 'A' || ch == 'a') {
688 if (ch == 's' || ch == 'S') {
689 wiz_statistics(player_ptr, q_ptr);
692 if (ch == 'r' || ch == 'R') {
693 wiz_reroll_item(player_ptr, q_ptr);
696 if (ch == 't' || ch == 'T') {
697 wiz_tweak_item(player_ptr, q_ptr);
700 if (ch == 'q' || ch == 'Q') {
701 wiz_quantity_item(q_ptr);
707 msg_print("Changes accepted.");
709 o_ptr->copy_from(q_ptr);
710 set_bits(player_ptr->update, PU_BONUS | PU_COMBINE | PU_REORDER);
711 set_bits(player_ptr->window_flags, PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER | PW_FLOOR_ITEM_LIST);
713 msg_print("Changes ignored.");
718 * @brief オブジェクトの装備スロットがエゴが有効なスロットかどうか判定
720 static int is_slot_able_to_be_ego(player_type *player_ptr, object_type *o_ptr)
722 int slot = wield_slot(player_ptr, o_ptr);
727 if ((o_ptr->tval == TV_SHOT) || (o_ptr->tval == TV_ARROW) || (o_ptr->tval == TV_BOLT))
734 * @brief 願ったが消えてしまった場合のメッセージ
736 static void wishing_puff_of_smoke(void)
738 msg_print(_("何かが足下に転がってきたが、煙のように消えてしまった。",
739 "You feel something roll beneath your feet, but it disappears in a puff of smoke!"));
743 * @brief 願ったが消えてしまった場合のメッセージ
744 * @param player_ptr 願ったプレイヤー情報への参照ポインタ
745 * @param prob ★などを願った場合の生成確率
746 * @param art_ok アーティファクトの生成を許すならTRUE
747 * @param ego_ok エゴの生成を許すならTRUE
748 * @param confirm 願わない場合に確認するかどうか
751 WishResult do_cmd_wishing(player_type *player_ptr, int prob, bool allow_art, bool allow_ego, bool confirm)
753 concptr fixed_str[] = {
770 char buf[MAX_NLEN] = "\0";
773 object_type *o_ptr = &forge;
774 char o_name[MAX_NLEN];
776 bool wish_art = false;
777 bool wish_randart = false;
778 bool wish_ego = false;
779 bool exam_base = true;
780 bool ok_art = (randint0(100) < prob) ? true : false;
781 bool ok_ego = (randint0(100) < 50 + prob) ? true : false;
782 bool must = (prob < 0) ? true : false;
783 bool blessed = false;
787 if (get_string(_("何をお望み? ", "For what do you wish?"), buf, (MAX_NLEN - 1)))
790 if (!get_check(_("何も願いません。本当によろしいですか?", "Do you wish nothing, really? ")))
793 return WishResult::NOTHING;
800 if (!strncmp(buf, "a ", 2))
801 str = ltrim(str + 1);
802 else if (!strncmp(buf, "an ", 3))
803 str = ltrim(str + 2);
808 if (!strncmp(str, _("祝福された", "blessed"), _(10, 7))) {
809 str = ltrim(str + _(10, 7));
813 for (int i = 0; fixed_str[i] != nullptr; i++) {
814 int len = strlen(fixed_str[i]);
815 if (!strncmp(str, fixed_str[i], len)) {
816 str = ltrim(str + len);
823 if (!strncmp(str, "★", 2)) {
824 str = ltrim(str + 2);
830 if (!strncmp(str, _("☆", "The "), _(2, 4))) {
831 str = ltrim(str + _(2, 4));
836 /* wishing random ego ? */
837 else if (!strncmp(str, _("高級な", "excellent "), _(6, 9))) {
838 str = ltrim(str + _(6, 9));
842 if (strlen(str) < 1) {
843 msg_print(_("名前がない!", "What?"));
844 return WishResult::NOTHING;
847 if (!allow_art && wish_art) {
848 msg_print(_("アーティファクトは願えない!", "You can not wish artifacts!"));
849 return WishResult::NOTHING;
853 msg_format("Wishing %s....", buf);
855 std::vector<KIND_OBJECT_IDX> k_ids;
856 std::vector<EGO_IDX> e_ids;
860 for (KIND_OBJECT_IDX k = 1; k < max_k_idx; k++) {
861 object_kind *k_ptr = &k_info[k];
862 if (k_ptr->name.empty())
866 describe_flavor(player_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY | OD_STORE));
871 msg_format("Matching object No.%d %s", k, o_name);
873 len = strlen(o_name);
875 if (_(!strrncmp(str, o_name, len), !strncmp(str, o_name, len))) {
883 if (allow_ego && k_ids.size() == 1) {
884 KIND_OBJECT_IDX k_idx = k_ids.back();
887 for (EGO_IDX k = 1; k < max_e_idx; k++) {
888 ego_item_type *e_ptr = &e_info[k];
889 if (e_ptr->name.empty())
892 strcpy(o_name, e_ptr->name.c_str());
897 msg_format("Mathcing ego No.%d %s...", k, o_name);
899 if (_(!strncmp(str, o_name, strlen(o_name)), !strrncmp(str, o_name, strlen(o_name)))) {
900 if (is_slot_able_to_be_ego(player_ptr, o_ptr) != e_ptr->slot)
909 std::vector<ARTIFACT_IDX> a_ids;
912 char a_desc[MAX_NLEN] = "\0";
913 char *a_str = a_desc;
917 for (ARTIFACT_IDX i = 1; i < max_a_idx; i++) {
918 artifact_type *a_ptr = &a_info[i];
919 if (a_ptr->name.empty())
922 KIND_OBJECT_IDX k_idx = lookup_kind(a_ptr->tval, a_ptr->sval);
929 describe_flavor(player_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY | OD_STORE));
934 strcpy(a_desc, a_ptr->name.c_str());
940 if (!strncmp(a_str, "『", 2)) {
942 char *s = strstr(a_str, "』");
947 int l = strlen(a_str);
948 if (!strrncmp(a_str, "の", 2)) {
954 if (a_str[0] == '\'') {
956 char *s = strchr(a_desc, '\'');
960 else if (!strncmp(a_str, (const char *)"of ", 3)) {
968 msg_format("Matching artifact No.%d %s(%s)", i, a_desc, _(&o_name[2], o_name));
970 std::vector<const char *> l = { a_str, a_ptr->name.c_str(), _(&o_name[2], o_name) };
971 for (size_t c = 0; c < l.size(); c++) {
972 if (!strcmp(str, l.at(c))) {
973 len = strlen(l.at(c));
983 if (w_ptr->wizard && (a_ids.size() > 1 || e_ids.size() > 1)) {
984 msg_print(_("候補が多すぎる!", "Too many matches!"));
985 return WishResult::FAIL;
988 if (a_ids.size() == 1) {
989 ARTIFACT_IDX a_idx = a_ids.back();
990 if (must || (ok_art && !a_info[a_idx].cur_num)) {
991 create_named_art(player_ptr, a_idx, player_ptr->y, player_ptr->x);
993 a_info[a_idx].cur_num = 1;
996 wishing_puff_of_smoke();
997 return WishResult::ARTIFACT;
1000 if (!allow_ego && (wish_ego || e_ids.size() > 0)) {
1001 msg_print(_("エゴアイテムは願えない!", "Can not wish ego item."));
1002 return WishResult::NOTHING;
1005 if (k_ids.size() == 1) {
1006 KIND_OBJECT_IDX k_idx = k_ids.back();
1007 object_kind *k_ptr = &k_info[k_idx];
1009 artifact_type *a_ptr;
1010 ARTIFACT_IDX a_idx = 0;
1011 if (k_ptr->gen_flags.has(TRG::INSTA_ART)) {
1012 for (ARTIFACT_IDX i = 1; i < max_a_idx; i++) {
1014 if (a_ptr->tval != k_ptr->tval || a_ptr->sval != k_ptr->sval)
1022 a_ptr = &a_info[a_idx];
1023 if (must || (ok_art && !a_ptr->cur_num)) {
1024 create_named_art(player_ptr, a_idx, player_ptr->y, player_ptr->x);
1026 a_info[a_idx].cur_num = 1;
1029 wishing_puff_of_smoke();
1030 return WishResult::ARTIFACT;
1034 if (must || ok_art) {
1037 apply_magic_to_object(player_ptr, o_ptr, k_ptr->level, (AM_SPECIAL | AM_NO_FIXED_ART));
1038 } while (!o_ptr->art_name || o_ptr->name1 || o_ptr->name2 || o_ptr->is_cursed());
1040 if (o_ptr->art_name)
1041 drop_near(player_ptr, o_ptr, -1, player_ptr->y, player_ptr->x);
1043 wishing_puff_of_smoke();
1045 return WishResult::ARTIFACT;
1048 WishResult res = WishResult::NOTHING;
1049 if (allow_ego && (wish_ego || e_ids.size() > 0)) {
1050 if (must || ok_ego) {
1051 if (e_ids.size() > 0) {
1053 o_ptr->name2 = e_ids[0];
1054 apply_ego(o_ptr, player_ptr->current_floor_ptr->base_level);
1056 int max_roll = 1000;
1058 for (i = 0; i < max_roll; i++) {
1060 (void)apply_magic_to_object(player_ptr, o_ptr, k_ptr->level, (AM_GREAT | AM_NO_FIXED_ART));
1062 if (o_ptr->name1 || o_ptr->art_name)
1069 for (auto e : e_ids) {
1070 if (o_ptr->name2 == e) {
1080 if (i == max_roll) {
1081 msg_print(_("失敗!もう一度願ってみてください。", "Failed! Try again."));
1082 return WishResult::FAIL;
1086 wishing_puff_of_smoke();
1089 res = WishResult::EGO;
1091 for (int i = 0; i < 100; i++) {
1093 apply_magic_to_object(player_ptr, o_ptr, 0, (AM_NO_FIXED_ART));
1094 if (!o_ptr->is_cursed())
1097 res = WishResult::NORMAL;
1100 if (blessed && wield_slot(player_ptr, o_ptr) != -1)
1101 o_ptr->art_flags.set(TR_BLESSED);
1103 if (fixed && wield_slot(player_ptr, o_ptr) != -1) {
1104 o_ptr->art_flags.set(TR_IGNORE_ACID);
1105 o_ptr->art_flags.set(TR_IGNORE_FIRE);
1108 (void)drop_near(player_ptr, o_ptr, -1, player_ptr->y, player_ptr->x);
1113 msg_print(_("うーん、そんなものは存在しないようだ。", "Ummmm, that is not existing..."));
1114 return WishResult::FAIL;