1 #include "inventory/player-inventory.h"
2 #include "autopick/autopick.h"
3 #include "core/asking-player.h"
4 #include "core/disturbance.h"
5 #include "core/player-redraw-types.h"
6 #include "core/player-update-types.h"
7 #include "core/stuff-handler.h"
8 #include "core/window-redrawer.h"
9 #include "dungeon/quest.h"
10 #include "flavor/flavor-describer.h"
11 #include "flavor/object-flavor-types.h"
12 #include "floor/floor-object.h"
13 #include "floor/object-scanner.h"
14 #include "game-option/auto-destruction-options.h"
15 #include "game-option/birth-options.h"
16 #include "game-option/input-options.h"
17 #include "game-option/play-record-options.h"
18 #include "game-option/text-display-options.h"
19 #include "inventory/inventory-object.h"
20 #include "inventory/inventory-slot-types.h"
21 #include "main/sound-definitions-table.h"
22 #include "main/sound-of-music.h"
23 #include "object/item-tester-hooker.h"
24 #include "object/item-use-flags.h"
25 #include "object/object-info.h"
26 #include "object/object-mark-types.h"
27 #include "player/player-move.h"
28 #include "spell-kind/spells-perception.h"
29 #include "system/floor-type-definition.h"
30 #include "system/grid-type-definition.h"
31 #include "system/item-entity.h"
32 #include "system/player-type-definition.h"
33 #include "target/target-checker.h"
34 #include "term/z-form.h"
35 #include "util/string-processor.h"
36 #include "view/display-messages.h"
37 #include "world/world.h"
39 #include "artifact/fixed-art-types.h"
40 #include "flavor/flavor-util.h"
44 * @brief 規定の処理にできるアイテムがプレイヤーの利用可能範囲内にあるかどうかを返す /
45 * Determine whether get_item() can get some item or not
46 * @return アイテムを拾えるならばTRUEを返す。
47 * @details assuming mode = (USE_EQUIP | USE_INVEN | USE_FLOOR).
49 bool can_get_item(PlayerType *player_ptr, const ItemTester &item_tester)
51 for (int j = 0; j < INVEN_TOTAL; j++) {
52 if (item_tester.okay(&player_ptr->inventory_list[j])) {
57 OBJECT_IDX floor_list[23];
58 ITEM_NUMBER floor_num = scan_floor_items(player_ptr, floor_list, player_ptr->y, player_ptr->x, SCAN_FLOOR_ITEM_TESTER | SCAN_FLOOR_ONLY_MARKED, item_tester);
59 return floor_num != 0;
63 * @brief 床上のアイテムを拾う選択用サブルーチン
64 * @return プレイヤーによりアイテムが選択されたならTRUEを返す。
66 static bool py_pickup_floor_aux(PlayerType *player_ptr)
68 OBJECT_IDX this_o_idx;
70 concptr q = _("どれを拾いますか?", "Get which item? ");
71 concptr s = _("もうザックには床にあるどのアイテムも入らない。", "You no longer have any room for the objects on the floor.");
72 if (choose_object(player_ptr, &item, q, s, (USE_FLOOR), FuncItemTester(check_store_item_to_inventory, player_ptr))) {
73 this_o_idx = 0 - item;
78 describe_pickup_item(player_ptr, this_o_idx);
83 * @brief 床上のアイテムを拾うメイン処理
84 * @param pickup FALSEなら金銭の自動拾いのみを行う/ FALSE then only gold will be picked up
86 * This is called by py_pickup() when easy_floor is TRUE.
88 void py_pickup_floor(PlayerType *player_ptr, bool pickup)
91 OBJECT_IDX floor_o_idx = 0;
93 auto &o_idx_list = player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x].o_idx_list;
94 for (auto it = o_idx_list.begin(); it != o_idx_list.end();) {
95 const OBJECT_IDX this_o_idx = *it++;
96 auto *o_ptr = &player_ptr->current_floor_ptr->o_list[this_o_idx];
97 const auto item_name = describe_flavor(player_ptr, o_ptr, 0);
98 disturb(player_ptr, false, false);
99 if (o_ptr->bi_key.tval() == ItemKindType::GOLD) {
100 constexpr auto mes = _(" $%ld の価値がある%sを見つけた。", "You have found %ld gold pieces worth of %s.");
101 msg_format(mes, (long)o_ptr->pval, item_name.data());
103 player_ptr->au += o_ptr->pval;
104 player_ptr->redraw |= (PR_GOLD);
105 player_ptr->window_flags |= (PW_PLAYER);
106 delete_object_idx(player_ptr, this_o_idx);
108 } else if (o_ptr->marked.has(OmType::SUPRESS_MESSAGE)) {
109 o_ptr->marked.reset(OmType::SUPRESS_MESSAGE);
113 if (check_store_item_to_inventory(player_ptr, o_ptr)) {
118 floor_o_idx = this_o_idx;
126 if (floor_num == 1) {
127 auto *o_ptr = &player_ptr->current_floor_ptr->o_list[floor_o_idx];
128 const auto item_name = describe_flavor(player_ptr, o_ptr, 0);
129 msg_format(_("%sがある。", "You see %s."), item_name.data());
131 msg_format(_("%d 個のアイテムの山がある。", "You see a pile of %d items."), floor_num);
138 if (floor_num == 1) {
139 auto *o_ptr = &player_ptr->current_floor_ptr->o_list[floor_o_idx];
140 const auto item_name = describe_flavor(player_ptr, o_ptr, 0);
141 msg_format(_("ザックには%sを入れる隙間がない。", "You have no room for %s."), item_name.data());
143 msg_print(_("ザックには床にあるどのアイテムも入らない。", "You have no room for any of the objects on the floor."));
149 if (floor_num != 1) {
150 while (can_pickup--) {
151 if (!py_pickup_floor_aux(player_ptr)) {
159 if (!carry_query_flag) {
160 describe_pickup_item(player_ptr, floor_o_idx);
164 char out_val[MAX_NLEN + 20];
165 auto *o_ptr = &player_ptr->current_floor_ptr->o_list[floor_o_idx];
166 const auto item_name = describe_flavor(player_ptr, o_ptr, 0);
167 strnfmt(out_val, sizeof(out_val), _("%sを拾いますか? ", "Pick up %s? "), item_name.data());
168 if (!get_check(out_val)) {
172 describe_pickup_item(player_ptr, floor_o_idx);
176 * @brief プレイヤーがオブジェクトを拾った際のメッセージ表示処理 /
177 * Helper routine for py_pickup() and py_pickup_floor().
178 * @param player_ptr プレイヤーへの参照ポインタ
179 * @param o_idx 取得したオブジェクトの参照ID
181 * アイテムを拾った際に「2つのケーキを持っている」
182 * "You have two cakes." とアイテムを拾った後の合計のみの表示がオリジナルだが、
183 * 違和感があるという指摘をうけたので、「~を拾った、~を持っている」という表示にかえてある。
185 * Add the given dungeon object to the character's inventory.\n
186 * Delete the object afterwards.\n
188 void describe_pickup_item(PlayerType *player_ptr, OBJECT_IDX o_idx)
190 auto *o_ptr = &player_ptr->current_floor_ptr->o_list[o_idx];
192 const auto old_item_name = describe_flavor(player_ptr, o_ptr, OD_NAME_ONLY);
193 const auto picked_count_str = describe_count_with_counter_suffix(*o_ptr);
194 const auto picked_count = o_ptr->number;
199 auto slot = store_item_to_inventory(player_ptr, o_ptr);
200 o_ptr = &player_ptr->inventory_list[slot];
201 delete_object_idx(player_ptr, o_idx);
202 if (player_ptr->ppersonality == PERSONALITY_MUNCHKIN) {
203 bool old_known = identify_item(player_ptr, o_ptr);
204 autopick_alter_item(player_ptr, slot, (bool)(destroy_identify && !old_known));
205 if (o_ptr->marked.has(OmType::AUTODESTROY)) {
210 const auto item_name = describe_flavor(player_ptr, o_ptr, 0);
212 if (o_ptr->is_specific_artifact(FixedArtifactId::CRIMSON) && (player_ptr->ppersonality == PERSONALITY_COMBAT)) {
213 msg_format("こうして、%sは『クリムゾン』を手に入れた。", player_ptr->name);
214 msg_print("しかし今、『混沌のサーペント』の放ったモンスターが、");
215 msg_format("%sに襲いかかる...", player_ptr->name);
218 msg_format("%s(%c)を持っている。", item_name.data(), index_to_label(slot));
220 if (o_ptr->number > picked_count) {
221 msg_format("%s拾って、%s(%c)を持っている。", picked_count_str.data(), item_name.data(), index_to_label(slot));
223 msg_format("%s(%c)を拾った。", item_name.data(), index_to_label(slot));
228 angband_strcpy(record_o_name, old_item_name.data(), old_item_name.length());
230 msg_format("You have %s (%c).", item_name.data(), index_to_label(slot));
231 angband_strcpy(record_o_name, item_name.data(), item_name.length());
233 record_turn = w_ptr->game_turn;
234 check_find_art_quest_completion(player_ptr, o_ptr);
238 * @brief プレイヤーがオブジェクト上に乗った際の表示処理 / Player "wants" to pick up an object or gold.
239 * @param player_ptr プレイヤーへの参照ポインタ
240 * @param pickup 自動拾い処理を行うならばTRUEとする
242 void carry(PlayerType *player_ptr, bool pickup)
244 verify_panel(player_ptr);
245 player_ptr->update |= PU_MONSTER_STATUSES;
246 player_ptr->redraw |= PR_MAP;
247 player_ptr->window_flags |= PW_OVERHEAD;
248 handle_stuff(player_ptr);
249 auto *g_ptr = &player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x];
250 autopick_pickup_items(player_ptr, g_ptr);
252 py_pickup_floor(player_ptr, pickup);
256 for (auto it = g_ptr->o_idx_list.begin(); it != g_ptr->o_idx_list.end();) {
257 const OBJECT_IDX this_o_idx = *it++;
258 auto *o_ptr = &player_ptr->current_floor_ptr->o_list[this_o_idx];
259 const auto item_name = describe_flavor(player_ptr, o_ptr, 0);
260 disturb(player_ptr, false, false);
261 if (o_ptr->bi_key.tval() == ItemKindType::GOLD) {
262 int value = (long)o_ptr->pval;
263 delete_object_idx(player_ptr, this_o_idx);
264 msg_format(_(" $%ld の価値がある%sを見つけた。", "You collect %ld gold pieces worth of %s."), (long)value, item_name.data());
266 player_ptr->au += value;
267 player_ptr->redraw |= (PR_GOLD);
268 player_ptr->window_flags |= (PW_PLAYER);
272 if (o_ptr->marked.has(OmType::SUPRESS_MESSAGE)) {
273 o_ptr->marked.reset(OmType::SUPRESS_MESSAGE);
278 msg_format(_("%sがある。", "You see %s."), item_name.data());
282 if (!check_store_item_to_inventory(player_ptr, o_ptr)) {
283 msg_format(_("ザックには%sを入れる隙間がない。", "You have no room for %s."), item_name.data());
287 int is_pickup_successful = true;
288 if (carry_query_flag) {
289 char out_val[MAX_NLEN + 20];
290 strnfmt(out_val, sizeof(out_val), _("%sを拾いますか? ", "Pick up %s? "), item_name.data());
291 is_pickup_successful = get_check(out_val);
294 if (is_pickup_successful) {
295 describe_pickup_item(player_ptr, this_o_idx);