OSDN Git Service

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