1 #include "store/sell-order.h"
2 #include "action/weapon-shield.h"
3 #include "autopick/autopick.h"
4 #include "core/asking-player.h"
5 #include "core/player-update-types.h"
6 #include "core/stuff-handler.h"
7 #include "core/window-redrawer.h"
8 #include "flavor/flavor-describer.h"
9 #include "flavor/object-flavor-types.h"
10 #include "floor/floor-object.h"
11 #include "game-option/birth-options.h"
12 #include "game-option/play-record-options.h"
13 #include "inventory/inventory-object.h"
14 #include "inventory/inventory-slot-types.h"
15 #include "io/write-diary.h"
16 #include "main/sound-definitions-table.h"
17 #include "main/sound-of-music.h"
18 #include "object-enchant/item-feeling.h"
19 #include "object-enchant/special-object-flags.h"
20 #include "object-hook/hook-checker.h"
21 #include "object/item-tester-hooker.h"
22 #include "object/item-use-flags.h"
23 #include "object/object-generator.h"
24 #include "object/object-info.h"
25 #include "object/object-stack.h"
26 #include "object/object-value.h"
27 #include "player-info/avatar.h"
28 #include "racial/racial-android.h"
29 #include "spell-kind/spells-perception.h"
30 #include "store/home.h"
31 #include "store/pricing.h"
32 #include "store/say-comments.h"
33 #include "store/service-checker.h"
34 #include "store/store-owners.h"
35 #include "store/store-util.h"
36 #include "store/store.h"
37 #include "system/object-type-definition.h"
38 #include "system/player-type-definition.h"
39 #include "term/screen-processor.h"
40 #include "util/bit-flags-calculator.h"
41 #include "view/display-messages.h"
42 #include "view/display-store.h"
43 #include "view/object-describer.h"
44 #include "world/world.h"
48 * @brief プレイヤーが売却する時の確認プロンプト / Prompt to sell for the price
49 * @param player_ptr プレーヤーへの参照ポインタ
50 * @param o_ptr オブジェクトの構造体参照ポインタ
51 * @return 売るなら(true,売値)、売らないなら(false,0)のタプル
53 static std::optional<PRICE> prompt_to_sell(player_type *player_ptr, object_type *o_ptr)
55 auto price_ask = price_item(player_ptr, o_ptr, ot_ptr->inflate, TRUE);
56 auto is_low_price = price_ask < LOW_PRICE_THRESHOLD;
59 price_ask -= price_ask / 10;
61 auto max_price = (PRICE)ot_ptr->max_cost;
63 if (price_ask > max_price) {
64 msg_print(_("即座にこの金額にまとまった。", "You instantly agree upon the price."));
66 price_ask = max_price;
68 msg_print(_("すんなりとこの金額にまとまった。", "You quickly agree upon the price."));
72 price_ask *= o_ptr->number;
73 concptr s = format(_("売値 $%ld で売りますか?", "Do you sell for $%ld? "), static_cast<long>(price_ask));
74 if (get_check_strict(player_ptr, s, CHECK_DEFAULT_Y)) {
82 * @brief 店からの売却処理のメインルーチン /
83 * Sell an item to the store (or home)
84 * @param owner_ptr プレーヤーへの参照ポインタ
86 void store_sell(player_type *owner_ptr)
88 concptr q; //!< @note プロンプトメッセージ
89 concptr s_none; //!< @note 売る/置くものがない場合のメッセージ
90 concptr s_full; //!< @note もう置けない場合のメッセージ
91 switch (cur_store_num) {
93 q = _("どのアイテムを置きますか? ", "Drop which item? ");
94 s_none = _("置けるアイテムを持っていません。", "You don't have any items to drop.");
95 s_full = _("我が家にはもう置く場所がない。", "Your home is full.");
98 q = _("どのアイテムを寄贈しますか? ", "Give which item? ");
99 s_none = _("寄贈できるアイテムを持っていません。", "You don't have any items to give.");
100 s_full = _("博物館はもう満杯だ。", "The Museum is full.");
103 q = _("どのアイテムを売りますか? ", "Sell which item? ");
104 s_none = _("欲しい物がないですねえ。", "You have nothing that I want.");
105 s_full = _("すいませんが、店にはもう置く場所がありません。", "I have not the room in my store to keep it.");
109 item_tester_hook = store_will_buy;
113 o_ptr = choose_object(owner_ptr, &item, q, s_none, USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT, TV_NONE);
117 if ((item >= INVEN_MAIN_HAND) && object_is_cursed(o_ptr)) {
118 msg_print(_("ふーむ、どうやらそれは呪われているようだね。", "Hmmm, it seems to be cursed."));
123 if (o_ptr->number > 1) {
124 amt = get_quantity(NULL, o_ptr->number);
130 object_type *q_ptr = &forge;
131 object_copy(q_ptr, o_ptr);
134 if ((o_ptr->tval == TV_ROD) || (o_ptr->tval == TV_WAND))
135 q_ptr->pval = o_ptr->pval * amt / o_ptr->number;
137 GAME_TEXT o_name[MAX_NLEN];
138 describe_flavor(owner_ptr, o_name, q_ptr, 0);
139 if ((cur_store_num != STORE_HOME) && (cur_store_num != STORE_MUSEUM)) {
140 q_ptr->inscription = 0;
141 q_ptr->feeling = FEEL_NONE;
144 if (!store_check_num(q_ptr)) {
150 if ((cur_store_num != STORE_HOME) && (cur_store_num != STORE_MUSEUM)) {
151 msg_format(_("%s(%c)を売却する。", "Selling %s (%c)."), o_name, index_to_label(item));
154 auto res = prompt_to_sell(owner_ptr, q_ptr);
155 placed = res.has_value();
157 PRICE price = res.value();
158 store_owner_says_comment(owner_ptr);
161 if (cur_store_num == STORE_BLACK)
162 chg_virtue(owner_ptr, V_JUSTICE, -1);
164 if ((o_ptr->tval == TV_BOTTLE) && (cur_store_num != STORE_HOME))
165 chg_virtue(owner_ptr, V_NATURE, 1);
167 owner_ptr->au += price;
168 store_prt_gold(owner_ptr);
169 PRICE dummy = object_value(owner_ptr, q_ptr) * q_ptr->number;
171 identify_item(owner_ptr, o_ptr);
173 object_copy(q_ptr, o_ptr);
175 q_ptr->ident |= IDENT_STORE;
177 if ((o_ptr->tval == TV_ROD) || (o_ptr->tval == TV_WAND))
178 q_ptr->pval = o_ptr->pval * amt / o_ptr->number;
180 PRICE value = object_value(owner_ptr, q_ptr) * q_ptr->number;
181 describe_flavor(owner_ptr, o_name, q_ptr, 0);
182 msg_format(_("%sを $%ldで売却しました。", "You sold %s for %ld gold."), o_name, static_cast<long>(price));
185 exe_write_diary(owner_ptr, DIARY_SELL, 0, o_name);
187 if (!((o_ptr->tval == TV_FIGURINE) && (value > 0)))
188 purchase_analyze(owner_ptr, price, value, dummy);
190 distribute_charges(o_ptr, q_ptr, amt);
192 inven_item_increase(owner_ptr, item, -amt);
193 inven_item_describe(owner_ptr, item);
194 if (o_ptr->number > 0)
195 autopick_alter_item(owner_ptr, item, FALSE);
197 inven_item_optimize(owner_ptr, item);
198 int item_pos = store_carry(owner_ptr, q_ptr);
200 store_top = (item_pos / store_bottom) * store_bottom;
201 display_store_inventory(owner_ptr);
204 } else if (cur_store_num == STORE_MUSEUM) {
205 char o2_name[MAX_NLEN];
206 describe_flavor(owner_ptr, o2_name, q_ptr, OD_NAME_ONLY);
208 if (-1 == store_check_num(q_ptr))
209 msg_print(_("それと同じ品物は既に博物館にあるようです。", "The Museum already has one of those items."));
211 msg_print(_("博物館に寄贈したものは取り出すことができません!!", "You cannot take back items which have been donated to the Museum!!"));
213 if (!get_check(format(_("本当に%sを寄贈しますか?", "Really give %s to the Museum? "), o2_name)))
216 identify_item(owner_ptr, q_ptr);
217 q_ptr->ident |= IDENT_FULL_KNOWN;
219 distribute_charges(o_ptr, q_ptr, amt);
220 msg_format(_("%sを置いた。(%c)", "You drop %s (%c)."), o_name, index_to_label(item));
223 vary_item(owner_ptr, item, -amt);
225 int item_pos = home_carry(owner_ptr, q_ptr);
227 store_top = (item_pos / store_bottom) * store_bottom;
228 display_store_inventory(owner_ptr);
231 distribute_charges(o_ptr, q_ptr, amt);
232 msg_format(_("%sを置いた。(%c)", "You drop %s (%c)."), o_name, index_to_label(item));
234 vary_item(owner_ptr, item, -amt);
235 int item_pos = home_carry(owner_ptr, q_ptr);
237 store_top = (item_pos / store_bottom) * store_bottom;
238 display_store_inventory(owner_ptr);
242 set_bits(owner_ptr->update, PU_BONUS);
243 set_bits(owner_ptr->window_flags, PW_PLAYER);
244 handle_stuff(owner_ptr);
246 if (placed && (item >= INVEN_MAIN_HAND)) {
247 calc_android_exp(owner_ptr);
248 verify_equip_slot(owner_ptr, item);