1 #include "cmd-action/cmd-open-close.h"
2 #include "action/open-close-execution.h"
3 #include "action/open-util.h"
4 #include "cmd-action/cmd-attack.h"
5 #include "core/disturbance.h"
6 #include "floor/geometry.h"
7 #include "game-option/disturbance-options.h"
8 #include "game-option/input-options.h"
9 #include "grid/feature.h"
10 #include "grid/grid.h"
11 #include "inventory/inventory-object.h"
12 #include "inventory/inventory-slot-types.h"
13 #include "io/input-key-requester.h"
14 #include "object/tval-types.h"
15 #include "player-base/player-class.h"
16 #include "player-info/samurai-data-type.h"
17 #include "player-status/player-energy.h"
18 #include "player/attack-defense-types.h"
19 #include "player/special-defense-types.h"
20 #include "specific-object/chest.h"
21 #include "status/action-setter.h"
22 #include "status/experience.h"
23 #include "system/floor-type-definition.h"
24 #include "system/grid-type-definition.h"
25 #include "system/item-entity.h"
26 #include "system/player-type-definition.h"
27 #include "system/redrawing-flags-updater.h"
28 #include "system/terrain-type-definition.h"
29 #include "target/target-getter.h"
30 #include "term/screen-processor.h"
31 #include "timed-effect/player-blindness.h"
32 #include "timed-effect/player-confusion.h"
33 #include "timed-effect/player-hallucination.h"
34 #include "timed-effect/timed-effects.h"
35 #include "util/bit-flags-calculator.h"
36 #include "view/display-messages.h"
40 * Attempt to open the given chest at the given location
41 * @param y 箱の存在するマスのY座標
42 * @param x 箱の存在するマスのX座標
43 * @param o_idx 箱のオブジェクトID
44 * @return 箱が開かなかった場合TRUE / Returns TRUE if repeated commands may continue
46 * Assume there is no monster blocking the destination
48 static bool exe_open_chest(PlayerType *player_ptr, const Pos2D &pos, OBJECT_IDX o_idx)
52 auto *o_ptr = &player_ptr->current_floor_ptr->o_list[o_idx];
53 PlayerEnergy(player_ptr).set_player_turn_energy(100);
54 if (o_ptr->pval > 0) {
56 int i = player_ptr->skill_dis;
57 const auto effects = player_ptr->effects();
58 if (effects->blindness()->is_blind() || no_lite(player_ptr)) {
62 if (effects->confusion()->is_confused() || effects->hallucination()->is_hallucinated()) {
66 int j = i - o_ptr->pval;
71 if (randint0(100) < j) {
72 msg_print(_("鍵をはずした。", "You have picked the lock."));
73 gain_exp(player_ptr, 1);
81 msg_print(_("鍵をはずせなかった。", "You failed to pick the lock."));
86 Chest chest(player_ptr);
87 chest.fire_trap(pos, o_idx);
88 chest.open(false, pos, o_idx);
95 * @brief 「開ける」コマンドのメインルーチン /
96 * Open a closed/locked/jammed door or a closed/locked chest.
98 * Unlocking a locked door/chest is worth one experience point.
100 void do_cmd_open(PlayerType *player_ptr)
103 if (player_ptr->wild_mode) {
107 PlayerClass(player_ptr).break_samurai_stance({ SamuraiStanceType::MUSOU });
111 int num_doors = count_dt(player_ptr, &y, &x, is_closed_door, false);
112 int num_chests = count_chests(player_ptr, &y, &x, false);
113 if (num_doors || num_chests) {
114 bool too_many = (num_doors && num_chests) || (num_doors > 1) || (num_chests > 1);
116 command_dir = coords_to_dir(player_ptr, y, x);
122 command_rep = command_arg - 1;
123 RedrawingFlagsUpdater::get_instance().set_flag(MainWindowRedrawingFlag::ACTION);
128 if (get_rep_dir(player_ptr, &dir, true)) {
129 y = player_ptr->y + ddy[dir];
130 x = player_ptr->x + ddx[dir];
131 const auto &grid = player_ptr->current_floor_ptr->grid_array[y][x];
132 const auto o_idx = chest_check(player_ptr->current_floor_ptr, y, x, false);
133 if (grid.get_terrain_mimic().flags.has_not(TerrainCharacteristics::OPEN) && !o_idx) {
134 msg_print(_("そこには開けるものが見当たらない。", "You see nothing there to open."));
135 } else if (grid.m_idx && player_ptr->riding != grid.m_idx) {
136 PlayerEnergy(player_ptr).set_player_turn_energy(100);
137 msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
138 do_cmd_attack(player_ptr, y, x, HISSATSU_NONE);
140 more = exe_open_chest(player_ptr, { y, x }, o_idx);
142 more = exe_open(player_ptr, y, x);
147 disturb(player_ptr, false, false);
152 * @brief 「閉じる」コマンドのメインルーチン /
153 * Close an open door.
155 * Unlocking a locked door/chest is worth one experience point.
157 void do_cmd_close(PlayerType *player_ptr)
159 if (player_ptr->wild_mode) {
163 PlayerClass(player_ptr).break_samurai_stance({ SamuraiStanceType::MUSOU });
166 if (easy_open && (count_dt(player_ptr, &y, &x, is_open, false) == 1)) {
167 command_dir = coords_to_dir(player_ptr, y, x);
171 command_rep = command_arg - 1;
172 RedrawingFlagsUpdater::get_instance().set_flag(MainWindowRedrawingFlag::ACTION);
178 if (get_rep_dir(player_ptr, &dir)) {
179 const Pos2D pos(player_ptr->y + ddy[dir], player_ptr->x + ddx[dir]);
180 const auto &grid = player_ptr->current_floor_ptr->get_grid(pos);
181 if (grid.get_terrain_mimic().flags.has_not(TerrainCharacteristics::CLOSE)) {
182 msg_print(_("そこには閉じるものが見当たらない。", "You see nothing there to close."));
183 } else if (grid.m_idx) {
184 PlayerEnergy(player_ptr).set_player_turn_energy(100);
185 msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
186 do_cmd_attack(player_ptr, pos.y, pos.x, HISSATSU_NONE);
188 more = exe_close(player_ptr, pos.y, pos.x);
193 disturb(player_ptr, false, false);
198 * @brief 箱、床のトラップ解除処理双方の統合メインルーチン /
199 * Disarms a trap, or chest
201 void do_cmd_disarm(PlayerType *player_ptr)
203 if (player_ptr->wild_mode) {
207 PlayerClass(player_ptr).break_samurai_stance({ SamuraiStanceType::MUSOU });
211 auto num_traps = count_dt(player_ptr, &y, &x, is_trap, true);
212 auto num_chests = count_chests(player_ptr, &y, &x, true);
213 if (num_traps || num_chests) {
214 auto too_many = (num_traps && num_chests) || (num_traps > 1) || (num_chests > 1);
216 command_dir = coords_to_dir(player_ptr, y, x);
222 command_rep = command_arg - 1;
223 RedrawingFlagsUpdater::get_instance().set_flag(MainWindowRedrawingFlag::ACTION);
229 if (get_rep_dir(player_ptr, &dir, true)) {
230 const Pos2D pos(player_ptr->y + ddy[dir], player_ptr->x + ddx[dir]);
231 const auto &grid = player_ptr->current_floor_ptr->get_grid(pos);
232 const auto feat = grid.get_feat_mimic();
233 const auto o_idx = chest_check(player_ptr->current_floor_ptr, pos.y, pos.x, true);
234 if (!is_trap(player_ptr, feat) && !o_idx) {
235 msg_print(_("そこには解除するものが見当たらない。", "You see nothing there to disarm."));
236 } else if (grid.m_idx && player_ptr->riding != grid.m_idx) {
237 msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
238 do_cmd_attack(player_ptr, pos.y, pos.x, HISSATSU_NONE);
240 more = exe_disarm_chest(player_ptr, pos.y, pos.x, o_idx);
242 more = exe_disarm(player_ptr, pos.y, pos.x, dir);
247 disturb(player_ptr, false, false);
252 * @brief 「打ち破る」動作コマンドのメインルーチン /
253 * Bash open a door, success based on character strength
256 * For a closed door, pval is positive if locked; negative if stuck.
258 * For an open door, pval is positive for a broken door.
260 * A closed door can be opened - harder if locked. Any door might be
261 * bashed open (and thereby broken). Bashing a door is (potentially)
262 * faster! You move into the door way. To open a stuck door, it must
263 * be bashed. A closed door can be jammed (see do_cmd_spike()).
265 * Creatures can also open or bash doors, see elsewhere.
268 void do_cmd_bash(PlayerType *player_ptr)
271 if (player_ptr->wild_mode) {
275 PlayerClass(player_ptr).break_samurai_stance({ SamuraiStanceType::MUSOU });
278 command_rep = command_arg - 1;
279 RedrawingFlagsUpdater::get_instance().set_flag(MainWindowRedrawingFlag::ACTION);
284 if (get_rep_dir(player_ptr, &dir)) {
285 const Pos2D pos(player_ptr->y + ddy[dir], player_ptr->x + ddx[dir]);
286 const Grid &grid = player_ptr->current_floor_ptr->get_grid(pos);
287 if (grid.get_terrain_mimic().flags.has_not(TerrainCharacteristics::BASH)) {
288 msg_print(_("そこには体当たりするものが見当たらない。", "You see nothing there to bash."));
289 } else if (grid.m_idx) {
290 PlayerEnergy(player_ptr).set_player_turn_energy(100);
291 msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
292 do_cmd_attack(player_ptr, pos.y, pos.x, HISSATSU_NONE);
294 more = exe_bash(player_ptr, pos.y, pos.x, dir);
299 disturb(player_ptr, false, false);
304 * @brief 「くさびを打つ」ために必要なオブジェクトを所持しているかどうかの判定を返す /
305 * Find the index of some "spikes", if possible.
306 * @param ip くさびとして打てるオブジェクトのID
307 * @return オブジェクトがある場合TRUEを返す
310 * Let user choose a pile of spikes, perhaps?
313 static bool get_spike(PlayerType *player_ptr, INVENTORY_IDX *ip)
315 for (INVENTORY_IDX i = 0; i < INVEN_PACK; i++) {
316 auto *o_ptr = &player_ptr->inventory_list[i];
317 if (!o_ptr->is_valid()) {
321 if (o_ptr->bi_key.tval() == ItemKindType::SPIKE) {
331 * @brief 「くさびを打つ」動作コマンドのメインルーチン /
332 * Jam a closed door with a spike
333 * @param player_ptr プレイヤーへの参照ポインタ
336 * This command may NOT be repeated
339 void do_cmd_spike(PlayerType *player_ptr)
342 if (player_ptr->wild_mode) {
346 PlayerClass(player_ptr).break_samurai_stance({ SamuraiStanceType::MUSOU });
348 if (!get_rep_dir(player_ptr, &dir)) {
352 const Pos2D pos(player_ptr->y + ddy[dir], player_ptr->x + ddx[dir]);
353 const auto &grid = player_ptr->current_floor_ptr->get_grid(pos);
354 const auto &terrain_mimic = grid.get_terrain_mimic();
356 if (terrain_mimic.flags.has_not(TerrainCharacteristics::SPIKE)) {
357 msg_print(_("そこにはくさびを打てるものが見当たらない。", "You see nothing there to spike."));
358 } else if (!get_spike(player_ptr, &i_idx)) {
359 msg_print(_("くさびを持っていない!", "You have no spikes!"));
360 } else if (grid.m_idx) {
361 PlayerEnergy(player_ptr).set_player_turn_energy(100);
362 msg_print(_("モンスターが立ちふさがっている!", "There is a monster in the way!"));
363 do_cmd_attack(player_ptr, pos.y, pos.x, HISSATSU_NONE);
365 PlayerEnergy(player_ptr).set_player_turn_energy(100);
366 msg_format(_("%sにくさびを打ち込んだ。", "You jam the %s with a spike."), terrain_mimic.name.data());
367 cave_alter_feat(player_ptr, pos.y, pos.x, TerrainCharacteristics::SPIKE);
368 vary_item(player_ptr, i_idx, -1);