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/stuff-handler.h"
6 #include "core/window-redrawer.h"
7 #include "dungeon/quest.h"
8 #include "flavor/flavor-describer.h"
9 #include "flavor/object-flavor-types.h"
10 #include "floor/floor-object.h"
11 #include "floor/object-scanner.h"
12 #include "game-option/auto-destruction-options.h"
13 #include "game-option/birth-options.h"
14 #include "game-option/input-options.h"
15 #include "game-option/play-record-options.h"
16 #include "game-option/text-display-options.h"
17 #include "inventory/inventory-object.h"
18 #include "inventory/inventory-slot-types.h"
19 #include "main/sound-definitions-table.h"
20 #include "main/sound-of-music.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-mark-types.h"
25 #include "player/player-move.h"
26 #include "spell-kind/spells-perception.h"
27 #include "system/floor-type-definition.h"
28 #include "system/grid-type-definition.h"
29 #include "system/item-entity.h"
30 #include "system/player-type-definition.h"
31 #include "system/redrawing-flags-updater.h"
32 #include "target/target-checker.h"
33 #include "term/z-form.h"
34 #include "util/string-processor.h"
35 #include "view/display-messages.h"
36 #include "world/world.h"
38 #include "artifact/fixed-art-types.h"
39 #include "flavor/flavor-util.h"
43 * @brief 規定の処理にできるアイテムがプレイヤーの利用可能範囲内にあるかどうかを返す /
44 * Determine whether get_item() can get some item or not
45 * @return アイテムを拾えるならばTRUEを返す。
46 * @details assuming mode = (USE_EQUIP | USE_INVEN | USE_FLOOR).
48 bool can_get_item(PlayerType *player_ptr, const ItemTester &item_tester)
50 for (int j = 0; j < INVEN_TOTAL; j++) {
51 if (item_tester.okay(&player_ptr->inventory_list[j])) {
56 constexpr auto mode = SCAN_FLOOR_ITEM_TESTER | SCAN_FLOOR_ONLY_MARKED;
57 OBJECT_IDX floor_list[23];
58 ITEM_NUMBER floor_num = scan_floor_items(player_ptr, floor_list, player_ptr->y, player_ptr->x, mode, item_tester);
59 return floor_num != 0;
63 * @brief 床上のアイテムを拾う選択用サブルーチン
64 * @return プレイヤーによりアイテムが選択されたならTRUEを返す。
66 static bool py_pickup_floor_aux(PlayerType *player_ptr)
70 constexpr auto q = _("どれを拾いますか?", "Get which item? ");
71 constexpr auto s = _("もうザックには床にあるどのアイテムも入らない。", "You no longer have any room for the objects on the floor.");
72 if (choose_object(player_ptr, &i_idx, q, s, (USE_FLOOR), FuncItemTester(check_store_item_to_inventory, player_ptr))) {
73 this_o_idx = 0 - i_idx;
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 auto &rfu = RedrawingFlagsUpdater::get_instance();
95 for (auto it = o_idx_list.begin(); it != o_idx_list.end();) {
96 const OBJECT_IDX this_o_idx = *it++;
97 auto *o_ptr = &player_ptr->current_floor_ptr->o_list[this_o_idx];
98 const auto item_name = describe_flavor(player_ptr, o_ptr, 0);
99 disturb(player_ptr, false, false);
100 if (o_ptr->bi_key.tval() == ItemKindType::GOLD) {
101 constexpr auto mes = _(" $%ld の価値がある%sを見つけた。", "You have found %ld gold pieces worth of %s.");
102 msg_format(mes, (long)o_ptr->pval, item_name.data());
104 player_ptr->au += o_ptr->pval;
105 rfu.set_flag(MainWindowRedrawingFlag::GOLD);
106 rfu.set_flag(SubWindowRedrawingFlag::PLAYER);
107 delete_object_idx(player_ptr, this_o_idx);
109 } else if (o_ptr->marked.has(OmType::SUPRESS_MESSAGE)) {
110 o_ptr->marked.reset(OmType::SUPRESS_MESSAGE);
114 if (check_store_item_to_inventory(player_ptr, o_ptr)) {
119 floor_o_idx = this_o_idx;
127 if (floor_num == 1) {
128 auto *o_ptr = &player_ptr->current_floor_ptr->o_list[floor_o_idx];
129 const auto item_name = describe_flavor(player_ptr, o_ptr, 0);
130 msg_format(_("%sがある。", "You see %s."), item_name.data());
132 msg_format(_("%d 個のアイテムの山がある。", "You see a pile of %d items."), floor_num);
139 if (floor_num == 1) {
140 auto *o_ptr = &player_ptr->current_floor_ptr->o_list[floor_o_idx];
141 const auto item_name = describe_flavor(player_ptr, o_ptr, 0);
142 msg_format(_("ザックには%sを入れる隙間がない。", "You have no room for %s."), item_name.data());
144 msg_print(_("ザックには床にあるどのアイテムも入らない。", "You have no room for any of the objects on the floor."));
150 if (floor_num != 1) {
151 while (can_pickup--) {
152 if (!py_pickup_floor_aux(player_ptr)) {
160 if (!carry_query_flag) {
161 describe_pickup_item(player_ptr, floor_o_idx);
165 char out_val[MAX_NLEN + 20];
166 auto *o_ptr = &player_ptr->current_floor_ptr->o_list[floor_o_idx];
167 const auto item_name = describe_flavor(player_ptr, o_ptr, 0);
168 strnfmt(out_val, sizeof(out_val), _("%sを拾いますか? ", "Pick up %s? "), item_name.data());
169 if (!input_check(out_val)) {
173 describe_pickup_item(player_ptr, floor_o_idx);
177 * @brief プレイヤーがオブジェクトを拾った際のメッセージ表示処理 /
178 * Helper routine for py_pickup() and py_pickup_floor().
179 * @param player_ptr プレイヤーへの参照ポインタ
180 * @param o_idx 取得したオブジェクトの参照ID
182 * アイテムを拾った際に「2つのケーキを持っている」
183 * "You have two cakes." とアイテムを拾った後の合計のみの表示がオリジナルだが、
184 * 違和感があるという指摘をうけたので、「~を拾った、~を持っている」という表示にかえてある。
186 * Add the given dungeon object to the character's inventory.\n
187 * Delete the object afterwards.\n
189 void describe_pickup_item(PlayerType *player_ptr, OBJECT_IDX o_idx)
191 auto *o_ptr = &player_ptr->current_floor_ptr->o_list[o_idx];
193 const auto old_item_name = describe_flavor(player_ptr, o_ptr, OD_NAME_ONLY);
194 const auto picked_count_str = describe_count_with_counter_suffix(*o_ptr);
195 const auto picked_count = o_ptr->number;
200 auto slot = store_item_to_inventory(player_ptr, o_ptr);
201 o_ptr = &player_ptr->inventory_list[slot];
202 delete_object_idx(player_ptr, o_idx);
203 if (player_ptr->ppersonality == PERSONALITY_MUNCHKIN) {
204 bool old_known = identify_item(player_ptr, o_ptr);
205 autopick_alter_item(player_ptr, slot, (bool)(destroy_identify && !old_known));
206 if (o_ptr->marked.has(OmType::AUTODESTROY)) {
211 const auto item_name = describe_flavor(player_ptr, o_ptr, 0);
213 if (o_ptr->is_specific_artifact(FixedArtifactId::CRIMSON) && (player_ptr->ppersonality == PERSONALITY_COMBAT)) {
214 msg_format("こうして、%sは『クリムゾン』を手に入れた。", player_ptr->name);
215 msg_print("しかし今、『混沌のサーペント』の放ったモンスターが、");
216 msg_format("%sに襲いかかる...", player_ptr->name);
219 msg_format("%s(%c)を持っている。", item_name.data(), index_to_label(slot));
221 if (o_ptr->number > picked_count) {
222 msg_format("%s拾って、%s(%c)を持っている。", picked_count_str.data(), item_name.data(), index_to_label(slot));
224 msg_format("%s(%c)を拾った。", item_name.data(), index_to_label(slot));
229 angband_strcpy(record_o_name, old_item_name, old_item_name.length());
231 msg_format("You have %s (%c).", item_name.data(), index_to_label(slot));
232 angband_strcpy(record_o_name, item_name, item_name.length());
234 record_turn = w_ptr->game_turn;
235 check_find_art_quest_completion(player_ptr, o_ptr);
239 * @brief プレイヤーがオブジェクト上に乗った際の表示処理 / Player "wants" to pick up an object or gold.
240 * @param player_ptr プレイヤーへの参照ポインタ
241 * @param pickup 自動拾い処理を行うならばTRUEとする
243 void carry(PlayerType *player_ptr, bool pickup)
245 verify_panel(player_ptr);
246 auto &rfu = RedrawingFlagsUpdater::get_instance();
247 rfu.set_flag(StatusRecalculatingFlag::MONSTER_STATUSES);
248 rfu.set_flag(MainWindowRedrawingFlag::MAP);
249 rfu.set_flag(SubWindowRedrawingFlag::OVERHEAD);
250 handle_stuff(player_ptr);
251 auto *g_ptr = &player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x];
252 autopick_pickup_items(player_ptr, g_ptr);
254 py_pickup_floor(player_ptr, pickup);
258 for (auto it = g_ptr->o_idx_list.begin(); it != g_ptr->o_idx_list.end();) {
259 const OBJECT_IDX this_o_idx = *it++;
260 auto *o_ptr = &player_ptr->current_floor_ptr->o_list[this_o_idx];
261 const auto item_name = describe_flavor(player_ptr, o_ptr, 0);
262 disturb(player_ptr, false, false);
263 if (o_ptr->bi_key.tval() == ItemKindType::GOLD) {
264 int value = (long)o_ptr->pval;
265 delete_object_idx(player_ptr, this_o_idx);
266 msg_format(_(" $%ld の価値がある%sを見つけた。", "You collect %ld gold pieces worth of %s."), (long)value, item_name.data());
268 player_ptr->au += value;
269 rfu.set_flag(MainWindowRedrawingFlag::GOLD);
270 rfu.set_flag(SubWindowRedrawingFlag::PLAYER);
274 if (o_ptr->marked.has(OmType::SUPRESS_MESSAGE)) {
275 o_ptr->marked.reset(OmType::SUPRESS_MESSAGE);
280 msg_format(_("%sがある。", "You see %s."), item_name.data());
284 if (!check_store_item_to_inventory(player_ptr, o_ptr)) {
285 msg_format(_("ザックには%sを入れる隙間がない。", "You have no room for %s."), item_name.data());
289 int is_pickup_successful = true;
290 if (carry_query_flag) {
291 char out_val[MAX_NLEN + 20];
292 strnfmt(out_val, sizeof(out_val), _("%sを拾いますか? ", "Pick up %s? "), item_name.data());
293 is_pickup_successful = input_check(out_val);
296 if (is_pickup_successful) {
297 describe_pickup_item(player_ptr, this_o_idx);