OSDN Git Service

Merge branch 'master' of https://github.com/hengband/hengband
[hengbandforosx/hengbandosx.git] / src / wizard / wizard-item-modifier.cpp
1 #include "wizard/wizard-item-modifier.h"
2 #include "artifact/fixed-art-generator.h"
3 #include "artifact/fixed-art-types.h"
4 #include "artifact/random-art-effects.h"
5 #include "artifact/random-art-generator.h"
6 #include "core/asking-player.h"
7 #include "core/show-file.h"
8 #include "core/stuff-handler.h"
9 #include "core/window-redrawer.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/item-apply-magic.h"
18 #include "object-enchant/item-magic-applier.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-hook.h"
26 #include "object/object-mark-types.h"
27 #include "object/object-value.h"
28 #include "spell-kind/spells-perception.h"
29 #include "spell/spells-object.h"
30 #include "system/alloc-entries.h"
31 #include "system/artifact-type-definition.h"
32 #include "system/baseitem-info.h"
33 #include "system/floor-type-definition.h"
34 #include "system/item-entity.h"
35 #include "system/player-type-definition.h"
36 #include "system/redrawing-flags-updater.h"
37 #include "system/system-variables.h"
38 #include "term/screen-processor.h"
39 #include "term/term-color-types.h"
40 #include "term/z-form.h"
41 #include "util/bit-flags-calculator.h"
42 #include "util/int-char-converter.h"
43 #include "util/string-processor.h"
44 #include "view/display-messages.h"
45 #include "wizard/wizard-messages.h"
46 #include "wizard/wizard-special-process.h"
47 #include "world/world.h"
48 #include <algorithm>
49 #include <limits>
50 #include <sstream>
51 #include <tuple>
52 #include <vector>
53
54 constexpr auto BASEITEM_MAX_DEPTH = 110; /*!< アイテムの階層毎生成率を表示する最大階 */
55
56 namespace {
57 /*!
58  * @brief アイテム設定コマンド一覧表
59  */
60 constexpr std::array wizard_sub_menu_table = {
61     std::make_tuple('a', _("アーティファクト出現フラグリセット", "Restore aware flag of fixed artifact")),
62     std::make_tuple('A', _("アーティファクトを出現済みにする", "Make a fixed artifact awared")),
63     std::make_tuple('B', _("フロア相当の呪物ドロップ", "Drop cursed item")),
64     std::make_tuple('c', _("フロア相当の一般品獲得ドロップ (★不許可)", "Drop normal item (excluding fixed artifacts)")),
65     std::make_tuple('C', _("フロア相当の一般品獲得ドロップ (★許可)", "Drop normal item (including fixed artifacts)")),
66     std::make_tuple('d', _("フロア相当の上質品獲得ドロップ", "Drop good item")),
67     std::make_tuple('D', _("フロア相当の高級品獲得ドロップ", "Drop excellent item")),
68     std::make_tuple('e', _("フロア相当のエゴ品獲得ドロップ", "Drop excellent item")),
69     std::make_tuple('E', _("フロア相当の特別品獲得ドロップ", "Drop special item")),
70     std::make_tuple('f', _("*鑑定*", "*Idenfity*")),
71     std::make_tuple('i', _("鑑定", "Idenfity")),
72     std::make_tuple('I', _("インベントリ全*鑑定*", "Idenfity all items fully in inventory")),
73     std::make_tuple('l', _("指定アイテム番号まで一括鑑定", "Make items awared to target item id")),
74     std::make_tuple('U', _("発動を変更する", "Modify item activation")),
75     std::make_tuple('w', _("願い", "Wishing")),
76 };
77
78 /*!
79  * @brief ゲーム設定コマンドの一覧を表示する
80  */
81 void display_wizard_sub_menu()
82 {
83     for (auto y = 1U; y <= wizard_sub_menu_table.size(); y++) {
84         term_erase(14, y, 64);
85     }
86
87     int r = 1;
88     int c = 15;
89     for (const auto &[symbol, desc] : wizard_sub_menu_table) {
90         std::stringstream ss;
91         ss << symbol << ") " << desc;
92         put_str(ss.str(), r++, c);
93     }
94 }
95 }
96
97 /*!
98  * @brief キャスト先の型の最小値、最大値でclampする。
99  */
100 template <typename T>
101 T clamp_cast(int val)
102 {
103     return static_cast<T>(std::clamp(val,
104         static_cast<int>(std::numeric_limits<T>::min()),
105         static_cast<int>(std::numeric_limits<T>::max())));
106 }
107
108 void wiz_restore_aware_flag_of_fixed_arfifact(FixedArtifactId reset_artifact_idx, bool aware = false);
109 void wiz_modify_item_activation(PlayerType *player_ptr);
110 void wiz_identify_full_inventory(PlayerType *player_ptr);
111
112 static void wiz_item_drop(PlayerType *player_ptr, const int num_items, const EnumClassFlagGroup<ItemMagicAppliance> &appliance)
113 {
114     uint mode = AM_NONE;
115     const auto is_cursed = appliance.has(ItemMagicAppliance::CURSED);
116     if (is_cursed) {
117         mode |= AM_CURSED;
118     }
119
120     if (appliance.has(ItemMagicAppliance::GOOD)) {
121         mode |= AM_GOOD;
122     }
123
124     if (appliance.has(ItemMagicAppliance::GREAT)) {
125         mode |= AM_GREAT;
126     }
127
128     if (appliance.has(ItemMagicAppliance::SPECIAL)) {
129         mode |= AM_SPECIAL;
130     }
131
132     for (auto i = 0; i < num_items; i++) {
133         ItemEntity item;
134         if (!make_object(player_ptr, &item, mode)) {
135             continue;
136         }
137
138         if (is_cursed && !item.is_cursed()) {
139             i--;
140             continue;
141         }
142
143         if (appliance.has(ItemMagicAppliance::EGO) && !item.is_ego()) {
144             i--;
145             continue;
146         }
147
148         if (!drop_near(player_ptr, &item, -1, player_ptr->y, player_ptr->x)) {
149             msg_print_wizard(player_ptr, 0, "No item dropping space!");
150             return;
151         }
152     }
153 }
154
155 /*!
156  * @brief ゲーム設定コマンドの入力を受け付ける
157  * @param player_ptr プレイヤーの情報へのポインタ
158  */
159 void wizard_item_modifier(PlayerType *player_ptr)
160 {
161     screen_save();
162     display_wizard_sub_menu();
163
164     char cmd;
165     get_com("Player Command: ", &cmd, false);
166     screen_load();
167
168     switch (cmd) {
169     case ESCAPE:
170     case ' ':
171     case '\n':
172     case '\r':
173         break;
174     case 'a':
175         wiz_restore_aware_flag_of_fixed_arfifact(i2enum<FixedArtifactId>(command_arg));
176         break;
177     case 'A':
178         wiz_restore_aware_flag_of_fixed_arfifact(i2enum<FixedArtifactId>(command_arg), true);
179         break;
180     case 'B':
181         command_arg = std::clamp<short>(command_arg, 1, 999);
182         wiz_item_drop(player_ptr, command_arg, { ItemMagicAppliance::CURSED });
183         break;
184     case 'c':
185         command_arg = std::clamp<short>(command_arg, 1, 999);
186         wiz_item_drop(player_ptr, command_arg, { ItemMagicAppliance::NO_FIXED_ART });
187         break;
188     case 'C':
189         command_arg = std::clamp<short>(command_arg, 1, 999);
190         wiz_item_drop(player_ptr, command_arg, {});
191         break;
192     case 'd':
193         command_arg = std::clamp<short>(command_arg, 1, 999);
194         wiz_item_drop(player_ptr, command_arg, { ItemMagicAppliance::GOOD });
195         break;
196     case 'D':
197         command_arg = std::clamp<short>(command_arg, 1, 999);
198         wiz_item_drop(player_ptr, command_arg, { ItemMagicAppliance::GOOD, ItemMagicAppliance::GREAT });
199         break;
200     case 'e':
201         command_arg = std::clamp<short>(command_arg, 1, 999);
202         wiz_item_drop(player_ptr, command_arg, { ItemMagicAppliance::GOOD, ItemMagicAppliance::GREAT, ItemMagicAppliance::EGO });
203         break;
204     case 'E':
205         command_arg = std::clamp<short>(command_arg, 1, 999);
206         wiz_item_drop(player_ptr, command_arg, { ItemMagicAppliance::GOOD, ItemMagicAppliance::GREAT, ItemMagicAppliance::SPECIAL });
207         break;
208     case 'f':
209         identify_fully(player_ptr, false);
210         break;
211     case 'i':
212         (void)ident_spell(player_ptr, false);
213         break;
214     case 'I':
215         wiz_identify_full_inventory(player_ptr);
216         break;
217     case 'l':
218         wiz_learn_items_all(player_ptr);
219         break;
220     case 'U':
221         wiz_modify_item_activation(player_ptr);
222         break;
223     case 'w':
224         do_cmd_wishing(player_ptr, -1, true, true, true);
225         break;
226     }
227 }
228
229 /*!
230  * @brief 固定アーティファクトの出現フラグをリセットする
231  * @param a_idx 指定したアーティファクトID
232  * @details 外からはenum class を受け取るが、この関数内では数値の直指定処理なので数値型にキャストする.
233  */
234 void wiz_restore_aware_flag_of_fixed_arfifact(FixedArtifactId reset_artifact_idx, bool aware)
235 {
236     auto max_a_idx = enum2i(artifacts_info.rbegin()->first);
237     int int_a_idx = enum2i(reset_artifact_idx);
238     if (int_a_idx <= 0) {
239         if (!get_value("Artifact ID", 1, max_a_idx, &int_a_idx)) {
240             return;
241         }
242     }
243
244     ArtifactsInfo::get_instance().get_artifact(i2enum<FixedArtifactId>(int_a_idx)).is_generated = aware;
245     msg_print(aware ? "Modified." : "Restored.");
246 }
247
248 /*!
249  * @brief オブジェクトに発動を追加する/変更する
250  * @param catser_ptr プレイヤー情報への参照ポインタ
251  */
252 void wiz_modify_item_activation(PlayerType *player_ptr)
253 {
254     constexpr auto q = _("どのアイテムの発動を変更しますか? ", "Which item? ");
255     constexpr auto s = _("発動を変更するアイテムがない。", "Nothing to do with.");
256     short item;
257     auto *o_ptr = choose_object(player_ptr, &item, q, s, USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT);
258     if (!o_ptr) {
259         return;
260     }
261
262     int val;
263     if (!get_value("Activation ID", enum2i(RandomArtActType::NONE), enum2i(RandomArtActType::MAX) - 1, &val)) {
264         return;
265     }
266
267     auto act_idx = i2enum<RandomArtActType>(val);
268     o_ptr->art_flags.set(TR_ACTIVATE);
269     o_ptr->activation_id = act_idx;
270 }
271
272 /*!
273  * @brief インベントリ内のアイテムを全て*鑑定*済みにする
274  * @param catser_ptr プレイヤー情報への参照ポインタ
275  */
276 void wiz_identify_full_inventory(PlayerType *player_ptr)
277 {
278     for (int i = 0; i < INVEN_TOTAL; i++) {
279         auto *o_ptr = &player_ptr->inventory_list[i];
280         if (!o_ptr->is_valid()) {
281             continue;
282         }
283
284         auto &baseitem = o_ptr->get_baseitem();
285         baseitem.aware = true; //!< @note 記録には残さないためTRUEを立てるのみ
286         set_bits(o_ptr->ident, IDENT_KNOWN | IDENT_FULL_KNOWN);
287         o_ptr->marked.set(OmType::TOUCHED);
288     }
289
290     auto &rfu = RedrawingFlagsUpdater::get_instance();
291     static constexpr auto flags_srf = {
292         StatusRecalculatingFlag::COMBINATION,
293         StatusRecalculatingFlag::REORDER,
294     };
295     rfu.set_flags(flags_srf);
296     static constexpr auto flags_swrf = {
297         SubWindowRedrawingFlag::INVENTORY,
298         SubWindowRedrawingFlag::EQUIPMENT,
299     };
300     rfu.set_flags(flags_swrf);
301 }
302
303 /*!
304  * @brief アイテムの階層毎生成率を表示する / Output a rarity graph for a type of object.
305  * @param tval ベースアイテムの大項目ID
306  * @param sval ベースアイテムの小項目ID
307  * @param row 表示列
308  * @param col 表示行
309  */
310 static void prt_alloc(const BaseitemKey &bi_key, TERM_LEN row, TERM_LEN col)
311 {
312     uint32_t rarity[BASEITEM_MAX_DEPTH]{};
313     uint32_t total[BASEITEM_MAX_DEPTH]{};
314     int32_t display[22]{};
315
316     auto home = 0;
317     for (auto i = 0; i < BASEITEM_MAX_DEPTH; i++) {
318         auto total_frac = 0;
319         constexpr auto magnificant = CHANCE_BASEITEM_LEVEL_BOOST * BASEITEM_MAX_DEPTH;
320         for (const auto &entry : alloc_kind_table) {
321             auto prob = 0;
322             if (entry.level <= i) {
323                 prob = entry.prob1 * magnificant;
324             } else if (entry.level - 1 > 0) {
325                 prob = entry.prob1 * i * BASEITEM_MAX_DEPTH / (entry.level - 1);
326             }
327
328             const auto &baseitem = entry.get_baseitem();
329             total[i] += prob / magnificant;
330             total_frac += prob % magnificant;
331
332             if (baseitem.bi_key == bi_key) {
333                 home = baseitem.level;
334                 rarity[i] += prob / magnificant;
335             }
336         }
337
338         total[i] += total_frac / magnificant;
339     }
340
341     for (auto i = 0; i < 22; i++) {
342         auto possibility = 0;
343         for (int j = i * BASEITEM_MAX_DEPTH / 22; j < (i + 1) * BASEITEM_MAX_DEPTH / 22; j++) {
344             possibility += rarity[j] * 100000 / total[j];
345         }
346
347         display[i] = possibility / 5;
348     }
349
350     for (auto i = 0; i < 22; i++) {
351         term_putch(col, row + i + 1, TERM_WHITE, '|');
352         prt(format("%2dF", (i * 5)), row + i + 1, col);
353         if ((i * BASEITEM_MAX_DEPTH / 22 <= home) && (home < (i + 1) * BASEITEM_MAX_DEPTH / 22)) {
354             c_prt(TERM_RED, format("%3d.%04d%%", display[i] / 1000, display[i] % 1000), row + i + 1, col + 3);
355         } else {
356             c_prt(TERM_WHITE, format("%3d.%04d%%", display[i] / 1000, display[i] % 1000), row + i + 1, col + 3);
357         }
358     }
359
360     concptr r = "+---Rate---+";
361     prt(r, row, col);
362 }
363
364 /*!
365  * @brief 32ビット変数のビット配列を並べて描画する / Output a long int in binary format.
366  */
367 static void prt_binary(BIT_FLAGS flags, const int row, int col)
368 {
369     uint32_t bitmask;
370     for (int i = bitmask = 1; i <= 32; i++, bitmask *= 2) {
371         if (flags & bitmask) {
372             term_putch(col++, row, TERM_BLUE, '*');
373         } else {
374             term_putch(col++, row, TERM_WHITE, '-');
375         }
376     }
377 }
378
379 /*!
380  * @brief アイテムの詳細ステータスを表示する /
381  * Change various "permanent" player variables.
382  * @param player_ptr プレイヤーへの参照ポインタ
383  * @param o_ptr 詳細を表示するアイテム情報の参照ポインタ
384  */
385 static void wiz_display_item(PlayerType *player_ptr, ItemEntity *o_ptr)
386 {
387     auto flags = object_flags(o_ptr);
388     auto get_seq_32bits = [](const TrFlags &flags, uint start) {
389         BIT_FLAGS result = 0U;
390         for (auto i = 0U; i < 32 && start + i < flags.size(); i++) {
391             if (flags.has(i2enum<tr_type>(start + i))) {
392                 result |= 1U << i;
393             }
394         }
395         return result;
396     };
397     int j = 13;
398     for (int i = 1; i <= 23; i++) {
399         prt("", i, j - 2);
400     }
401
402     prt_alloc(o_ptr->bi_key, 1, 0);
403     const auto item_name = describe_flavor(player_ptr, o_ptr, OD_STORE);
404     prt(item_name, 2, j);
405
406     auto line = 4;
407     const auto &bi_key = o_ptr->bi_key;
408     const auto item_level = o_ptr->get_baseitem().level;
409     prt(format("kind = %-5d  level = %-4d  tval = %-5d  sval = %-5d", o_ptr->bi_id, item_level, enum2i(bi_key.tval()), bi_key.sval().value()), line, j);
410     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), ++line, j);
411     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), ++line, j);
412     prt(format("fixed_artifact_idx = %-4d  ego_idx = %-4d  cost = %d", enum2i(o_ptr->fixed_artifact_idx), enum2i(o_ptr->ego_idx), object_value_real(o_ptr)), ++line, j);
413     prt(format("ident = %04x  activation_id = %-4d  timeout = %-d", o_ptr->ident, enum2i(o_ptr->activation_id), o_ptr->timeout), ++line, j);
414     prt(format("chest_level = %-4d  fuel = %-d", o_ptr->chest_level, o_ptr->fuel), ++line, j);
415     prt(format("smith_hit = %-4d  smith_damage = %-4d", o_ptr->smith_hit, o_ptr->smith_damage), ++line, j);
416     prt(format("cursed  = %-4lX  captured_monster_speed = %-4d", o_ptr->curse_flags.to_ulong(), o_ptr->captured_monster_speed), ++line, j);
417     prt(format("captured_monster_max_hp = %-4d  captured_monster_max_hp = %-4d", o_ptr->captured_monster_current_hp, o_ptr->captured_monster_max_hp), ++line, j);
418
419     prt("+------------FLAGS1------------+", ++line, j);
420     prt("AFFECT........SLAY........BRAND.", ++line, j);
421     prt("      mf      cvae      xsqpaefc", ++line, j);
422     prt("siwdccsossidsahanvudotgddhuoclio", ++line, j);
423     prt("tnieohtctrnipttmiinmrrnrrraiierl", ++line, j);
424     prt("rtsxnarelcfgdkcpmldncltggpksdced", ++line, j);
425     prt_binary(get_seq_32bits(flags, 32 * 0), ++line, j);
426
427     prt("+------------FLAGS2------------+", ++line, j);
428     prt("SUST....IMMUN.RESIST............", ++line, j);
429     prt("      reaefctrpsaefcpfldbc sn   ", ++line, j);
430     prt("siwdcciaclioheatcliooeialoshtncd", ++line, j);
431     prt("tnieohdsierlrfraierliatrnnnrhehi", ++line, j);
432     prt("rtsxnaeydcedwlatdcedsrekdfddrxss", ++line, j);
433     prt_binary(get_seq_32bits(flags, 32 * 1), ++line, j);
434
435     line = 13;
436     prt("+------------FLAGS3------------+", line, j + 32);
437     prt("fe cnn t      stdrmsiiii d ab   ", ++line, j + 32);
438     prt("aa aoomywhs lleeieihgggg rtgl   ", ++line, j + 32);
439     prt("uu utmacaih eielgggonnnnaaere   ", ++line, j + 32);
440     prt("rr reanurdo vtieeehtrrrrcilas   ", ++line, j + 32);
441     prt("aa algarnew ienpsntsaefctnevs   ", ++line, j + 32);
442     prt_binary(get_seq_32bits(flags, 32 * 2), ++line, j + 32);
443
444     prt("+------------FLAGS4------------+", ++line, j + 32);
445     prt("KILL....ESP.........            ", ++line, j + 32);
446     prt("aeud tghaud tgdhegnu            ", ++line, j + 32);
447     prt("nvneoriunneoriruvoon            ", ++line, j + 32);
448     prt("iidmroamidmroagmionq            ", ++line, j + 32);
449     prt("mlenclnmmenclnnnldlu            ", ++line, j + 32);
450     prt_binary(get_seq_32bits(flags, 32 * 3), ++line, j + 32);
451 }
452
453 /*!
454  * @brief 検査対象のアイテムを基準とした生成テストを行う /
455  * Try to create an item again. Output some statistics.    -Bernd-
456  * @param player_ptr プレイヤーへの参照ポインタ
457  * @param o_ptr 生成テストの基準となるアイテム情報の参照ポインタ
458  * The statistics are correct now.  We acquire a clean grid, and then
459  * repeatedly place an object in this grid, copying it into an item
460  * holder, and then deleting the object.  We fiddle with the artifact
461  * counter flags to prevent weirdness.  We use the items to collect
462  * statistics on item creation relative to the initial item.
463  */
464 static void wiz_statistics(PlayerType *player_ptr, ItemEntity *o_ptr)
465 {
466     concptr q = "Rolls: %ld  Correct: %ld  Matches: %ld  Better: %ld  Worse: %ld  Other: %ld";
467     concptr p = "Enter number of items to roll: ";
468     char tmp_val[80];
469
470     if (o_ptr->is_fixed_artifact()) {
471         o_ptr->get_fixed_artifact().is_generated = false;
472     }
473
474     uint32_t i, matches, better, worse, other, correct;
475     uint32_t test_roll = 1000000;
476     char ch;
477     concptr quality;
478     BIT_FLAGS mode;
479     while (true) {
480         concptr pmt = "Roll for [n]ormal, [g]ood, or [e]xcellent treasure? ";
481         wiz_display_item(player_ptr, o_ptr);
482         if (!get_com(pmt, &ch, false)) {
483             break;
484         }
485
486         if (ch == 'n' || ch == 'N') {
487             mode = 0L;
488             quality = "normal";
489         } else if (ch == 'g' || ch == 'G') {
490             mode = AM_GOOD;
491             quality = "good";
492         } else if (ch == 'e' || ch == 'E') {
493             mode = AM_GOOD | AM_GREAT;
494             quality = "excellent";
495         } else {
496             break;
497         }
498
499         strnfmt(tmp_val, sizeof(tmp_val), "%ld", (long int)test_roll);
500         if (get_string(p, tmp_val, 10)) {
501             test_roll = atol(tmp_val);
502         }
503         test_roll = std::max<uint>(1, test_roll);
504         msg_format("Creating a lot of %s items. Base level = %d.", quality, player_ptr->current_floor_ptr->dun_level);
505         msg_print(nullptr);
506
507         correct = matches = better = worse = other = 0;
508         for (i = 0; i <= test_roll; i++) {
509             if ((i < 100) || (i % 100 == 0)) {
510                 inkey_scan = true;
511                 if (inkey()) {
512                     flush();
513                     break; // stop rolling
514                 }
515
516                 prt(format(q, i, correct, matches, better, worse, other), 0, 0);
517                 term_fresh();
518             }
519
520             ItemEntity forge;
521             auto *q_ptr = &forge;
522             q_ptr->wipe();
523             make_object(player_ptr, q_ptr, mode);
524             if (q_ptr->is_fixed_artifact()) {
525                 q_ptr->get_fixed_artifact().is_generated = false;
526             }
527
528             if (o_ptr->bi_key != q_ptr->bi_key) {
529                 continue;
530             }
531
532             correct++;
533             const auto is_same_fixed_artifact_idx = o_ptr->is_specific_artifact(q_ptr->fixed_artifact_idx);
534             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) && is_same_fixed_artifact_idx) {
535                 matches++;
536             } 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)) {
537                 better++;
538             } 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)) {
539                 worse++;
540             } else {
541                 other++;
542             }
543         }
544
545         msg_format(q, i, correct, matches, better, worse, other);
546         msg_print(nullptr);
547     }
548
549     if (o_ptr->is_fixed_artifact()) {
550         o_ptr->get_fixed_artifact().is_generated = true;
551     }
552 }
553
554 /*!
555  * @brief アイテムの質を選択して再生成する /
556  * Apply magic to an item or turn it into an artifact. -Bernd-
557  * @param o_ptr 再生成の対象となるアイテム情報の参照ポインタ
558  */
559 static void wiz_reroll_item(PlayerType *player_ptr, ItemEntity *o_ptr)
560 {
561     if (o_ptr->is_fixed_or_random_artifact()) {
562         return;
563     }
564
565     ItemEntity forge;
566     ItemEntity *q_ptr;
567     q_ptr = &forge;
568     q_ptr->copy_from(o_ptr);
569
570     char ch;
571     bool changed = false;
572     while (true) {
573         wiz_display_item(player_ptr, q_ptr);
574         if (!get_com("[a]ccept, [w]orthless, [c]ursed, [n]ormal, [g]ood, [e]xcellent, [s]pecial? ", &ch, false)) {
575             if (q_ptr->is_fixed_artifact()) {
576                 q_ptr->get_fixed_artifact().is_generated = false;
577                 q_ptr->fixed_artifact_idx = FixedArtifactId::NONE;
578             }
579
580             changed = false;
581             break;
582         }
583
584         if (ch == 'A' || ch == 'a') {
585             changed = true;
586             break;
587         }
588
589         if (q_ptr->is_fixed_artifact()) {
590             q_ptr->get_fixed_artifact().is_generated = false;
591             q_ptr->fixed_artifact_idx = FixedArtifactId::NONE;
592         }
593
594         switch (tolower(ch)) {
595         /* Apply bad magic, but first clear object */
596         case 'w':
597             q_ptr->prep(o_ptr->bi_id);
598             ItemMagicApplier(player_ptr, q_ptr, player_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD | AM_GREAT | AM_CURSED).execute();
599             break;
600         /* Apply bad magic, but first clear object */
601         case 'c':
602             q_ptr->prep(o_ptr->bi_id);
603             ItemMagicApplier(player_ptr, q_ptr, player_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD | AM_CURSED).execute();
604             break;
605         /* Apply normal magic, but first clear object */
606         case 'n':
607             q_ptr->prep(o_ptr->bi_id);
608             ItemMagicApplier(player_ptr, q_ptr, player_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART).execute();
609             break;
610         /* Apply good magic, but first clear object */
611         case 'g':
612             q_ptr->prep(o_ptr->bi_id);
613             ItemMagicApplier(player_ptr, q_ptr, player_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD).execute();
614             break;
615         /* Apply great magic, but first clear object */
616         case 'e':
617             q_ptr->prep(o_ptr->bi_id);
618             ItemMagicApplier(player_ptr, q_ptr, player_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD | AM_GREAT).execute();
619             break;
620         /* Apply special magic, but first clear object */
621         case 's':
622             q_ptr->prep(o_ptr->bi_id);
623             ItemMagicApplier(player_ptr, q_ptr, player_ptr->current_floor_ptr->dun_level, AM_GOOD | AM_GREAT | AM_SPECIAL).execute();
624             if (!q_ptr->is_fixed_or_random_artifact()) {
625                 become_random_artifact(player_ptr, q_ptr, false);
626             }
627
628             break;
629         default:
630             break;
631         }
632
633         q_ptr->iy = o_ptr->iy;
634         q_ptr->ix = o_ptr->ix;
635         q_ptr->marked = o_ptr->marked;
636     }
637
638     if (!changed) {
639         return;
640     }
641
642     o_ptr->copy_from(q_ptr);
643     auto &rfu = RedrawingFlagsUpdater::get_instance();
644     static constexpr auto flags_srf = {
645         StatusRecalculatingFlag::BONUS,
646         StatusRecalculatingFlag::COMBINATION,
647         StatusRecalculatingFlag::REORDER,
648     };
649     rfu.set_flags(flags_srf);
650     static constexpr auto flags_swrf = {
651         SubWindowRedrawingFlag::INVENTORY,
652         SubWindowRedrawingFlag::EQUIPMENT,
653         SubWindowRedrawingFlag::SPELL,
654         SubWindowRedrawingFlag::PLAYER,
655         SubWindowRedrawingFlag::FLOOR_ITEMS,
656         SubWindowRedrawingFlag::FOUND_ITEMS,
657     };
658     rfu.set_flags(flags_swrf);
659 }
660
661 /*!
662  * @briefアイテムの基礎能力値を調整する / Tweak an item
663  * @param player_ptr プレイヤーへの参照ポインタ
664  * @param o_ptr 調整するアイテムの参照ポインタ
665  */
666 static void wiz_tweak_item(PlayerType *player_ptr, ItemEntity *o_ptr)
667 {
668     if (o_ptr->is_fixed_or_random_artifact()) {
669         return;
670     }
671
672     concptr p = "Enter new 'pval' setting: ";
673     char tmp_val[80];
674     strnfmt(tmp_val, sizeof(tmp_val), "%d", o_ptr->pval);
675     if (!get_string(p, tmp_val, 5)) {
676         return;
677     }
678
679     o_ptr->pval = clamp_cast<int16_t>(atoi(tmp_val));
680     wiz_display_item(player_ptr, o_ptr);
681     p = "Enter new 'to_a' setting: ";
682     strnfmt(tmp_val, sizeof(tmp_val), "%d", o_ptr->to_a);
683     if (!get_string(p, tmp_val, 5)) {
684         return;
685     }
686
687     o_ptr->to_a = clamp_cast<int16_t>(atoi(tmp_val));
688     wiz_display_item(player_ptr, o_ptr);
689     p = "Enter new 'to_h' setting: ";
690     strnfmt(tmp_val, sizeof(tmp_val), "%d", o_ptr->to_h);
691     if (!get_string(p, tmp_val, 5)) {
692         return;
693     }
694
695     o_ptr->to_h = clamp_cast<int16_t>(atoi(tmp_val));
696     wiz_display_item(player_ptr, o_ptr);
697     p = "Enter new 'to_d' setting: ";
698     strnfmt(tmp_val, sizeof(tmp_val), "%d", (int)o_ptr->to_d);
699     if (!get_string(p, tmp_val, 5)) {
700         return;
701     }
702
703     o_ptr->to_d = clamp_cast<int16_t>(atoi(tmp_val));
704     wiz_display_item(player_ptr, o_ptr);
705 }
706
707 /*!
708  * @brief 検査対象のアイテムの数を変更する /
709  * Change the quantity of a the item
710  * @param player_ptr プレイヤーへの参照ポインタ
711  * @param o_ptr 変更するアイテム情報構造体の参照ポインタ
712  */
713 static void wiz_quantity_item(ItemEntity *o_ptr)
714 {
715     if (o_ptr->is_fixed_or_random_artifact()) {
716         return;
717     }
718
719     int tmp_qnt = o_ptr->number;
720     char tmp_val[100];
721     strnfmt(tmp_val, sizeof(tmp_val), "%d", (int)o_ptr->number);
722     if (get_string("Quantity: ", tmp_val, 2)) {
723         int tmp_int = atoi(tmp_val);
724         if (tmp_int < 1) {
725             tmp_int = 1;
726         }
727
728         if (tmp_int > 99) {
729             tmp_int = 99;
730         }
731
732         o_ptr->number = (byte)tmp_int;
733     }
734
735     if (o_ptr->bi_key.tval() == ItemKindType::ROD) {
736         o_ptr->pval = o_ptr->pval * o_ptr->number / tmp_qnt;
737     }
738 }
739
740 /*!
741  * @brief アイテムを弄るデバッグコマンド
742  * Play with an item. Options include:
743  * @details
744  *   - Output statistics (via wiz_roll_item)<br>
745  *   - Reroll item (via wiz_reroll_item)<br>
746  *   - Change properties (via wiz_tweak_item)<br>
747  *   - Change the number of items (via wiz_quantity_item)<br>
748  */
749 void wiz_modify_item(PlayerType *player_ptr)
750 {
751     constexpr auto q = "Play with which object? ";
752     constexpr auto s = "You have nothing to play with.";
753     short item;
754     auto *o_ptr = choose_object(player_ptr, &item, q, s, USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT);
755     if (!o_ptr) {
756         return;
757     }
758
759     screen_save();
760
761     ItemEntity forge;
762     ItemEntity *q_ptr;
763     q_ptr = &forge;
764     q_ptr->copy_from(o_ptr);
765     char ch;
766     bool changed = false;
767     while (true) {
768         wiz_display_item(player_ptr, q_ptr);
769         if (!get_com("[a]ccept [s]tatistics [r]eroll [t]weak [q]uantity? ", &ch, false)) {
770             changed = false;
771             break;
772         }
773
774         if (ch == 'A' || ch == 'a') {
775             changed = true;
776             break;
777         }
778
779         if (ch == 's' || ch == 'S') {
780             wiz_statistics(player_ptr, q_ptr);
781         }
782
783         if (ch == 'r' || ch == 'R') {
784             wiz_reroll_item(player_ptr, q_ptr);
785         }
786
787         if (ch == 't' || ch == 'T') {
788             wiz_tweak_item(player_ptr, q_ptr);
789         }
790
791         if (ch == 'q' || ch == 'Q') {
792             wiz_quantity_item(q_ptr);
793         }
794     }
795
796     screen_load();
797     if (changed) {
798         msg_print("Changes accepted.");
799
800         o_ptr->copy_from(q_ptr);
801         auto &rfu = RedrawingFlagsUpdater::get_instance();
802         static constexpr auto flags_srf = {
803             StatusRecalculatingFlag::BONUS,
804             StatusRecalculatingFlag::COMBINATION,
805             StatusRecalculatingFlag::REORDER,
806         };
807         rfu.set_flags(flags_srf);
808         static constexpr auto flags_swrf = {
809             SubWindowRedrawingFlag::INVENTORY,
810             SubWindowRedrawingFlag::EQUIPMENT,
811             SubWindowRedrawingFlag::SPELL,
812             SubWindowRedrawingFlag::PLAYER,
813             SubWindowRedrawingFlag::FLOOR_ITEMS,
814             SubWindowRedrawingFlag::FOUND_ITEMS,
815         };
816         rfu.set_flags(flags_swrf);
817     } else {
818         msg_print("Changes ignored.");
819     }
820 }
821
822 /*!
823  * @brief オブジェクトの装備スロットがエゴが有効なスロットかどうか判定
824  */
825 static int is_slot_able_to_be_ego(PlayerType *player_ptr, ItemEntity *o_ptr)
826 {
827     int slot = wield_slot(player_ptr, o_ptr);
828
829     if (slot > -1) {
830         return slot;
831     }
832
833     if (o_ptr->is_ammo()) {
834         return INVEN_AMMO;
835     }
836
837     return -1;
838 }
839
840 /*!
841  * @brief 願ったが消えてしまった場合のメッセージ
842  */
843 static void wishing_puff_of_smoke(void)
844 {
845     msg_print(_("何かが足下に転がってきたが、煙のように消えてしまった。",
846         "You feel something roll beneath your feet, but it disappears in a puff of smoke!"));
847 }
848
849 /*!
850  * @brief 願ったが消えてしまった場合のメッセージ
851  * @param player_ptr 願ったプレイヤー情報への参照ポインタ
852  * @param prob ★などを願った場合の生成確率
853  * @param art_ok アーティファクトの生成を許すならTRUE
854  * @param ego_ok エゴの生成を許すならTRUE
855  * @param confirm 願わない場合に確認するかどうか
856  * @return 願った結果
857  */
858 WishResultType do_cmd_wishing(PlayerType *player_ptr, int prob, bool allow_art, bool allow_ego, bool confirm)
859 {
860     concptr fixed_str[] = {
861 #ifdef JP
862         "燃えない",
863         "錆びない",
864         "腐食しない",
865         "安定した",
866 #else
867         "rotproof",
868         "fireproof",
869         "rustproof",
870         "erodeproof",
871         "corrodeproof",
872         "fixed",
873 #endif
874         nullptr,
875     };
876
877     char buf[MAX_NLEN] = "\0";
878     char *str = buf;
879     ItemEntity forge;
880     auto *o_ptr = &forge;
881     bool wish_art = false;
882     bool wish_randart = false;
883     bool wish_ego = false;
884     bool exam_base = true;
885     bool ok_art = randint0(100) < prob;
886     bool ok_ego = randint0(100) < 50 + prob;
887     bool must = prob < 0;
888     bool blessed = false;
889     bool fixed = true;
890
891     while (1) {
892         if (get_string(_("何をお望み? ", "For what do you wish?"), buf, (MAX_NLEN - 1))) {
893             break;
894         }
895         if (confirm) {
896             if (!get_check(_("何も願いません。本当によろしいですか?", "Do you wish nothing, really? "))) {
897                 continue;
898             }
899         }
900         return WishResultType::NOTHING;
901     }
902
903 #ifndef JP
904     str_tolower(str);
905
906     /* remove 'a' */
907     if (!strncmp(buf, "a ", 2)) {
908         str = ltrim(str + 1);
909     } else if (!strncmp(buf, "an ", 3)) {
910         str = ltrim(str + 2);
911     }
912 #endif // !JP
913
914     str = rtrim(str);
915
916     if (!strncmp(str, _("祝福された", "blessed"), _(10, 7))) {
917         str = ltrim(str + _(10, 7));
918         blessed = true;
919     }
920
921     for (int i = 0; fixed_str[i] != nullptr; i++) {
922         int len = strlen(fixed_str[i]);
923         if (!strncmp(str, fixed_str[i], len)) {
924             str = ltrim(str + len);
925             fixed = true;
926             break;
927         }
928     }
929
930 #ifdef JP
931     if (!strncmp(str, "★", 2)) {
932         str = ltrim(str + 2);
933         wish_art = true;
934         exam_base = false;
935     } else
936 #endif
937
938         if (!strncmp(str, _("☆", "The "), _(2, 4))) {
939         str = ltrim(str + _(2, 4));
940         wish_art = true;
941         wish_randart = true;
942     }
943
944     /* wishing random ego ? */
945     else if (!strncmp(str, _("高級な", "excellent "), _(6, 9))) {
946         str = ltrim(str + _(6, 9));
947         wish_ego = true;
948     }
949
950     if (strlen(str) < 1) {
951         msg_print(_("名前がない!", "What?"));
952         return WishResultType::NOTHING;
953     }
954
955     if (!allow_art && wish_art) {
956         msg_print(_("アーティファクトは願えない!", "You can not wish artifacts!"));
957         return WishResultType::NOTHING;
958     }
959
960     if (cheat_xtra) {
961         msg_format("Wishing %s....", buf);
962     }
963
964     std::vector<short> k_ids;
965     std::vector<EgoType> e_ids;
966     if (exam_base) {
967         int max_len = 0;
968         for (const auto &baseitem : baseitems_info) {
969             if (baseitem.idx == 0 || baseitem.name.empty()) {
970                 continue;
971             }
972
973             o_ptr->prep(baseitem.idx);
974 #ifdef JP
975             const auto item_name = describe_flavor(player_ptr, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY | OD_STORE));
976 #else
977             auto item_name = describe_flavor(player_ptr, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY | OD_STORE));
978             str_tolower(item_name.data());
979 #endif
980             if (cheat_xtra) {
981                 msg_format("Matching object No.%d %s", baseitem.idx, item_name.data());
982             }
983
984             const int len = item_name.length();
985             if (std::string(str).find(item_name) != std::string::npos) {
986                 if (len > max_len) {
987                     k_ids.push_back(baseitem.idx);
988                     max_len = len;
989                 }
990             }
991         }
992
993         if (allow_ego && k_ids.size() == 1) {
994             short bi_id = k_ids.back();
995             o_ptr->prep(bi_id);
996
997             for (const auto &[e_idx, ego] : egos_info) {
998                 if (ego.idx == EgoType::NONE || ego.name.empty()) {
999                     continue;
1000                 }
1001
1002                 std::string item_name(ego.name);
1003 #ifdef JP
1004 #else
1005                 str_tolower(item_name.data());
1006 #endif
1007                 if (cheat_xtra) {
1008                     msg_format("matching ego no.%d %s...", enum2i(ego.idx), item_name.data());
1009                 }
1010
1011                 if (std::string(str).find(item_name) != std::string::npos) {
1012                     if (is_slot_able_to_be_ego(player_ptr, o_ptr) != ego.slot) {
1013                         continue;
1014                     }
1015
1016                     e_ids.push_back(ego.idx);
1017                 }
1018             }
1019         }
1020     }
1021
1022     std::vector<FixedArtifactId> a_ids;
1023
1024     if (allow_art) {
1025         char a_desc[MAX_NLEN] = "\0";
1026         char *a_str = a_desc;
1027
1028         int len;
1029         int mlen = 0;
1030         for (const auto &[a_idx, artifact] : artifacts_info) {
1031             if (a_idx == FixedArtifactId::NONE || artifact.name.empty()) {
1032                 continue;
1033             }
1034
1035             const auto bi_id = lookup_baseitem_id(artifact.bi_key);
1036             if (bi_id == 0) {
1037                 continue;
1038             }
1039
1040             o_ptr->prep(bi_id);
1041             o_ptr->fixed_artifact_idx = a_idx;
1042
1043 #ifdef JP
1044             const auto item_name = describe_flavor(player_ptr, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY | OD_STORE));
1045 #else
1046             auto item_name = describe_flavor(player_ptr, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY | OD_STORE));
1047             str_tolower(item_name.data());
1048 #endif
1049             a_str = a_desc;
1050             strcpy(a_desc, artifact.name.data());
1051
1052             if (*a_str == '$') {
1053                 a_str++;
1054             }
1055 #ifdef JP
1056             /* remove quotes */
1057             if (!strncmp(a_str, "『", 2)) {
1058                 a_str += 2;
1059                 char *s = strstr(a_str, "』");
1060                 *s = '\0';
1061             }
1062             /* remove 'of' */
1063             else {
1064                 int l = strlen(a_str);
1065                 if (!strrncmp(a_str, "の", 2)) {
1066                     a_str[l - 2] = '\0';
1067                 }
1068             }
1069 #else
1070             /* remove quotes */
1071             if (a_str[0] == '\'') {
1072                 a_str += 1;
1073                 char *s = strchr(a_desc, '\'');
1074                 *s = '\0';
1075             }
1076             /* remove 'of ' */
1077             else if (!strncmp(a_str, (const char *)"of ", 3)) {
1078                 a_str += 3;
1079             }
1080
1081             str_tolower(a_str);
1082 #endif
1083             const auto match_name = _(item_name.data() + 2, item_name.data());
1084             if (cheat_xtra) {
1085                 msg_format("Matching artifact No.%d %s(%s)", enum2i(a_idx), a_desc, match_name);
1086             }
1087
1088             std::vector<const char *> l = { a_str, artifact.name.data(), match_name };
1089             for (size_t c = 0; c < l.size(); c++) {
1090                 if (!strcmp(str, l.at(c))) {
1091                     len = strlen(l.at(c));
1092                     if (len > mlen) {
1093                         a_ids.push_back(a_idx);
1094                         mlen = len;
1095                     }
1096                 }
1097             }
1098         }
1099     }
1100
1101     if (w_ptr->wizard && (a_ids.size() > 1 || e_ids.size() > 1)) {
1102         msg_print(_("候補が多すぎる!", "Too many matches!"));
1103         return WishResultType::FAIL;
1104     }
1105
1106     if (a_ids.size() == 1) {
1107         const auto a_idx = a_ids.back();
1108         const auto &artifact = ArtifactsInfo::get_instance().get_artifact(a_idx);
1109         if (must || (ok_art && !artifact.is_generated)) {
1110             (void)create_named_art(player_ptr, a_idx, player_ptr->y, player_ptr->x);
1111         } else {
1112             wishing_puff_of_smoke();
1113         }
1114
1115         return WishResultType::ARTIFACT;
1116     }
1117
1118     if (!allow_ego && (wish_ego || e_ids.size() > 0)) {
1119         msg_print(_("エゴアイテムは願えない!", "Can not wish ego item."));
1120         return WishResultType::NOTHING;
1121     }
1122
1123     if (k_ids.size() == 1) {
1124         const auto bi_id = k_ids.back();
1125         const auto &baseitem = baseitems_info[bi_id];
1126         auto a_idx = FixedArtifactId::NONE;
1127         if (baseitem.gen_flags.has(ItemGenerationTraitType::INSTA_ART)) {
1128             for (const auto &[a_idx_loop, artifact_loop] : artifacts_info) {
1129                 if (a_idx_loop == FixedArtifactId::NONE || artifact_loop.bi_key != baseitem.bi_key) {
1130                     continue;
1131                 }
1132
1133                 a_idx = a_idx_loop;
1134                 break;
1135             }
1136         }
1137
1138         if (a_idx != FixedArtifactId::NONE) {
1139             const auto &artifact = ArtifactsInfo::get_instance().get_artifact(a_idx);
1140             if (must || (ok_art && !artifact.is_generated)) {
1141                 (void)create_named_art(player_ptr, a_idx, player_ptr->y, player_ptr->x);
1142             } else {
1143                 wishing_puff_of_smoke();
1144             }
1145
1146             return WishResultType::ARTIFACT;
1147         }
1148
1149         if (wish_randart) {
1150             if (must || ok_art) {
1151                 do {
1152                     o_ptr->prep(bi_id);
1153                     ItemMagicApplier(player_ptr, o_ptr, baseitem.level, AM_SPECIAL | AM_NO_FIXED_ART).execute();
1154                 } while (!o_ptr->is_random_artifact() || o_ptr->is_ego() || o_ptr->is_cursed());
1155
1156                 if (o_ptr->is_random_artifact()) {
1157                     drop_near(player_ptr, o_ptr, -1, player_ptr->y, player_ptr->x);
1158                 }
1159             } else {
1160                 wishing_puff_of_smoke();
1161             }
1162             return WishResultType::ARTIFACT;
1163         }
1164
1165         WishResultType res = WishResultType::NOTHING;
1166         if (allow_ego && (wish_ego || e_ids.size() > 0)) {
1167             if (must || ok_ego) {
1168                 if (e_ids.size() > 0) {
1169                     o_ptr->prep(bi_id);
1170                     o_ptr->ego_idx = e_ids[0];
1171                     apply_ego(o_ptr, player_ptr->current_floor_ptr->base_level);
1172                 } else {
1173                     int max_roll = 1000;
1174                     int i = 0;
1175                     for (i = 0; i < max_roll; i++) {
1176                         o_ptr->prep(bi_id);
1177                         ItemMagicApplier(player_ptr, o_ptr, baseitem.level, AM_GREAT | AM_NO_FIXED_ART).execute();
1178                         if (o_ptr->is_random_artifact()) {
1179                             continue;
1180                         }
1181
1182                         if (wish_ego) {
1183                             break;
1184                         }
1185
1186                         EgoType e_idx = EgoType::NONE;
1187                         for (auto e : e_ids) {
1188                             if (o_ptr->ego_idx == e) {
1189                                 e_idx = e;
1190                                 break;
1191                             }
1192                         }
1193
1194                         if (e_idx != EgoType::NONE) {
1195                             break;
1196                         }
1197                     }
1198
1199                     if (i == max_roll) {
1200                         msg_print(_("失敗!もう一度願ってみてください。", "Failed! Try again."));
1201                         return WishResultType::FAIL;
1202                     }
1203                 }
1204             } else {
1205                 wishing_puff_of_smoke();
1206             }
1207
1208             res = WishResultType::EGO;
1209         } else {
1210             for (int i = 0; i < 100; i++) {
1211                 o_ptr->prep(bi_id);
1212                 ItemMagicApplier(player_ptr, o_ptr, 0, AM_NO_FIXED_ART).execute();
1213                 if (!o_ptr->is_cursed()) {
1214                     break;
1215                 }
1216             }
1217             res = WishResultType::NORMAL;
1218         }
1219
1220         if (blessed && wield_slot(player_ptr, o_ptr) != -1) {
1221             o_ptr->art_flags.set(TR_BLESSED);
1222         }
1223
1224         if (fixed && wield_slot(player_ptr, o_ptr) != -1) {
1225             o_ptr->art_flags.set(TR_IGNORE_ACID);
1226             o_ptr->art_flags.set(TR_IGNORE_FIRE);
1227         }
1228
1229         (void)drop_near(player_ptr, o_ptr, -1, player_ptr->y, player_ptr->x);
1230
1231         return res;
1232     }
1233
1234     msg_print(_("うーん、そんなものは存在しないようだ。", "Ummmm, that is not existing..."));
1235     return WishResultType::FAIL;
1236 }