OSDN Git Service

Merge pull request #3506 from Hourier/Fix-Compilation-Warnings-3.0.0Beta-11
[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     constexpr auto q = _("どのアイテムを金に変えますか?", "Turn which item to gold? ");
32     constexpr auto s = _("金に変えられる物がありません。", "You have nothing to turn to gold.");
33     short item;
34     auto *o_ptr = choose_object(player_ptr, &item, q, s, (USE_INVEN | USE_FLOOR));
35     if (!o_ptr) {
36         return false;
37     }
38
39     auto amt = 1;
40     if (o_ptr->number > 1) {
41         amt = input_quantity(o_ptr->number);
42         if (amt <= 0) {
43             return false;
44         }
45     }
46
47     const auto old_number = o_ptr->number;
48     o_ptr->number = amt;
49     const auto item_name = describe_flavor(player_ptr, o_ptr, 0);
50     o_ptr->number = old_number;
51
52     if (!force) {
53         if (confirm_destroy || (o_ptr->get_price() > 0)) {
54             char out_val[MAX_NLEN + 40];
55             strnfmt(out_val, sizeof(out_val), _("本当に%sを金に変えますか?", "Really turn %s to gold? "), item_name.data());
56             if (!input_check(out_val)) {
57                 return false;
58             }
59         }
60     }
61
62     if (!can_player_destroy_object(o_ptr)) {
63         msg_format(_("%sを金に変えることに失敗した。", "You fail to turn %s to gold!"), item_name.data());
64         return false;
65     }
66
67     auto price = object_value_real(o_ptr);
68     if (price <= 0) {
69         msg_format(_("%sをニセの金に変えた。", "You turn %s to fool's gold."), item_name.data());
70         vary_item(player_ptr, item, -amt);
71         return true;
72     }
73
74     price /= 3;
75
76     if (amt > 1) {
77         price *= amt;
78     }
79
80     if (price > 30000) {
81         price = 30000;
82     }
83
84     msg_format(_("%sを$%d の金に変えた。", "You turn %s to %d coins worth of gold."), item_name.data(), price);
85     player_ptr->au += price;
86     auto &rfu = RedrawingFlagsUpdater::get_instance();
87     rfu.set_flag(MainWindowRedrawingFlag::GOLD);
88     rfu.set_flag(SubWindowRedrawingFlag::PLAYER);
89     vary_item(player_ptr, item, -amt);
90     return true;
91 }