1 #include "mind/mind-archer.h"
2 #include "action/action-limited.h"
3 #include "autopick/autopick.h"
4 #include "core/asking-player.h"
5 #include "flavor/flavor-describer.h"
6 #include "floor/cave.h"
7 #include "floor/floor-object.h"
8 #include "floor/geometry.h"
10 #include "inventory/inventory-object.h"
11 #include "io/command-repeater.h"
12 #include "object-enchant/item-apply-magic.h"
13 #include "object-enchant/item-magic-applier.h"
14 #include "object-enchant/object-boost.h"
15 #include "object/item-tester-hooker.h"
16 #include "object/item-use-flags.h"
17 #include "object/object-kind-hook.h"
18 #include "perception/object-perception.h"
19 #include "system/angband.h"
20 #include "system/baseitem-info.h"
21 #include "system/floor-type-definition.h"
22 #include "system/grid-type-definition.h"
23 #include "system/item-entity.h"
24 #include "system/player-type-definition.h"
25 #include "system/redrawing-flags-updater.h"
26 #include "system/terrain-type-definition.h"
27 #include "target/target-getter.h"
28 #include "util/bit-flags-calculator.h"
29 #include "view/display-messages.h"
32 enum ammo_creation_type {
39 static bool select_ammo_creation_type(ammo_creation_type &type, PLAYER_LEVEL plev)
42 if (repeat_pull(&code)) {
43 type = i2enum<ammo_creation_type>(code);
57 prompt = _("[S]弾, [A]矢, [B]クロスボウの矢 :", "Create [S]hots, Create [A]rrow or Create [B]olt ?");
58 } else if (plev >= 10) {
59 prompt = _("[S]弾, [A]矢:", "Create [S]hots or Create [A]rrow ?");
61 prompt = _("[S]弾:", "Create [S]hots ?");
64 while (type == AMMO_NONE) {
65 const auto ch = input_command(prompt, true);
70 if (ch == 'S' || ch == 's') {
75 if ((ch == 'A' || ch == 'a') && (plev >= 10)) {
80 if ((ch == 'B' || ch == 'b') && (plev >= 20)) {
86 repeat_push(static_cast<COMMAND_CODE>(type));
91 * @brief「弾/矢の製造」処理 / do_cmd_cast calls this function if the player's class is 'archer'.
92 * Hook to determine if an object is contertible in an arrow/bolt
93 * @return 製造を実際に行ったらTRUE、キャンセルしたらFALSEを返す
95 bool create_ammo(PlayerType *player_ptr)
97 if (cmd_limit_confused(player_ptr) || cmd_limit_blind(player_ptr)) {
101 ammo_creation_type ext = AMMO_NONE;
103 if (!select_ammo_creation_type(ext, player_ptr->lev)) {
110 if (!get_rep_dir(player_ptr, &dir)) {
114 const auto pos = player_ptr->get_neighbor(dir);
115 const auto &grid = player_ptr->current_floor_ptr->get_grid(pos);
116 if (grid.get_terrain_mimic().flags.has_not(TerrainCharacteristics::CAN_DIG)) {
117 msg_print(_("そこには岩石がない。", "You need a pile of rubble."));
121 if (!grid.cave_has_flag(TerrainCharacteristics::CAN_DIG) || !grid.cave_has_flag(TerrainCharacteristics::HURT_ROCK)) {
122 msg_print(_("硬すぎて崩せなかった。", "You failed to make ammo."));
127 auto *q_ptr = &forge;
128 q_ptr->prep(lookup_baseitem_id({ ItemKindType::SHOT, m_bonus(1, player_ptr->lev) + 1 }));
129 q_ptr->number = (byte)rand_range(15, 30);
130 object_aware(player_ptr, q_ptr);
131 q_ptr->mark_as_known();
132 ItemMagicApplier(player_ptr, q_ptr, player_ptr->lev, AM_NO_FIXED_ART).execute();
133 q_ptr->discount = 99;
134 int16_t slot = store_item_to_inventory(player_ptr, q_ptr);
135 const auto item_name = describe_flavor(player_ptr, q_ptr, 0);
136 msg_print(_(format("%sを作った。", item_name.data()), "You make some ammo."));
138 autopick_alter_item(player_ptr, slot, false);
141 cave_alter_feat(player_ptr, pos.y, pos.x, TerrainCharacteristics::HURT_ROCK);
142 RedrawingFlagsUpdater::get_instance().set_flag(StatusRecalculatingFlag::FLOW);
146 constexpr auto q = _("どのアイテムから作りますか? ", "Convert which item? ");
147 constexpr auto s = _("材料を持っていない。", "You have no item to convert.");
149 auto *q_ptr = choose_object(player_ptr, &i_idx, q, s, USE_INVEN | USE_FLOOR, FuncItemTester(&ItemEntity::is_convertible));
156 q_ptr->prep(lookup_baseitem_id({ ItemKindType::ARROW, static_cast<short>(m_bonus(1, player_ptr->lev) + 1) }));
157 q_ptr->number = (byte)rand_range(5, 10);
158 object_aware(player_ptr, q_ptr);
159 q_ptr->mark_as_known();
160 ItemMagicApplier(player_ptr, q_ptr, player_ptr->lev, AM_NO_FIXED_ART).execute();
161 q_ptr->discount = 99;
162 const auto item_name = describe_flavor(player_ptr, q_ptr, 0);
163 msg_print(_(format("%sを作った。", item_name.data()), "You make some ammo."));
164 vary_item(player_ptr, i_idx, -1);
165 int16_t slot = store_item_to_inventory(player_ptr, q_ptr);
167 autopick_alter_item(player_ptr, slot, false);
173 constexpr auto q = _("どのアイテムから作りますか? ", "Convert which item? ");
174 constexpr auto s = _("材料を持っていない。", "You have no item to convert.");
176 auto *q_ptr = choose_object(player_ptr, &i_idx, q, s, (USE_INVEN | USE_FLOOR), FuncItemTester(&ItemEntity::is_convertible));
183 q_ptr->prep(lookup_baseitem_id({ ItemKindType::BOLT, static_cast<short>(m_bonus(1, player_ptr->lev) + 1) }));
184 q_ptr->number = (byte)rand_range(4, 8);
185 object_aware(player_ptr, q_ptr);
186 q_ptr->mark_as_known();
187 ItemMagicApplier(player_ptr, q_ptr, player_ptr->lev, AM_NO_FIXED_ART).execute();
188 q_ptr->discount = 99;
189 const auto item_name = describe_flavor(player_ptr, q_ptr, 0);
190 msg_print(_(format("%sを作った。", item_name.data()), "You make some ammo."));
191 vary_item(player_ptr, i_idx, -1);
192 int16_t slot = store_item_to_inventory(player_ptr, q_ptr);
194 autopick_alter_item(player_ptr, slot, false);