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-hook/hook-enchant.h"
23 #include "object-hook/hook-checker.h"
24 #include "object/item-use-flags.h"
25 #include "object/object-flags.h"
26 #include "object/object-info.h"
27 #include "object/object-kind.h"
28 #include "object/object-kind-hook.h"
29 #include "object/object-mark-types.h"
30 #include "object/object-value.h"
31 #include "util/bit-flags-calculator.h"
32 #include "util/string-processor.h"
33 #include "spell-kind/spells-perception.h"
34 #include "spell/spells-object.h"
35 #include "system/alloc-entries.h"
36 #include "system/artifact-type-definition.h"
37 #include "system/floor-type-definition.h"
38 #include "system/object-type-definition.h"
39 #include "system/player-type-definition.h"
40 #include "system/system-variables.h"
41 #include "term/screen-processor.h"
42 #include "term/term-color-types.h"
43 #include "view/display-messages.h"
44 #include "util/bit-flags-calculator.h"
45 #include "util/int-char-converter.h"
46 #include "wizard/wizard-special-process.h"
47 #include "world/world.h"
52 #define K_MAX_DEPTH 110 /*!< アイテムの階層毎生成率を表示する最大階 */
56 * @brief アイテム設定コマンド一覧表
58 std::vector<std::vector<std::string>> wizard_sub_menu_table = {
59 { "a", _("アーティファクト出現フラグリセット", "Restore aware flag of fixed artifact") },
60 { "A", _("アーティファクトを出現済みにする", "Make a fixed artifact awared") },
61 { "e", _("高級品獲得ドロップ", "Drop excellent object") },
62 { "f", _("*鑑定*", "*Idenfity*") },
63 { "i", _("鑑定", "Idenfity") },
64 { "I", _("インベントリ全*鑑定*", "Idenfity all objects fully in inventory") },
65 { "l", _("指定アイテム番号まで一括鑑定", "Make objects awared to target object id") },
66 { "g", _("上質なアイテムドロップ", "Drop good object") },
67 { "s", _("特別品獲得ドロップ", "Drop special object") },
68 { "w", _("願い", "Wishing") },
69 { "U", _("発動を変更する", "Modify item activation") },
73 * @brief ゲーム設定コマンドの一覧を表示する
75 void display_wizard_sub_menu()
77 for (size_t y = 1; y <= wizard_sub_menu_table.size(); y++)
78 term_erase(14, y, 64);
82 int sz = wizard_sub_menu_table.size();
83 for (int i = 0; i < sz; i++) {
85 ss << wizard_sub_menu_table[i][0] << ") " << wizard_sub_menu_table[i][1];
86 put_str(ss.str().c_str(), r++, c);
92 * @brief キャスト先の型の最小値、最大値でclampする。
97 return static_cast<T>(std::clamp(val,
98 static_cast<int>(std::numeric_limits<T>::min()),
99 static_cast<int>(std::numeric_limits<T>::max())));
102 void wiz_restore_aware_flag_of_fixed_arfifact(ARTIFACT_IDX a_idx, bool aware = false);
103 void wiz_modify_item_activation(player_type *caster_ptr);
104 void wiz_identify_full_inventory(player_type *caster_ptr);
107 * @brief ゲーム設定コマンドの入力を受け付ける
108 * @param creature_ptr プレイヤーの情報へのポインタ
110 void wizard_item_modifier(player_type *creature_ptr)
113 display_wizard_sub_menu();
116 get_com("Player Command: ", &cmd, FALSE);
126 wiz_restore_aware_flag_of_fixed_arfifact(command_arg);
129 wiz_restore_aware_flag_of_fixed_arfifact(command_arg, true);
132 if (command_arg <= 0)
135 acquirement(creature_ptr, creature_ptr->y, creature_ptr->x, command_arg, TRUE, FALSE, TRUE);
138 identify_fully(creature_ptr, FALSE, TV_NONE);
141 if (command_arg <= 0)
144 acquirement(creature_ptr, creature_ptr->y, creature_ptr->x, command_arg, FALSE, FALSE, TRUE);
147 (void)ident_spell(creature_ptr, FALSE, TV_NONE);
150 wiz_identify_full_inventory(creature_ptr);
153 wiz_learn_items_all(creature_ptr);
156 if (command_arg <= 0)
159 acquirement(creature_ptr, creature_ptr->y, creature_ptr->x, command_arg, TRUE, TRUE, TRUE);
162 wiz_modify_item_activation(creature_ptr);
165 do_cmd_wishing(creature_ptr, -1, TRUE, TRUE, TRUE);
171 * @brief 固定アーティファクトの出現フラグをリセットする
172 * @param a_idx 指定したアーティファクトID
174 void wiz_restore_aware_flag_of_fixed_arfifact(ARTIFACT_IDX a_idx, bool aware)
178 sprintf(tmp, "Artifact ID (1-%d): ", max_a_idx - 1);
179 char tmp_val[10] = "";
180 if (!get_string(tmp, tmp_val, 3))
183 a_idx = (ARTIFACT_IDX)atoi(tmp_val);
186 if (a_idx <= 0 || a_idx >= max_a_idx) {
187 msg_format(_("番号は1から%dの間で指定して下さい。", "ID must be between 1 to %d."), max_a_idx - 1);
191 auto *a_ptr = &a_info[a_idx];
192 a_ptr->cur_num = aware ? 1 : 0;
193 msg_print(aware ? "Modified." : "Restored.");
197 * @brief オブジェクトに発動を追加する/変更する
198 * @param catser_ptr プレイヤー情報への参照ポインタ
200 void wiz_modify_item_activation(player_type *caster_ptr)
202 concptr q = "Which object? ";
203 concptr s = "Nothing to do with.";
205 auto *o_ptr = choose_object(caster_ptr, &item, q, s, USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT, TV_NONE);
211 sprintf(tmp, "Artifact ID (1-%d): ", ACT_MAX);
212 char tmp_val[10] = "";
213 if (!get_string(tmp, tmp_val, 3))
216 act_idx = (XTRA16)atoi(tmp_val);
218 if (act_idx <= 0 || act_idx > ACT_MAX) {
219 msg_format(_("番号は1から%dの間で指定して下さい。", "ID must be between 1 to %d."), ACT_MAX - 1);
223 add_flag(o_ptr->art_flags, TR_ACTIVATE);
224 o_ptr->xtra2 = act_idx;
228 * @brief インベントリ内のアイテムを全て*鑑定*済みにする
229 * @param catser_ptr プレイヤー情報への参照ポインタ
231 void wiz_identify_full_inventory(player_type *caster_ptr)
233 for (int i = 0; i < INVEN_TOTAL; i++) {
234 object_type *o_ptr = &caster_ptr->inventory_list[i];
238 auto k_ptr = &k_info[o_ptr->k_idx];
239 k_ptr->aware = TRUE; //!< @note 記録には残さないためTRUEを立てるのみ
240 set_bits(o_ptr->ident, IDENT_KNOWN | IDENT_FULL_KNOWN);
241 set_bits(o_ptr->marked, OM_TOUCHED);
244 /* Refrect item informaiton onto subwindows without updating inventory */
245 reset_bits(caster_ptr->update, PU_COMBINE | PU_REORDER);
246 handle_stuff(caster_ptr);
247 set_bits(caster_ptr->update, PU_COMBINE | PU_REORDER);
248 set_bits(caster_ptr->window_flags, PW_INVEN | PW_EQUIP);
252 * @brief アイテムの階層毎生成率を表示する / Output a rarity graph for a type of object.
253 * @param tval ベースアイテムの大項目ID
254 * @param sval ベースアイテムの小項目ID
258 static void prt_alloc(tval_type tval, OBJECT_SUBTYPE_VALUE sval, TERM_LEN row, TERM_LEN col)
260 u32b rarity[K_MAX_DEPTH];
261 (void)C_WIPE(rarity, K_MAX_DEPTH, u32b);
262 u32b total[K_MAX_DEPTH];
263 (void)C_WIPE(total, K_MAX_DEPTH, u32b);
265 (void)C_WIPE(display, 22, s32b);
268 for (int i = 0; i < K_MAX_DEPTH; i++) {
271 alloc_entry *table = alloc_kind_table;
272 for (int j = 0; j < alloc_kind_size; j++) {
275 if (table[j].level <= i) {
276 prob = table[j].prob1 * GREAT_OBJ * K_MAX_DEPTH;
277 } else if (table[j].level - 1 > 0) {
278 prob = table[j].prob1 * i * K_MAX_DEPTH / (table[j].level - 1);
281 k_ptr = &k_info[table[j].index];
283 total[i] += prob / (GREAT_OBJ * K_MAX_DEPTH);
284 total_frac += prob % (GREAT_OBJ * K_MAX_DEPTH);
286 if ((k_ptr->tval == tval) && (k_ptr->sval == sval)) {
288 rarity[i] += prob / (GREAT_OBJ * K_MAX_DEPTH);
292 total[i] += total_frac / (GREAT_OBJ * K_MAX_DEPTH);
295 for (int i = 0; i < 22; i++) {
297 for (int j = i * K_MAX_DEPTH / 22; j < (i + 1) * K_MAX_DEPTH / 22; j++)
298 possibility += rarity[j] * 100000 / total[j];
300 display[i] = possibility / 5;
303 for (int i = 0; i < 22; i++) {
304 term_putch(col, row + i + 1, TERM_WHITE, '|');
305 prt(format("%2dF", (i * 5)), row + i + 1, col);
306 if ((i * K_MAX_DEPTH / 22 <= home) && (home < (i + 1) * K_MAX_DEPTH / 22))
307 c_prt(TERM_RED, format("%3d.%04d%%", display[i] / 1000, display[i] % 1000), row + i + 1, col + 3);
309 c_prt(TERM_WHITE, format("%3d.%04d%%", display[i] / 1000, display[i] % 1000), row + i + 1, col + 3);
312 concptr r = "+---Rate---+";
317 * @brief 32ビット変数のビット配列を並べて描画する / Output a long int in binary format.
319 static void prt_binary(BIT_FLAGS flags, const int row, int col)
322 for (int i = bitmask = 1; i <= 32; i++, bitmask *= 2)
324 term_putch(col++, row, TERM_BLUE, '*');
326 term_putch(col++, row, TERM_WHITE, '-');
330 * @brief アイテムの詳細ステータスを表示する /
331 * Change various "permanent" player variables.
332 * @param player_ptr プレーヤーへの参照ポインタ
333 * @param o_ptr 詳細を表示するアイテム情報の参照ポインタ
335 static void wiz_display_item(player_type *player_ptr, object_type *o_ptr)
337 BIT_FLAGS flgs[TR_FLAG_SIZE];
338 object_flags(player_ptr, o_ptr, flgs);
340 for (int i = 1; i <= 23; i++)
343 prt_alloc(o_ptr->tval, o_ptr->sval, 1, 0);
345 describe_flavor(player_ptr, buf, o_ptr, OD_STORE);
347 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);
348 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);
349 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);
350 prt(format("name1 = %-4d name2 = %-4d cost = %ld", o_ptr->name1, o_ptr->name2, (long)object_value_real(player_ptr, o_ptr)), 7, j);
351 prt(format("ident = %04x xtra1 = %-4d xtra2 = %-4d timeout = %-d", o_ptr->ident, o_ptr->xtra1, o_ptr->xtra2, o_ptr->timeout), 8, j);
352 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);
354 prt("+------------FLAGS1------------+", 10, j);
355 prt("AFFECT........SLAY........BRAND.", 11, j);
356 prt(" mf cvae xsqpaefc", 12, j);
357 prt("siwdccsossidsahanvudotgddhuoclio", 13, j);
358 prt("tnieohtctrnipttmiinmrrnrrraiierl", 14, j);
359 prt("rtsxnarelcfgdkcpmldncltggpksdced", 15, j);
360 prt_binary(flgs[0], 16, j);
362 prt("+------------FLAGS2------------+", 17, j);
363 prt("SUST....IMMUN.RESIST............", 18, j);
364 prt(" reaefctrpsaefcpfldbc sn ", 19, j);
365 prt("siwdcciaclioheatcliooeialoshtncd", 20, j);
366 prt("tnieohdsierlrfraierliatrnnnrhehi", 21, j);
367 prt("rtsxnaeydcedwlatdcedsrekdfddrxss", 22, j);
368 prt_binary(flgs[1], 23, j);
370 prt("+------------FLAGS3------------+", 10, j + 32);
371 prt("fe cnn t stdrmsiiii d ab ", 11, j + 32);
372 prt("aa aoomywhs lleeieihgggg rtgl ", 12, j + 32);
373 prt("uu utmacaih eielgggonnnnaaere ", 13, j + 32);
374 prt("rr reanurdo vtieeehtrrrrcilas ", 14, j + 32);
375 prt("aa algarnew ienpsntsaefctnevs ", 15, j + 32);
376 prt_binary(flgs[2], 16, j + 32);
378 prt("+------------FLAGS4------------+", 17, j + 32);
379 prt("KILL....ESP......... ", 18, j + 32);
380 prt("aeud tghaud tgdhegnu ", 19, j + 32);
381 prt("nvneoriunneoriruvoon ", 20, j + 32);
382 prt("iidmroamidmroagmionq ", 21, j + 32);
383 prt("mlenclnmmenclnnnldlu ", 22, j + 32);
384 prt_binary(flgs[3], 23, j + 32);
388 * @brief 検査対象のアイテムを基準とした生成テストを行う /
389 * Try to create an item again. Output some statistics. -Bernd-
390 * @param caster_ptr プレーヤーへの参照ポインタ
391 * @param o_ptr 生成テストの基準となるアイテム情報の参照ポインタ
392 * The statistics are correct now. We acquire a clean grid, and then
393 * repeatedly place an object in this grid, copying it into an item
394 * holder, and then deleting the object. We fiddle with the artifact
395 * counter flags to prevent weirdness. We use the items to collect
396 * statistics on item creation relative to the initial item.
398 static void wiz_statistics(player_type *caster_ptr, object_type *o_ptr)
400 concptr q = "Rolls: %ld Correct: %ld Matches: %ld Better: %ld Worse: %ld Other: %ld";
401 concptr p = "Enter number of items to roll: ";
404 if (object_is_fixed_artifact(o_ptr))
405 a_info[o_ptr->name1].cur_num = 0;
407 u32b i, matches, better, worse, other, correct;
408 u32b test_roll = 1000000;
413 concptr pmt = "Roll for [n]ormal, [g]ood, or [e]xcellent treasure? ";
414 wiz_display_item(caster_ptr, o_ptr);
415 if (!get_com(pmt, &ch, FALSE))
418 if (ch == 'n' || ch == 'N') {
421 } else if (ch == 'g' || ch == 'G') {
424 } else if (ch == 'e' || ch == 'E') {
425 mode = AM_GOOD | AM_GREAT;
426 quality = "excellent";
431 sprintf(tmp_val, "%ld", (long int)test_roll);
432 if (get_string(p, tmp_val, 10))
433 test_roll = atol(tmp_val);
434 test_roll = MAX(1, test_roll);
435 msg_format("Creating a lot of %s items. Base level = %d.", quality, caster_ptr->current_floor_ptr->dun_level);
438 correct = matches = better = worse = other = 0;
439 for (i = 0; i <= test_roll; i++) {
440 if ((i < 100) || (i % 100 == 0)) {
444 break; // stop rolling
447 prt(format(q, i, correct, matches, better, worse, other), 0, 0);
452 object_type *q_ptr = &forge;
454 make_object(caster_ptr, q_ptr, mode);
455 if (object_is_fixed_artifact(q_ptr))
456 a_info[q_ptr->name1].cur_num = 0;
458 if ((o_ptr->tval != q_ptr->tval) || (o_ptr->sval != q_ptr->sval))
462 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)
463 && (q_ptr->name1 == o_ptr->name1)) {
465 } 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)) {
467 } 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 msg_format(q, i, correct, matches, better, worse, other);
478 if (object_is_fixed_artifact(o_ptr))
479 a_info[o_ptr->name1].cur_num = 1;
483 * @brief アイテムの質を選択して再生成する /
484 * Apply magic to an item or turn it into an artifact. -Bernd-
485 * @param o_ptr 再生成の対象となるアイテム情報の参照ポインタ
487 static void wiz_reroll_item(player_type *owner_ptr, object_type *o_ptr)
489 if (object_is_artifact(o_ptr))
495 q_ptr->copy_from(o_ptr);
498 bool changed = FALSE;
500 wiz_display_item(owner_ptr, q_ptr);
501 if (!get_com("[a]ccept, [w]orthless, [c]ursed, [n]ormal, [g]ood, [e]xcellent, [s]pecial? ", &ch, FALSE)) {
502 if (object_is_fixed_artifact(q_ptr)) {
503 a_info[q_ptr->name1].cur_num = 0;
511 if (ch == 'A' || ch == 'a') {
516 if (object_is_fixed_artifact(q_ptr)) {
517 a_info[q_ptr->name1].cur_num = 0;
521 switch (tolower(ch)) {
522 /* Apply bad magic, but first clear object */
524 q_ptr->prep(owner_ptr, o_ptr->k_idx);
525 apply_magic_to_object(owner_ptr, q_ptr, owner_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD | AM_GREAT | AM_CURSED);
527 /* Apply bad magic, but first clear object */
529 q_ptr->prep(owner_ptr, o_ptr->k_idx);
530 apply_magic_to_object(owner_ptr, q_ptr, owner_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD | AM_CURSED);
532 /* Apply normal magic, but first clear object */
534 q_ptr->prep(owner_ptr, o_ptr->k_idx);
535 apply_magic_to_object(owner_ptr, q_ptr, owner_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART);
537 /* Apply good magic, but first clear object */
539 q_ptr->prep(owner_ptr, o_ptr->k_idx);
540 apply_magic_to_object(owner_ptr, q_ptr, owner_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD);
542 /* Apply great magic, but first clear object */
544 q_ptr->prep(owner_ptr, o_ptr->k_idx);
545 apply_magic_to_object(owner_ptr, q_ptr, owner_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD | AM_GREAT);
547 /* Apply special magic, but first clear object */
549 q_ptr->prep(owner_ptr, o_ptr->k_idx);
550 apply_magic_to_object(owner_ptr, q_ptr, owner_ptr->current_floor_ptr->dun_level, AM_GOOD | AM_GREAT | AM_SPECIAL);
551 if (!object_is_artifact(q_ptr))
552 become_random_artifact(owner_ptr, q_ptr, FALSE);
559 q_ptr->iy = o_ptr->iy;
560 q_ptr->ix = o_ptr->ix;
561 q_ptr->marked = o_ptr->marked;
567 o_ptr->copy_from(q_ptr);
568 set_bits(owner_ptr->update, PU_BONUS | PU_COMBINE | PU_REORDER);
569 set_bits(owner_ptr->window_flags, PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER | PW_FLOOR_ITEM_LIST);
573 * @briefアイテムの基礎能力値を調整する / Tweak an item
574 * @param player_ptr プレーヤーへの参照ポインタ
575 * @param o_ptr 調整するアイテムの参照ポインタ
577 static void wiz_tweak_item(player_type *player_ptr, object_type *o_ptr)
579 if (object_is_artifact(o_ptr))
582 concptr p = "Enter new 'pval' setting: ";
584 sprintf(tmp_val, "%d", o_ptr->pval);
585 if (!get_string(p, tmp_val, 5))
588 o_ptr->pval = clamp_cast<s16b>(atoi(tmp_val));
589 wiz_display_item(player_ptr, o_ptr);
590 p = "Enter new 'to_a' setting: ";
591 sprintf(tmp_val, "%d", o_ptr->to_a);
592 if (!get_string(p, tmp_val, 5))
595 o_ptr->to_a = clamp_cast<s16b>(atoi(tmp_val));
596 wiz_display_item(player_ptr, o_ptr);
597 p = "Enter new 'to_h' setting: ";
598 sprintf(tmp_val, "%d", o_ptr->to_h);
599 if (!get_string(p, tmp_val, 5))
602 o_ptr->to_h = clamp_cast<s16b>(atoi(tmp_val));
603 wiz_display_item(player_ptr, o_ptr);
604 p = "Enter new 'to_d' setting: ";
605 sprintf(tmp_val, "%d", (int)o_ptr->to_d);
606 if (!get_string(p, tmp_val, 5))
609 o_ptr->to_d = clamp_cast<s16b>(atoi(tmp_val));
610 wiz_display_item(player_ptr, o_ptr);
614 * @brief 検査対象のアイテムの数を変更する /
615 * Change the quantity of a the item
616 * @param caster_ptr プレーヤーへの参照ポインタ
617 * @param o_ptr 変更するアイテム情報構造体の参照ポインタ
619 static void wiz_quantity_item(object_type *o_ptr)
621 if (object_is_artifact(o_ptr))
624 int tmp_qnt = o_ptr->number;
626 sprintf(tmp_val, "%d", (int)o_ptr->number);
627 if (get_string("Quantity: ", tmp_val, 2)) {
628 int tmp_int = atoi(tmp_val);
635 o_ptr->number = (byte)tmp_int;
638 if (o_ptr->tval == TV_ROD)
639 o_ptr->pval = o_ptr->pval * o_ptr->number / tmp_qnt;
643 * @brief アイテムを弄るデバッグコマンド
644 * Play with an item. Options include:
646 * - Output statistics (via wiz_roll_item)<br>
647 * - Reroll item (via wiz_reroll_item)<br>
648 * - Change properties (via wiz_tweak_item)<br>
649 * - Change the number of items (via wiz_quantity_item)<br>
651 void wiz_modify_item(player_type *creature_ptr)
653 concptr q = "Play with which object? ";
654 concptr s = "You have nothing to play with.";
657 o_ptr = choose_object(creature_ptr, &item, q, s, USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT, TV_NONE);
666 q_ptr->copy_from(o_ptr);
668 bool changed = FALSE;
670 wiz_display_item(creature_ptr, q_ptr);
671 if (!get_com("[a]ccept [s]tatistics [r]eroll [t]weak [q]uantity? ", &ch, FALSE)) {
676 if (ch == 'A' || ch == 'a') {
681 if (ch == 's' || ch == 'S') {
682 wiz_statistics(creature_ptr, q_ptr);
685 if (ch == 'r' || ch == 'R') {
686 wiz_reroll_item(creature_ptr, q_ptr);
689 if (ch == 't' || ch == 'T') {
690 wiz_tweak_item(creature_ptr, q_ptr);
693 if (ch == 'q' || ch == 'Q') {
694 wiz_quantity_item(q_ptr);
700 msg_print("Changes accepted.");
702 o_ptr->copy_from(q_ptr);
703 set_bits(creature_ptr->update, PU_BONUS | PU_COMBINE | PU_REORDER);
704 set_bits(creature_ptr->window_flags, PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER | PW_FLOOR_ITEM_LIST);
706 msg_print("Changes ignored.");
711 * @brief オブジェクトの装備スロットがエゴが有効なスロットかどうか判定
713 static int is_slot_able_to_be_ego(player_type *caster_ptr, object_type *o_ptr)
715 int slot = wield_slot(caster_ptr, o_ptr);
720 if ((o_ptr->tval == TV_SHOT) || (o_ptr->tval == TV_ARROW) || (o_ptr->tval == TV_BOLT))
727 * @brief 願ったが消えてしまった場合のメッセージ
729 static void wishing_puff_of_smoke(void)
731 msg_print(_("何かが足下に転がってきたが、煙のように消えてしまった。",
732 "You feel something roll beneath your feet, but it disappears in a puff of smoke!"));
736 * @brief 願ったが消えてしまった場合のメッセージ
737 * @param caster_ptr 願ったプレイヤー情報への参照ポインタ
738 * @param prob ★などを願った場合の生成確率
739 * @param art_ok アーティファクトの生成を許すならTRUE
740 * @param ego_ok エゴの生成を許すならTRUE
741 * @param confirm 願わない場合に確認するかどうか
744 WishResult do_cmd_wishing(player_type *caster_ptr, int prob, bool allow_art, bool allow_ego, bool confirm)
746 concptr fixed_str[] = {
763 char buf[MAX_NLEN] = "\0";
766 object_type *o_ptr = &forge;
767 char o_name[MAX_NLEN];
769 bool wish_art = FALSE;
770 bool wish_randart = FALSE;
771 bool wish_ego = FALSE;
772 bool exam_base = TRUE;
773 bool ok_art = (randint0(100) < prob) ? TRUE : FALSE;
774 bool ok_ego = (randint0(100) < 50 + prob) ? TRUE : FALSE;
775 bool must = (prob < 0) ? TRUE : FALSE;
776 bool blessed = FALSE;
780 if (get_string(_("何をお望み? ", "For what do you wish?"), buf, (MAX_NLEN - 1)))
783 if (!get_check(_("何も願いません。本当によろしいですか?", "Do you wish nothing, really? ")))
786 return WishResult::NOTHING;
793 if (!strncmp(buf, "a ", 2))
794 str = ltrim(str + 1);
795 else if (!strncmp(buf, "an ", 3))
796 str = ltrim(str + 2);
801 if (!strncmp(str, _("祝福された", "blessed"), _(10, 7))) {
802 str = ltrim(str + _(10, 7));
806 for (int i = 0; fixed_str[i] != NULL; i++) {
807 int len = strlen(fixed_str[i]);
808 if (!strncmp(str, fixed_str[i], len)) {
809 str = ltrim(str + len);
816 if (!strncmp(str, "★", 2)) {
817 str = ltrim(str + 2);
823 if (!strncmp(str, _("☆", "The "), _(2, 4))) {
824 str = ltrim(str + _(2, 4));
829 /* wishing random ego ? */
830 else if (!strncmp(str, _("高級な", "excellent "), _(6, 9))) {
831 str = ltrim(str + _(6, 9));
835 if (strlen(str) < 1) {
836 msg_print(_("名前がない!", "What?"));
837 return WishResult::NOTHING;
840 if (!allow_art && wish_art) {
841 msg_print(_("アーティファクトは願えない!", "You can not wish artifacts!"));
842 return WishResult::NOTHING;
846 msg_format("Wishing %s....", buf);
848 std::vector<KIND_OBJECT_IDX> k_ids;
849 std::vector<EGO_IDX> e_ids;
853 for (KIND_OBJECT_IDX k = 1; k < max_k_idx; k++) {
854 object_kind *k_ptr = &k_info[k];
855 if (k_ptr->name.empty())
858 o_ptr->prep(caster_ptr, k);
859 describe_flavor(caster_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY | OD_STORE));
864 msg_format("Matching object No.%d %s", k, o_name);
866 len = strlen(o_name);
868 if (_(!strrncmp(str, o_name, len), !strncmp(str, o_name, len))) {
876 if (allow_ego && k_ids.size() == 1) {
877 KIND_OBJECT_IDX k_idx = k_ids.back();
878 o_ptr->prep(caster_ptr, k_idx);
880 for (EGO_IDX k = 1; k < max_e_idx; k++) {
881 ego_item_type *e_ptr = &e_info[k];
882 if (e_ptr->name.empty())
885 strcpy(o_name, e_ptr->name.c_str());
890 msg_format("Mathcing ego No.%d %s...", k, o_name);
892 if (_(!strncmp(str, o_name, strlen(o_name)), !strrncmp(str, o_name, strlen(o_name)))) {
893 if (is_slot_able_to_be_ego(caster_ptr, o_ptr) != e_ptr->slot)
902 std::vector<ARTIFACT_IDX> a_ids;
905 char a_desc[MAX_NLEN] = "\0";
906 char *a_str = a_desc;
910 for (ARTIFACT_IDX i = 1; i < max_a_idx; i++) {
911 artifact_type *a_ptr = &a_info[i];
912 if (a_ptr->name.empty())
915 KIND_OBJECT_IDX k_idx = lookup_kind(a_ptr->tval, a_ptr->sval);
919 o_ptr->prep(caster_ptr, k_idx);
922 describe_flavor(caster_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY | OD_STORE));
927 strcpy(a_desc, a_ptr->name.c_str());
933 if (!strncmp(a_str, "『", 2)) {
935 char *s = strstr(a_str, "』");
940 int l = strlen(a_str);
941 if (!strrncmp(a_str, "の", 2)) {
947 if (a_str[0] == '\'') {
949 char *s = strchr(a_desc, '\'');
953 else if (!strncmp(a_str, (const char *)"of ", 3)) {
961 msg_format("Matching artifact No.%d %s(%s)", i, a_desc, _(&o_name[2], o_name));
963 std::vector<const char *> l = { a_str, a_ptr->name.c_str(), _(&o_name[2], o_name) };
964 for (size_t c = 0; c < l.size(); c++) {
965 if (!strcmp(str, l.at(c))) {
966 len = strlen(l.at(c));
976 if (current_world_ptr->wizard && (a_ids.size() > 1 || e_ids.size() > 1)) {
977 msg_print(_("候補が多すぎる!", "Too many matches!"));
978 return WishResult::FAIL;
981 if (a_ids.size() == 1) {
982 ARTIFACT_IDX a_idx = a_ids.back();
983 if (must || (ok_art && !a_info[a_idx].cur_num)) {
984 create_named_art(caster_ptr, a_idx, caster_ptr->y, caster_ptr->x);
985 if (!current_world_ptr->wizard)
986 a_info[a_idx].cur_num = 1;
989 wishing_puff_of_smoke();
990 return WishResult::ARTIFACT;
993 if (!allow_ego && (wish_ego || e_ids.size() > 0)) {
994 msg_print(_("エゴアイテムは願えない!", "Can not wish ego item."));
995 return WishResult::NOTHING;
998 if (k_ids.size() == 1) {
999 KIND_OBJECT_IDX k_idx = k_ids.back();
1000 object_kind *k_ptr = &k_info[k_idx];
1002 artifact_type *a_ptr;
1003 ARTIFACT_IDX a_idx = 0;
1004 if (k_ptr->gen_flags.has(TRG::INSTA_ART)) {
1005 for (ARTIFACT_IDX i = 1; i < max_a_idx; i++) {
1007 if (a_ptr->tval != k_ptr->tval || a_ptr->sval != k_ptr->sval)
1015 a_ptr = &a_info[a_idx];
1016 if (must || (ok_art && !a_ptr->cur_num)) {
1017 create_named_art(caster_ptr, a_idx, caster_ptr->y, caster_ptr->x);
1018 if (!current_world_ptr->wizard)
1019 a_info[a_idx].cur_num = 1;
1022 wishing_puff_of_smoke();
1023 return WishResult::ARTIFACT;
1027 if (must || ok_art) {
1029 o_ptr->prep(caster_ptr, k_idx);
1030 apply_magic_to_object(caster_ptr, o_ptr, k_ptr->level, (AM_SPECIAL | AM_NO_FIXED_ART));
1031 } while (!o_ptr->art_name || o_ptr->name1 || o_ptr->name2 || object_is_cursed(o_ptr));
1033 if (o_ptr->art_name)
1034 drop_near(caster_ptr, o_ptr, -1, caster_ptr->y, caster_ptr->x);
1036 wishing_puff_of_smoke();
1038 return WishResult::ARTIFACT;
1041 WishResult res = WishResult::NOTHING;
1042 if (allow_ego && (wish_ego || e_ids.size() > 0)) {
1043 if (must || ok_ego) {
1044 if (e_ids.size() > 0) {
1045 o_ptr->prep(caster_ptr, k_idx);
1046 o_ptr->name2 = e_ids[0];
1047 apply_ego(caster_ptr, o_ptr, caster_ptr->current_floor_ptr->base_level);
1049 int max_roll = 1000;
1051 for (i = 0; i < max_roll; i++) {
1052 o_ptr->prep(caster_ptr, k_idx);
1053 (void)apply_magic_to_object(caster_ptr, o_ptr, k_ptr->level, (AM_GREAT | AM_NO_FIXED_ART));
1055 if (o_ptr->name1 || o_ptr->art_name)
1062 for (auto e : e_ids) {
1063 if (o_ptr->name2 == e) {
1073 if (i == max_roll) {
1074 msg_print(_("失敗!もう一度願ってみてください。", "Failed! Try again."));
1075 return WishResult::FAIL;
1079 wishing_puff_of_smoke();
1082 res = WishResult::EGO;
1084 for (int i = 0; i < 100; i++) {
1085 o_ptr->prep(caster_ptr, k_idx);
1086 apply_magic_to_object(caster_ptr, o_ptr, 0, (AM_NO_FIXED_ART));
1087 if (!object_is_cursed(o_ptr))
1090 res = WishResult::NORMAL;
1093 if (blessed && wield_slot(caster_ptr, o_ptr) != -1)
1094 add_flag(o_ptr->art_flags, TR_BLESSED);
1096 if (fixed && wield_slot(caster_ptr, o_ptr) != -1) {
1097 add_flag(o_ptr->art_flags, TR_IGNORE_ACID);
1098 add_flag(o_ptr->art_flags, TR_IGNORE_FIRE);
1101 (void)drop_near(caster_ptr, o_ptr, -1, caster_ptr->y, caster_ptr->x);
1106 msg_print(_("うーん、そんなものは存在しないようだ。", "Ummmm, that is not existing..."));
1107 return WishResult::FAIL;