1 #include "store/sell-order.h"
2 #include "action/weapon-shield.h"
3 #include "autopick/autopick.h"
4 #include "avatar/avatar.h"
5 #include "core/asking-player.h"
6 #include "core/player-update-types.h"
7 #include "core/stuff-handler.h"
8 #include "core/window-redrawer.h"
9 #include "flavor/flavor-describer.h"
10 #include "flavor/object-flavor-types.h"
11 #include "floor/floor-object.h"
12 #include "game-option/birth-options.h"
13 #include "game-option/play-record-options.h"
14 #include "inventory/inventory-object.h"
15 #include "inventory/inventory-slot-types.h"
16 #include "io/write-diary.h"
17 #include "main/sound-definitions-table.h"
18 #include "main/sound-of-music.h"
19 #include "object-enchant/item-feeling.h"
20 #include "object-enchant/special-object-flags.h"
21 #include "object/item-tester-hooker.h"
22 #include "object/item-use-flags.h"
23 #include "object/object-info.h"
24 #include "object/object-stack.h"
25 #include "object/object-value.h"
26 #include "racial/racial-android.h"
27 #include "spell-kind/spells-perception.h"
28 #include "store/home.h"
29 #include "store/pricing.h"
30 #include "store/say-comments.h"
31 #include "store/service-checker.h"
32 #include "store/store-owners.h"
33 #include "store/store-util.h"
34 #include "store/store.h"
35 #include "system/object-type-definition.h"
36 #include "system/player-type-definition.h"
37 #include "term/screen-processor.h"
38 #include "util/bit-flags-calculator.h"
39 #include "view/display-messages.h"
40 #include "view/display-store.h"
41 #include "view/object-describer.h"
42 #include "world/world.h"
46 * @brief プレイヤーが売却する時の確認プロンプト / Prompt to sell for the price
47 * @param player_ptr プレイヤーへの参照ポインタ
48 * @param o_ptr オブジェクトの構造体参照ポインタ
49 * @return 売るなら(true,売値)、売らないなら(false,0)のタプル
51 static std::optional<PRICE> prompt_to_sell(PlayerType *player_ptr, object_type *o_ptr)
53 auto price_ask = price_item(player_ptr, o_ptr, ot_ptr->inflate, true);
55 price_ask = std::min(price_ask, ot_ptr->max_cost);
56 price_ask *= o_ptr->number;
57 concptr s = format(_("売値 $%ld で売りますか?", "Do you sell for $%ld? "), static_cast<long>(price_ask));
58 if (get_check_strict(player_ptr, s, CHECK_DEFAULT_Y)) {
66 * @brief 店からの売却処理のメインルーチン /
67 * Sell an item to the store (or home)
68 * @param player_ptr プレイヤーへの参照ポインタ
70 void store_sell(PlayerType *player_ptr)
72 concptr q; //!< @note プロンプトメッセージ
73 concptr s_none; //!< @note 売る/置くものがない場合のメッセージ
74 concptr s_full; //!< @note もう置けない場合のメッセージ
75 switch (cur_store_num) {
76 case StoreSaleType::HOME:
77 q = _("どのアイテムを置きますか? ", "Drop which item? ");
78 s_none = _("置けるアイテムを持っていません。", "You don't have any items to drop.");
79 s_full = _("我が家にはもう置く場所がない。", "Your home is full.");
81 case StoreSaleType::MUSEUM:
82 q = _("どのアイテムを寄贈しますか? ", "Give which item? ");
83 s_none = _("寄贈できるアイテムを持っていません。", "You don't have any items to give.");
84 s_full = _("博物館はもう満杯だ。", "The Museum is full.");
87 q = _("どのアイテムを売りますか? ", "Sell which item? ");
88 s_none = _("欲しい物がないですねえ。", "You have nothing that I want.");
89 s_full = _("すいませんが、店にはもう置く場所がありません。", "I have not the room in my store to keep it.");
95 o_ptr = choose_object(player_ptr, &item, q, s_none, USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT, FuncItemTester(store_will_buy, player_ptr));
99 if ((item >= INVEN_MAIN_HAND) && o_ptr->is_cursed()) {
100 msg_print(_("ふーむ、どうやらそれは呪われているようだね。", "Hmmm, it seems to be cursed."));
105 if (o_ptr->number > 1) {
106 amt = get_quantity(nullptr, o_ptr->number);
112 object_type *q_ptr = &forge;
113 q_ptr->copy_from(o_ptr);
116 if ((o_ptr->tval == ItemKindType::ROD) || (o_ptr->tval == ItemKindType::WAND))
117 q_ptr->pval = o_ptr->pval * amt / o_ptr->number;
119 GAME_TEXT o_name[MAX_NLEN];
120 describe_flavor(player_ptr, o_name, q_ptr, 0);
121 if ((cur_store_num != StoreSaleType::HOME) && (cur_store_num != StoreSaleType::MUSEUM)) {
122 q_ptr->inscription = 0;
123 q_ptr->feeling = FEEL_NONE;
126 if (!store_check_num(q_ptr)) {
132 if ((cur_store_num != StoreSaleType::HOME) && (cur_store_num != StoreSaleType::MUSEUM)) {
133 msg_format(_("%s(%c)を売却する。", "Selling %s (%c)."), o_name, index_to_label(item));
136 auto res = prompt_to_sell(player_ptr, q_ptr);
137 placed = res.has_value();
139 PRICE price = res.value();
140 store_owner_says_comment(player_ptr);
143 if (cur_store_num == StoreSaleType::BLACK)
144 chg_virtue(player_ptr, V_JUSTICE, -1);
146 if ((o_ptr->tval == ItemKindType::BOTTLE) && (cur_store_num != StoreSaleType::HOME))
147 chg_virtue(player_ptr, V_NATURE, 1);
149 player_ptr->au += price;
150 store_prt_gold(player_ptr);
151 PRICE dummy = object_value(q_ptr) * q_ptr->number;
153 identify_item(player_ptr, o_ptr);
155 q_ptr->copy_from(o_ptr);
157 q_ptr->ident |= IDENT_STORE;
159 if ((o_ptr->tval == ItemKindType::ROD) || (o_ptr->tval == ItemKindType::WAND))
160 q_ptr->pval = o_ptr->pval * amt / o_ptr->number;
162 PRICE value = object_value(q_ptr) * q_ptr->number;
163 describe_flavor(player_ptr, o_name, q_ptr, 0);
164 msg_format(_("%sを $%ldで売却しました。", "You sold %s for %ld gold."), o_name, static_cast<long>(price));
167 exe_write_diary(player_ptr, DIARY_SELL, 0, o_name);
169 if (!((o_ptr->tval == ItemKindType::FIGURINE) && (value > 0)))
170 purchase_analyze(player_ptr, price, value, dummy);
172 distribute_charges(o_ptr, q_ptr, amt);
174 inven_item_increase(player_ptr, item, -amt);
175 inven_item_describe(player_ptr, item);
176 if (o_ptr->number > 0)
177 autopick_alter_item(player_ptr, item, false);
179 inven_item_optimize(player_ptr, item);
180 int item_pos = store_carry(q_ptr);
182 store_top = (item_pos / store_bottom) * store_bottom;
183 display_store_inventory(player_ptr);
186 } else if (cur_store_num == StoreSaleType::MUSEUM) {
187 char o2_name[MAX_NLEN];
188 describe_flavor(player_ptr, o2_name, q_ptr, OD_NAME_ONLY);
190 if (-1 == store_check_num(q_ptr))
191 msg_print(_("それと同じ品物は既に博物館にあるようです。", "The Museum already has one of those items."));
193 msg_print(_("博物館に寄贈したものは取り出すことができません!!", "You cannot take back items which have been donated to the Museum!!"));
195 if (!get_check(format(_("本当に%sを寄贈しますか?", "Really give %s to the Museum? "), o2_name)))
198 identify_item(player_ptr, q_ptr);
199 q_ptr->ident |= IDENT_FULL_KNOWN;
201 distribute_charges(o_ptr, q_ptr, amt);
202 msg_format(_("%sを置いた。(%c)", "You drop %s (%c)."), o_name, index_to_label(item));
205 vary_item(player_ptr, item, -amt);
207 int item_pos = home_carry(player_ptr, q_ptr);
209 store_top = (item_pos / store_bottom) * store_bottom;
210 display_store_inventory(player_ptr);
213 distribute_charges(o_ptr, q_ptr, amt);
214 msg_format(_("%sを置いた。(%c)", "You drop %s (%c)."), o_name, index_to_label(item));
216 vary_item(player_ptr, item, -amt);
217 int item_pos = home_carry(player_ptr, q_ptr);
219 store_top = (item_pos / store_bottom) * store_bottom;
220 display_store_inventory(player_ptr);
224 set_bits(player_ptr->update, PU_BONUS);
225 set_bits(player_ptr->window_flags, PW_PLAYER);
226 handle_stuff(player_ptr);
228 if (placed && (item >= INVEN_MAIN_HAND)) {
229 calc_android_exp(player_ptr);
230 verify_equip_slot(player_ptr, item);