OSDN Git Service

92530bf63c0ad91e3b333efed9ad7567a3ca5e7b
[hengbandforosx/hengbandosx.git] / src / spell-realm / spells-sorcery.cpp
1 #include "spell-realm/spells-sorcery.h"
2 #include "core/asking-player.h"
3 #include "core/player-redraw-types.h"
4 #include "core/window-redrawer.h"
5 #include "flavor/flavor-describer.h"
6 #include "floor/floor-object.h"
7 #include "game-option/input-options.h"
8 #include "inventory/inventory-object.h"
9 #include "io/input-key-requester.h"
10 #include "object-hook/hook-expendable.h"
11 #include "object/item-use-flags.h"
12 #include "object/object-value.h"
13 #include "system/item-entity.h"
14 #include "system/player-type-definition.h"
15 #include "system/redrawing-flags-updater.h"
16 #include "term/z-form.h"
17 #include "view/display-messages.h"
18
19 /*!
20  * @brief アイテムの価値に応じた錬金術処理 /
21  * Turns an object into gold, gain some of its value in a shop
22  * @param player_ptr プレイヤーへの参照ポインタ
23  * @return 処理が実際に行われたらTRUEを返す
24  */
25 bool alchemy(PlayerType *player_ptr)
26 {
27     bool force = false;
28     if (command_arg > 0) {
29         force = true;
30     }
31
32     concptr q = _("どのアイテムを金に変えますか?", "Turn which item to gold? ");
33     concptr s = _("金に変えられる物がありません。", "You have nothing to turn to gold.");
34     OBJECT_IDX item;
35     ItemEntity *o_ptr;
36     o_ptr = choose_object(player_ptr, &item, q, s, (USE_INVEN | USE_FLOOR));
37     if (!o_ptr) {
38         return false;
39     }
40
41     int amt = 1;
42     if (o_ptr->number > 1) {
43         amt = get_quantity(std::nullopt, o_ptr->number);
44         if (amt <= 0) {
45             return false;
46         }
47     }
48
49     ITEM_NUMBER old_number = o_ptr->number;
50     o_ptr->number = amt;
51     const auto item_name = describe_flavor(player_ptr, o_ptr, 0);
52     o_ptr->number = old_number;
53
54     if (!force) {
55         if (confirm_destroy || (o_ptr->get_price() > 0)) {
56             char out_val[MAX_NLEN + 40];
57             strnfmt(out_val, sizeof(out_val), _("本当に%sを金に変えますか?", "Really turn %s to gold? "), item_name.data());
58             if (!get_check(out_val)) {
59                 return false;
60             }
61         }
62     }
63
64     if (!can_player_destroy_object(player_ptr, o_ptr)) {
65         msg_format(_("%sを金に変えることに失敗した。", "You fail to turn %s to gold!"), item_name.data());
66         return false;
67     }
68
69     PRICE price = object_value_real(o_ptr);
70     if (price <= 0) {
71         msg_format(_("%sをニセの金に変えた。", "You turn %s to fool's gold."), item_name.data());
72         vary_item(player_ptr, item, -amt);
73         return true;
74     }
75
76     price /= 3;
77
78     if (amt > 1) {
79         price *= amt;
80     }
81
82     if (price > 30000) {
83         price = 30000;
84     }
85
86     msg_format(_("%sを$%d の金に変えた。", "You turn %s to %d coins worth of gold."), item_name.data(), price);
87     player_ptr->au += price;
88     auto &rfu = RedrawingFlagsUpdater::get_instance();
89     rfu.set_flag(MainWindowRedrawingFlag::GOLD);
90     player_ptr->window_flags |= PW_PLAYER;
91     vary_item(player_ptr, item, -amt);
92     return true;
93 }