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"
53 #define K_MAX_DEPTH 110 /*!< アイテムの階層毎生成率を表示する最大階 */
57 * @brief アイテム設定コマンド一覧表
59 std::vector<std::vector<std::string>> wizard_sub_menu_table = {
60 { "a", _("アーティファクト出現フラグリセット", "Restore aware flag of fixed artifact") },
61 { "A", _("アーティファクトを出現済みにする", "Make a fixed artifact awared") },
62 { "e", _("高級品獲得ドロップ", "Drop excellent object") },
63 { "f", _("*鑑定*", "*Idenfity*") },
64 { "i", _("鑑定", "Idenfity") },
65 { "I", _("インベントリ全*鑑定*", "Idenfity all objects fully in inventory") },
66 { "l", _("指定アイテム番号まで一括鑑定", "Make objects awared to target object id") },
67 { "g", _("上質なアイテムドロップ", "Drop good object") },
68 { "s", _("特別品獲得ドロップ", "Drop special object") },
69 { "w", _("願い", "Wishing") },
70 { "U", _("発動を変更する", "Modify item activation") },
74 * @brief ゲーム設定コマンドの一覧を表示する
76 void display_wizard_sub_menu()
78 for (size_t y = 1; y <= wizard_sub_menu_table.size(); y++)
79 term_erase(14, y, 64);
83 int sz = wizard_sub_menu_table.size();
84 for (int i = 0; i < sz; i++) {
86 ss << wizard_sub_menu_table[i][0] << ") " << wizard_sub_menu_table[i][1];
87 put_str(ss.str().c_str(), r++, c);
93 * @brief キャスト先の型の最小値、最大値でclampする。
98 return static_cast<T>(std::clamp(val,
99 static_cast<int>(std::numeric_limits<T>::min()),
100 static_cast<int>(std::numeric_limits<T>::max())));
103 void wiz_restore_aware_flag_of_fixed_arfifact(ARTIFACT_IDX a_idx, bool aware = false);
104 void wiz_modify_item_activation(player_type *caster_ptr);
105 void wiz_identify_full_inventory(player_type *caster_ptr);
108 * @brief ゲーム設定コマンドの入力を受け付ける
109 * @param creature_ptr プレイヤーの情報へのポインタ
111 void wizard_item_modifier(player_type *creature_ptr)
114 display_wizard_sub_menu();
117 get_com("Player Command: ", &cmd, false);
127 wiz_restore_aware_flag_of_fixed_arfifact(command_arg);
130 wiz_restore_aware_flag_of_fixed_arfifact(command_arg, true);
133 if (command_arg <= 0)
136 acquirement(creature_ptr, creature_ptr->y, creature_ptr->x, command_arg, true, false, true);
139 identify_fully(creature_ptr, false);
142 if (command_arg <= 0)
145 acquirement(creature_ptr, creature_ptr->y, creature_ptr->x, command_arg, false, false, true);
148 (void)ident_spell(creature_ptr, false);
151 wiz_identify_full_inventory(creature_ptr);
154 wiz_learn_items_all(creature_ptr);
157 if (command_arg <= 0)
160 acquirement(creature_ptr, creature_ptr->y, creature_ptr->x, command_arg, true, true, true);
163 wiz_modify_item_activation(creature_ptr);
166 do_cmd_wishing(creature_ptr, -1, true, true, true);
172 * @brief 固定アーティファクトの出現フラグをリセットする
173 * @param a_idx 指定したアーティファクトID
175 void wiz_restore_aware_flag_of_fixed_arfifact(ARTIFACT_IDX a_idx, bool aware)
179 sprintf(tmp, "Artifact ID (1-%d): ", max_a_idx - 1);
180 char tmp_val[10] = "";
181 if (!get_string(tmp, tmp_val, 3))
184 a_idx = (ARTIFACT_IDX)atoi(tmp_val);
187 if (a_idx <= 0 || a_idx >= max_a_idx) {
188 msg_format(_("番号は1から%dの間で指定して下さい。", "ID must be between 1 to %d."), max_a_idx - 1);
192 auto *a_ptr = &a_info[a_idx];
193 a_ptr->cur_num = aware ? 1 : 0;
194 msg_print(aware ? "Modified." : "Restored.");
198 * @brief オブジェクトに発動を追加する/変更する
199 * @param catser_ptr プレイヤー情報への参照ポインタ
201 void wiz_modify_item_activation(player_type *caster_ptr)
203 concptr q = "Which object? ";
204 concptr s = "Nothing to do with.";
206 auto *o_ptr = choose_object(caster_ptr, &item, q, s, USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT);
212 sprintf(tmp, "Artifact ID (1-%d): ", ACT_MAX);
213 char tmp_val[10] = "";
214 if (!get_string(tmp, tmp_val, 3))
217 act_idx = (XTRA16)atoi(tmp_val);
219 if (act_idx <= 0 || act_idx > ACT_MAX) {
220 msg_format(_("番号は1から%dの間で指定して下さい。", "ID must be between 1 to %d."), ACT_MAX - 1);
224 add_flag(o_ptr->art_flags, TR_ACTIVATE);
225 o_ptr->xtra2 = act_idx;
229 * @brief インベントリ内のアイテムを全て*鑑定*済みにする
230 * @param catser_ptr プレイヤー情報への参照ポインタ
232 void wiz_identify_full_inventory(player_type *caster_ptr)
234 for (int i = 0; i < INVEN_TOTAL; i++) {
235 object_type *o_ptr = &caster_ptr->inventory_list[i];
239 auto k_ptr = &k_info[o_ptr->k_idx];
240 k_ptr->aware = true; //!< @note 記録には残さないためTRUEを立てるのみ
241 set_bits(o_ptr->ident, IDENT_KNOWN | IDENT_FULL_KNOWN);
242 set_bits(o_ptr->marked, OM_TOUCHED);
245 /* Refrect item informaiton onto subwindows without updating inventory */
246 reset_bits(caster_ptr->update, PU_COMBINE | PU_REORDER);
247 handle_stuff(caster_ptr);
248 set_bits(caster_ptr->update, PU_COMBINE | PU_REORDER);
249 set_bits(caster_ptr->window_flags, PW_INVEN | PW_EQUIP);
253 * @brief アイテムの階層毎生成率を表示する / Output a rarity graph for a type of object.
254 * @param tval ベースアイテムの大項目ID
255 * @param sval ベースアイテムの小項目ID
259 static void prt_alloc(tval_type tval, OBJECT_SUBTYPE_VALUE sval, TERM_LEN row, TERM_LEN col)
261 uint32_t rarity[K_MAX_DEPTH];
262 (void)C_WIPE(rarity, K_MAX_DEPTH, uint32_t);
263 uint32_t total[K_MAX_DEPTH];
264 (void)C_WIPE(total, K_MAX_DEPTH, uint32_t);
266 (void)C_WIPE(display, 22, int32_t);
269 for (int i = 0; i < K_MAX_DEPTH; i++) {
272 alloc_entry *table = alloc_kind_table;
273 for (int j = 0; j < alloc_kind_size; j++) {
276 if (table[j].level <= i) {
277 prob = table[j].prob1 * GREAT_OBJ * K_MAX_DEPTH;
278 } else if (table[j].level - 1 > 0) {
279 prob = table[j].prob1 * i * K_MAX_DEPTH / (table[j].level - 1);
282 k_ptr = &k_info[table[j].index];
284 total[i] += prob / (GREAT_OBJ * K_MAX_DEPTH);
285 total_frac += prob % (GREAT_OBJ * K_MAX_DEPTH);
287 if ((k_ptr->tval == tval) && (k_ptr->sval == sval)) {
289 rarity[i] += prob / (GREAT_OBJ * K_MAX_DEPTH);
293 total[i] += total_frac / (GREAT_OBJ * K_MAX_DEPTH);
296 for (int i = 0; i < 22; i++) {
298 for (int j = i * K_MAX_DEPTH / 22; j < (i + 1) * K_MAX_DEPTH / 22; j++)
299 possibility += rarity[j] * 100000 / total[j];
301 display[i] = possibility / 5;
304 for (int i = 0; i < 22; i++) {
305 term_putch(col, row + i + 1, TERM_WHITE, '|');
306 prt(format("%2dF", (i * 5)), row + i + 1, col);
307 if ((i * K_MAX_DEPTH / 22 <= home) && (home < (i + 1) * K_MAX_DEPTH / 22))
308 c_prt(TERM_RED, format("%3d.%04d%%", display[i] / 1000, display[i] % 1000), row + i + 1, col + 3);
310 c_prt(TERM_WHITE, format("%3d.%04d%%", display[i] / 1000, display[i] % 1000), row + i + 1, col + 3);
313 concptr r = "+---Rate---+";
318 * @brief 32ビット変数のビット配列を並べて描画する / Output a long int in binary format.
320 static void prt_binary(BIT_FLAGS flags, const int row, int col)
323 for (int i = bitmask = 1; i <= 32; i++, bitmask *= 2)
325 term_putch(col++, row, TERM_BLUE, '*');
327 term_putch(col++, row, TERM_WHITE, '-');
331 * @brief アイテムの詳細ステータスを表示する /
332 * Change various "permanent" player variables.
333 * @param player_ptr プレーヤーへの参照ポインタ
334 * @param o_ptr 詳細を表示するアイテム情報の参照ポインタ
336 static void wiz_display_item(player_type *player_ptr, object_type *o_ptr)
339 object_flags(o_ptr, flgs);
341 for (int i = 1; i <= 23; i++)
344 prt_alloc(o_ptr->tval, o_ptr->sval, 1, 0);
346 describe_flavor(player_ptr, buf, o_ptr, OD_STORE);
348 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);
349 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);
350 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);
351 prt(format("name1 = %-4d name2 = %-4d cost = %ld", o_ptr->name1, o_ptr->name2, (long)object_value_real(o_ptr)), 7, j);
352 prt(format("ident = %04x xtra1 = %-4d xtra2 = %-4d timeout = %-d", o_ptr->ident, o_ptr->xtra1, o_ptr->xtra2, o_ptr->timeout), 8, j);
353 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);
355 prt("+------------FLAGS1------------+", 10, j);
356 prt("AFFECT........SLAY........BRAND.", 11, j);
357 prt(" mf cvae xsqpaefc", 12, j);
358 prt("siwdccsossidsahanvudotgddhuoclio", 13, j);
359 prt("tnieohtctrnipttmiinmrrnrrraiierl", 14, j);
360 prt("rtsxnarelcfgdkcpmldncltggpksdced", 15, j);
361 prt_binary(flgs[0], 16, j);
363 prt("+------------FLAGS2------------+", 17, j);
364 prt("SUST....IMMUN.RESIST............", 18, j);
365 prt(" reaefctrpsaefcpfldbc sn ", 19, j);
366 prt("siwdcciaclioheatcliooeialoshtncd", 20, j);
367 prt("tnieohdsierlrfraierliatrnnnrhehi", 21, j);
368 prt("rtsxnaeydcedwlatdcedsrekdfddrxss", 22, j);
369 prt_binary(flgs[1], 23, j);
371 prt("+------------FLAGS3------------+", 10, j + 32);
372 prt("fe cnn t stdrmsiiii d ab ", 11, j + 32);
373 prt("aa aoomywhs lleeieihgggg rtgl ", 12, j + 32);
374 prt("uu utmacaih eielgggonnnnaaere ", 13, j + 32);
375 prt("rr reanurdo vtieeehtrrrrcilas ", 14, j + 32);
376 prt("aa algarnew ienpsntsaefctnevs ", 15, j + 32);
377 prt_binary(flgs[2], 16, j + 32);
379 prt("+------------FLAGS4------------+", 17, j + 32);
380 prt("KILL....ESP......... ", 18, j + 32);
381 prt("aeud tghaud tgdhegnu ", 19, j + 32);
382 prt("nvneoriunneoriruvoon ", 20, j + 32);
383 prt("iidmroamidmroagmionq ", 21, j + 32);
384 prt("mlenclnmmenclnnnldlu ", 22, j + 32);
385 prt_binary(flgs[3], 23, j + 32);
389 * @brief 検査対象のアイテムを基準とした生成テストを行う /
390 * Try to create an item again. Output some statistics. -Bernd-
391 * @param caster_ptr プレーヤーへの参照ポインタ
392 * @param o_ptr 生成テストの基準となるアイテム情報の参照ポインタ
393 * The statistics are correct now. We acquire a clean grid, and then
394 * repeatedly place an object in this grid, copying it into an item
395 * holder, and then deleting the object. We fiddle with the artifact
396 * counter flags to prevent weirdness. We use the items to collect
397 * statistics on item creation relative to the initial item.
399 static void wiz_statistics(player_type *caster_ptr, object_type *o_ptr)
401 concptr q = "Rolls: %ld Correct: %ld Matches: %ld Better: %ld Worse: %ld Other: %ld";
402 concptr p = "Enter number of items to roll: ";
405 if (object_is_fixed_artifact(o_ptr))
406 a_info[o_ptr->name1].cur_num = 0;
408 uint32_t i, matches, better, worse, other, correct;
409 uint32_t test_roll = 1000000;
414 concptr pmt = "Roll for [n]ormal, [g]ood, or [e]xcellent treasure? ";
415 wiz_display_item(caster_ptr, o_ptr);
416 if (!get_com(pmt, &ch, false))
419 if (ch == 'n' || ch == 'N') {
422 } else if (ch == 'g' || ch == 'G') {
425 } else if (ch == 'e' || ch == 'E') {
426 mode = AM_GOOD | AM_GREAT;
427 quality = "excellent";
432 sprintf(tmp_val, "%ld", (long int)test_roll);
433 if (get_string(p, tmp_val, 10))
434 test_roll = atol(tmp_val);
435 test_roll = MAX(1, test_roll);
436 msg_format("Creating a lot of %s items. Base level = %d.", quality, caster_ptr->current_floor_ptr->dun_level);
439 correct = matches = better = worse = other = 0;
440 for (i = 0; i <= test_roll; i++) {
441 if ((i < 100) || (i % 100 == 0)) {
445 break; // stop rolling
448 prt(format(q, i, correct, matches, better, worse, other), 0, 0);
453 object_type *q_ptr = &forge;
455 make_object(caster_ptr, q_ptr, mode);
456 if (object_is_fixed_artifact(q_ptr))
457 a_info[q_ptr->name1].cur_num = 0;
459 if ((o_ptr->tval != q_ptr->tval) || (o_ptr->sval != q_ptr->sval))
463 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)
464 && (q_ptr->name1 == o_ptr->name1)) {
466 } 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)) {
468 } 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)) {
475 msg_format(q, i, correct, matches, better, worse, other);
479 if (object_is_fixed_artifact(o_ptr))
480 a_info[o_ptr->name1].cur_num = 1;
484 * @brief アイテムの質を選択して再生成する /
485 * Apply magic to an item or turn it into an artifact. -Bernd-
486 * @param o_ptr 再生成の対象となるアイテム情報の参照ポインタ
488 static void wiz_reroll_item(player_type *owner_ptr, object_type *o_ptr)
490 if (object_is_artifact(o_ptr))
496 q_ptr->copy_from(o_ptr);
499 bool changed = false;
501 wiz_display_item(owner_ptr, q_ptr);
502 if (!get_com("[a]ccept, [w]orthless, [c]ursed, [n]ormal, [g]ood, [e]xcellent, [s]pecial? ", &ch, false)) {
503 if (object_is_fixed_artifact(q_ptr)) {
504 a_info[q_ptr->name1].cur_num = 0;
512 if (ch == 'A' || ch == 'a') {
517 if (object_is_fixed_artifact(q_ptr)) {
518 a_info[q_ptr->name1].cur_num = 0;
522 switch (tolower(ch)) {
523 /* Apply bad magic, but first clear object */
525 q_ptr->prep(o_ptr->k_idx);
526 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);
528 /* Apply bad magic, but first clear object */
530 q_ptr->prep(o_ptr->k_idx);
531 apply_magic_to_object(owner_ptr, q_ptr, owner_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD | AM_CURSED);
533 /* Apply normal magic, but first clear object */
535 q_ptr->prep(o_ptr->k_idx);
536 apply_magic_to_object(owner_ptr, q_ptr, owner_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART);
538 /* Apply good magic, but first clear object */
540 q_ptr->prep(o_ptr->k_idx);
541 apply_magic_to_object(owner_ptr, q_ptr, owner_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD);
543 /* Apply great magic, but first clear object */
545 q_ptr->prep(o_ptr->k_idx);
546 apply_magic_to_object(owner_ptr, q_ptr, owner_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD | AM_GREAT);
548 /* Apply special magic, but first clear object */
550 q_ptr->prep(o_ptr->k_idx);
551 apply_magic_to_object(owner_ptr, q_ptr, owner_ptr->current_floor_ptr->dun_level, AM_GOOD | AM_GREAT | AM_SPECIAL);
552 if (!object_is_artifact(q_ptr))
553 become_random_artifact(owner_ptr, q_ptr, false);
560 q_ptr->iy = o_ptr->iy;
561 q_ptr->ix = o_ptr->ix;
562 q_ptr->marked = o_ptr->marked;
568 o_ptr->copy_from(q_ptr);
569 set_bits(owner_ptr->update, PU_BONUS | PU_COMBINE | PU_REORDER);
570 set_bits(owner_ptr->window_flags, PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER | PW_FLOOR_ITEM_LIST);
574 * @briefアイテムの基礎能力値を調整する / Tweak an item
575 * @param player_ptr プレーヤーへの参照ポインタ
576 * @param o_ptr 調整するアイテムの参照ポインタ
578 static void wiz_tweak_item(player_type *player_ptr, object_type *o_ptr)
580 if (object_is_artifact(o_ptr))
583 concptr p = "Enter new 'pval' setting: ";
585 sprintf(tmp_val, "%d", o_ptr->pval);
586 if (!get_string(p, tmp_val, 5))
589 o_ptr->pval = clamp_cast<int16_t>(atoi(tmp_val));
590 wiz_display_item(player_ptr, o_ptr);
591 p = "Enter new 'to_a' setting: ";
592 sprintf(tmp_val, "%d", o_ptr->to_a);
593 if (!get_string(p, tmp_val, 5))
596 o_ptr->to_a = clamp_cast<int16_t>(atoi(tmp_val));
597 wiz_display_item(player_ptr, o_ptr);
598 p = "Enter new 'to_h' setting: ";
599 sprintf(tmp_val, "%d", o_ptr->to_h);
600 if (!get_string(p, tmp_val, 5))
603 o_ptr->to_h = clamp_cast<int16_t>(atoi(tmp_val));
604 wiz_display_item(player_ptr, o_ptr);
605 p = "Enter new 'to_d' setting: ";
606 sprintf(tmp_val, "%d", (int)o_ptr->to_d);
607 if (!get_string(p, tmp_val, 5))
610 o_ptr->to_d = clamp_cast<int16_t>(atoi(tmp_val));
611 wiz_display_item(player_ptr, o_ptr);
615 * @brief 検査対象のアイテムの数を変更する /
616 * Change the quantity of a the item
617 * @param caster_ptr プレーヤーへの参照ポインタ
618 * @param o_ptr 変更するアイテム情報構造体の参照ポインタ
620 static void wiz_quantity_item(object_type *o_ptr)
622 if (object_is_artifact(o_ptr))
625 int tmp_qnt = o_ptr->number;
627 sprintf(tmp_val, "%d", (int)o_ptr->number);
628 if (get_string("Quantity: ", tmp_val, 2)) {
629 int tmp_int = atoi(tmp_val);
636 o_ptr->number = (byte)tmp_int;
639 if (o_ptr->tval == TV_ROD)
640 o_ptr->pval = o_ptr->pval * o_ptr->number / tmp_qnt;
644 * @brief アイテムを弄るデバッグコマンド
645 * Play with an item. Options include:
647 * - Output statistics (via wiz_roll_item)<br>
648 * - Reroll item (via wiz_reroll_item)<br>
649 * - Change properties (via wiz_tweak_item)<br>
650 * - Change the number of items (via wiz_quantity_item)<br>
652 void wiz_modify_item(player_type *creature_ptr)
654 concptr q = "Play with which object? ";
655 concptr s = "You have nothing to play with.";
658 o_ptr = choose_object(creature_ptr, &item, q, s, USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT);
667 q_ptr->copy_from(o_ptr);
669 bool changed = false;
671 wiz_display_item(creature_ptr, q_ptr);
672 if (!get_com("[a]ccept [s]tatistics [r]eroll [t]weak [q]uantity? ", &ch, false)) {
677 if (ch == 'A' || ch == 'a') {
682 if (ch == 's' || ch == 'S') {
683 wiz_statistics(creature_ptr, q_ptr);
686 if (ch == 'r' || ch == 'R') {
687 wiz_reroll_item(creature_ptr, q_ptr);
690 if (ch == 't' || ch == 'T') {
691 wiz_tweak_item(creature_ptr, q_ptr);
694 if (ch == 'q' || ch == 'Q') {
695 wiz_quantity_item(q_ptr);
701 msg_print("Changes accepted.");
703 o_ptr->copy_from(q_ptr);
704 set_bits(creature_ptr->update, PU_BONUS | PU_COMBINE | PU_REORDER);
705 set_bits(creature_ptr->window_flags, PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER | PW_FLOOR_ITEM_LIST);
707 msg_print("Changes ignored.");
712 * @brief オブジェクトの装備スロットがエゴが有効なスロットかどうか判定
714 static int is_slot_able_to_be_ego(player_type *caster_ptr, object_type *o_ptr)
716 int slot = wield_slot(caster_ptr, o_ptr);
721 if ((o_ptr->tval == TV_SHOT) || (o_ptr->tval == TV_ARROW) || (o_ptr->tval == TV_BOLT))
728 * @brief 願ったが消えてしまった場合のメッセージ
730 static void wishing_puff_of_smoke(void)
732 msg_print(_("何かが足下に転がってきたが、煙のように消えてしまった。",
733 "You feel something roll beneath your feet, but it disappears in a puff of smoke!"));
737 * @brief 願ったが消えてしまった場合のメッセージ
738 * @param caster_ptr 願ったプレイヤー情報への参照ポインタ
739 * @param prob ★などを願った場合の生成確率
740 * @param art_ok アーティファクトの生成を許すならTRUE
741 * @param ego_ok エゴの生成を許すならTRUE
742 * @param confirm 願わない場合に確認するかどうか
745 WishResult do_cmd_wishing(player_type *caster_ptr, int prob, bool allow_art, bool allow_ego, bool confirm)
747 concptr fixed_str[] = {
764 char buf[MAX_NLEN] = "\0";
767 object_type *o_ptr = &forge;
768 char o_name[MAX_NLEN];
770 bool wish_art = false;
771 bool wish_randart = false;
772 bool wish_ego = false;
773 bool exam_base = true;
774 bool ok_art = (randint0(100) < prob) ? true : false;
775 bool ok_ego = (randint0(100) < 50 + prob) ? true : false;
776 bool must = (prob < 0) ? true : false;
777 bool blessed = false;
781 if (get_string(_("何をお望み? ", "For what do you wish?"), buf, (MAX_NLEN - 1)))
784 if (!get_check(_("何も願いません。本当によろしいですか?", "Do you wish nothing, really? ")))
787 return WishResult::NOTHING;
794 if (!strncmp(buf, "a ", 2))
795 str = ltrim(str + 1);
796 else if (!strncmp(buf, "an ", 3))
797 str = ltrim(str + 2);
802 if (!strncmp(str, _("祝福された", "blessed"), _(10, 7))) {
803 str = ltrim(str + _(10, 7));
807 for (int i = 0; fixed_str[i] != NULL; i++) {
808 int len = strlen(fixed_str[i]);
809 if (!strncmp(str, fixed_str[i], len)) {
810 str = ltrim(str + len);
817 if (!strncmp(str, "★", 2)) {
818 str = ltrim(str + 2);
824 if (!strncmp(str, _("☆", "The "), _(2, 4))) {
825 str = ltrim(str + _(2, 4));
830 /* wishing random ego ? */
831 else if (!strncmp(str, _("高級な", "excellent "), _(6, 9))) {
832 str = ltrim(str + _(6, 9));
836 if (strlen(str) < 1) {
837 msg_print(_("名前がない!", "What?"));
838 return WishResult::NOTHING;
841 if (!allow_art && wish_art) {
842 msg_print(_("アーティファクトは願えない!", "You can not wish artifacts!"));
843 return WishResult::NOTHING;
847 msg_format("Wishing %s....", buf);
849 std::vector<KIND_OBJECT_IDX> k_ids;
850 std::vector<EGO_IDX> e_ids;
854 for (KIND_OBJECT_IDX k = 1; k < max_k_idx; k++) {
855 object_kind *k_ptr = &k_info[k];
856 if (k_ptr->name.empty())
860 describe_flavor(caster_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY | OD_STORE));
865 msg_format("Matching object No.%d %s", k, o_name);
867 len = strlen(o_name);
869 if (_(!strrncmp(str, o_name, len), !strncmp(str, o_name, len))) {
877 if (allow_ego && k_ids.size() == 1) {
878 KIND_OBJECT_IDX k_idx = k_ids.back();
881 for (EGO_IDX k = 1; k < max_e_idx; k++) {
882 ego_item_type *e_ptr = &e_info[k];
883 if (e_ptr->name.empty())
886 strcpy(o_name, e_ptr->name.c_str());
891 msg_format("Mathcing ego No.%d %s...", k, o_name);
893 if (_(!strncmp(str, o_name, strlen(o_name)), !strrncmp(str, o_name, strlen(o_name)))) {
894 if (is_slot_able_to_be_ego(caster_ptr, o_ptr) != e_ptr->slot)
903 std::vector<ARTIFACT_IDX> a_ids;
906 char a_desc[MAX_NLEN] = "\0";
907 char *a_str = a_desc;
911 for (ARTIFACT_IDX i = 1; i < max_a_idx; i++) {
912 artifact_type *a_ptr = &a_info[i];
913 if (a_ptr->name.empty())
916 KIND_OBJECT_IDX k_idx = lookup_kind(a_ptr->tval, a_ptr->sval);
923 describe_flavor(caster_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY | OD_STORE));
928 strcpy(a_desc, a_ptr->name.c_str());
934 if (!strncmp(a_str, "『", 2)) {
936 char *s = strstr(a_str, "』");
941 int l = strlen(a_str);
942 if (!strrncmp(a_str, "の", 2)) {
948 if (a_str[0] == '\'') {
950 char *s = strchr(a_desc, '\'');
954 else if (!strncmp(a_str, (const char *)"of ", 3)) {
962 msg_format("Matching artifact No.%d %s(%s)", i, a_desc, _(&o_name[2], o_name));
964 std::vector<const char *> l = { a_str, a_ptr->name.c_str(), _(&o_name[2], o_name) };
965 for (size_t c = 0; c < l.size(); c++) {
966 if (!strcmp(str, l.at(c))) {
967 len = strlen(l.at(c));
977 if (current_world_ptr->wizard && (a_ids.size() > 1 || e_ids.size() > 1)) {
978 msg_print(_("候補が多すぎる!", "Too many matches!"));
979 return WishResult::FAIL;
982 if (a_ids.size() == 1) {
983 ARTIFACT_IDX a_idx = a_ids.back();
984 if (must || (ok_art && !a_info[a_idx].cur_num)) {
985 create_named_art(caster_ptr, a_idx, caster_ptr->y, caster_ptr->x);
986 if (!current_world_ptr->wizard)
987 a_info[a_idx].cur_num = 1;
990 wishing_puff_of_smoke();
991 return WishResult::ARTIFACT;
994 if (!allow_ego && (wish_ego || e_ids.size() > 0)) {
995 msg_print(_("エゴアイテムは願えない!", "Can not wish ego item."));
996 return WishResult::NOTHING;
999 if (k_ids.size() == 1) {
1000 KIND_OBJECT_IDX k_idx = k_ids.back();
1001 object_kind *k_ptr = &k_info[k_idx];
1003 artifact_type *a_ptr;
1004 ARTIFACT_IDX a_idx = 0;
1005 if (k_ptr->gen_flags.has(TRG::INSTA_ART)) {
1006 for (ARTIFACT_IDX i = 1; i < max_a_idx; i++) {
1008 if (a_ptr->tval != k_ptr->tval || a_ptr->sval != k_ptr->sval)
1016 a_ptr = &a_info[a_idx];
1017 if (must || (ok_art && !a_ptr->cur_num)) {
1018 create_named_art(caster_ptr, a_idx, caster_ptr->y, caster_ptr->x);
1019 if (!current_world_ptr->wizard)
1020 a_info[a_idx].cur_num = 1;
1023 wishing_puff_of_smoke();
1024 return WishResult::ARTIFACT;
1028 if (must || ok_art) {
1031 apply_magic_to_object(caster_ptr, o_ptr, k_ptr->level, (AM_SPECIAL | AM_NO_FIXED_ART));
1032 } while (!o_ptr->art_name || o_ptr->name1 || o_ptr->name2 || object_is_cursed(o_ptr));
1034 if (o_ptr->art_name)
1035 drop_near(caster_ptr, o_ptr, -1, caster_ptr->y, caster_ptr->x);
1037 wishing_puff_of_smoke();
1039 return WishResult::ARTIFACT;
1042 WishResult res = WishResult::NOTHING;
1043 if (allow_ego && (wish_ego || e_ids.size() > 0)) {
1044 if (must || ok_ego) {
1045 if (e_ids.size() > 0) {
1047 o_ptr->name2 = e_ids[0];
1048 apply_ego(o_ptr, caster_ptr->current_floor_ptr->base_level);
1050 int max_roll = 1000;
1052 for (i = 0; i < max_roll; i++) {
1054 (void)apply_magic_to_object(caster_ptr, o_ptr, k_ptr->level, (AM_GREAT | AM_NO_FIXED_ART));
1056 if (o_ptr->name1 || o_ptr->art_name)
1063 for (auto e : e_ids) {
1064 if (o_ptr->name2 == e) {
1074 if (i == max_roll) {
1075 msg_print(_("失敗!もう一度願ってみてください。", "Failed! Try again."));
1076 return WishResult::FAIL;
1080 wishing_puff_of_smoke();
1083 res = WishResult::EGO;
1085 for (int i = 0; i < 100; i++) {
1087 apply_magic_to_object(caster_ptr, o_ptr, 0, (AM_NO_FIXED_ART));
1088 if (!object_is_cursed(o_ptr))
1091 res = WishResult::NORMAL;
1094 if (blessed && wield_slot(caster_ptr, o_ptr) != -1)
1095 add_flag(o_ptr->art_flags, TR_BLESSED);
1097 if (fixed && wield_slot(caster_ptr, o_ptr) != -1) {
1098 add_flag(o_ptr->art_flags, TR_IGNORE_ACID);
1099 add_flag(o_ptr->art_flags, TR_IGNORE_FIRE);
1102 (void)drop_near(caster_ptr, o_ptr, -1, caster_ptr->y, caster_ptr->x);
1107 msg_print(_("うーん、そんなものは存在しないようだ。", "Ummmm, that is not existing..."));
1108 return WishResult::FAIL;