1 #include "market/building-craft-fix.h"
2 #include "artifact/artifact-info.h"
3 #include "artifact/fixed-art-types.h"
4 #include "artifact/random-art-effects.h"
5 #include "core/asking-player.h"
6 #include "core/player-update-types.h"
7 #include "core/stuff-handler.h"
8 #include "flavor/flavor-describer.h"
9 #include "flavor/object-flavor-types.h"
10 #include "floor/floor-object.h"
11 #include "inventory/inventory-object.h"
12 #include "market/building-util.h"
13 #include "object-enchant/object-boost.h"
14 #include "object-enchant/special-object-flags.h"
15 #include "object-enchant/tr-types.h"
16 #include "object-hook/hook-weapon.h"
17 #include "object/item-tester-hooker.h"
18 #include "object/item-use-flags.h"
19 #include "object/object-flags.h"
20 #include "object/object-kind-hook.h"
21 #include "object/object-value.h"
22 #include "racial/racial-android.h"
23 #include "spell-realm/spells-hex.h"
24 #include "sv-definition/sv-other-types.h"
25 #include "sv-definition/sv-weapon-types.h"
26 #include "system/baseitem-info.h"
27 #include "system/item-entity.h"
28 #include "system/player-type-definition.h"
29 #include "term/screen-processor.h"
30 #include "util/bit-flags-calculator.h"
31 #include "view/display-messages.h"
35 * @brief 修復材料のオブジェクトから修復対象に特性を移植する。
36 * @param to_ptr 修復対象オブジェクトの構造体の参照ポインタ。
37 * @param from_ptr 修復材料オブジェクトの構造体の参照ポインタ。
38 * @return 修復対象になるならTRUEを返す。
40 static void give_one_ability_of_object(ItemEntity *to_ptr, ItemEntity *from_ptr)
42 auto to_flags = object_flags(to_ptr);
43 auto from_flags = object_flags(from_ptr);
46 tr_type cand[TR_FLAG_MAX];
47 for (int i = 0; i < TR_FLAG_MAX; i++) {
64 auto tr_flag = i2enum<tr_type>(i);
65 if (from_flags.has(tr_flag) && to_flags.has_not(tr_flag)) {
66 if (!(TR_PVAL_FLAG_MASK.has(tr_flag) && (from_ptr->pval < 1))) {
77 auto tr_idx = cand[randint0(n)];
78 to_ptr->art_flags.set(tr_idx);
79 if (TR_PVAL_FLAG_MASK.has(tr_idx)) {
80 to_ptr->pval = std::max<short>(to_ptr->pval, 1);
82 auto bmax = std::min<short>(3, std::max<short>(1, 40 / (to_ptr->dd * to_ptr->ds)));
83 if (tr_idx == TR_BLOWS) {
84 to_ptr->pval = std::min<short>(to_ptr->pval, bmax);
86 if (tr_idx == TR_SPEED) {
87 to_ptr->pval = std::min<short>(to_ptr->pval, 4);
91 static std::pair<bool, ItemEntity *> select_repairing_broken_weapon(PlayerType *player_ptr, const int row, short *item)
93 prt(_("修復には材料となるもう1つの武器が必要です。", "Hand one material weapon to repair a broken weapon."), row, 2);
94 prt(_("材料に使用した武器はなくなります!", "The material weapon will disappear after repairing!!"), row + 1, 2);
95 const auto q = _("どの折れた武器を修復しますか?", "Repair which broken weapon? ");
96 const auto s = _("修復できる折れた武器がありません。", "You have no broken weapon to repair.");
97 auto *o_ptr = choose_object(player_ptr, item, q, s, (USE_INVEN | USE_EQUIP), FuncItemTester(&ItemEntity::is_broken_weapon));
98 if (o_ptr == nullptr) {
99 return { false, nullptr };
102 if (!o_ptr->is_ego() && !o_ptr->is_fixed_or_random_artifact()) {
103 msg_format(_("それは直してもしょうがないぜ。", "It is worthless to repair."));
104 return { false, o_ptr };
107 if (o_ptr->number > 1) {
108 msg_format(_("一度に複数を修復することはできません!", "They are too many to repair at once!"));
109 return { false, o_ptr };
112 return { true, o_ptr };
115 static void display_reparing_weapon(PlayerType *player_ptr, ItemEntity *o_ptr, const int row)
117 const auto item_name = describe_flavor(player_ptr, o_ptr, OD_NAME_ONLY);
118 prt(format(_("修復する武器 : %s", "Repairing: %s"), item_name.data()), row + 3, 2);
121 static void display_repair_success_message(PlayerType *player_ptr, ItemEntity *o_ptr, const int cost)
123 const auto item_name = describe_flavor(player_ptr, o_ptr, OD_NAME_ONLY);
125 msg_format("$%dで%sに修復しました。", cost, item_name.data());
127 msg_format("Repaired into %s for %d gold.", item_name.data(), cost);
133 * @brief アイテム修復処理のメインルーチン / Repair broken weapon
134 * @param player_ptr プレイヤーへの参照ポインタ
135 * @param bcost 基本修復費用
138 static PRICE repair_broken_weapon_aux(PlayerType *player_ptr, PRICE bcost)
143 const auto &[selection, o_ptr] = select_repairing_broken_weapon(player_ptr, row, &item);
148 display_reparing_weapon(player_ptr, o_ptr, row);
149 const auto q = _("材料となる武器は?", "Which weapon for material? ");
150 const auto s = _("材料となる武器がありません。", "You have no material for the repair.");
152 auto *mo_ptr = choose_object(player_ptr, &mater, q, s, (USE_INVEN | USE_EQUIP), FuncItemTester(&ItemEntity::is_orthodox_melee_weapons));
158 msg_print(_("クラインの壷じゃない!", "This is not a Klein bottle!"));
162 const auto item_name = describe_flavor(player_ptr, mo_ptr, OD_NAME_ONLY);
163 prt(format(_("材料とする武器: %s", "Material : %s"), item_name.data()), row + 4, 2);
164 const auto cost = bcost + object_value_real(o_ptr) * 2;
165 if (!get_check(format(_("$%dかかりますがよろしいですか? ", "Costs %d gold, okay? "), cost))) {
169 if (player_ptr->au < cost) {
170 msg_format(_("%sを修復するだけのゴールドがありません!", "You do not have the gold to repair %s!"), item_name.data());
176 if (o_ptr->bi_key.sval() == SV_BROKEN_DAGGER) {
179 for (const auto &baseitem : baseitems_info) {
180 if (baseitem.bi_key.tval() != ItemKindType::SWORD) {
184 const auto sval = baseitem.bi_key.sval();
185 if ((sval == SV_BROKEN_DAGGER) || (sval == SV_BROKEN_SWORD) || (sval == SV_POISON_NEEDLE)) {
189 if (baseitem.weight > 99) {
194 bi_id = baseitem.idx;
199 auto tval = (one_in_(5) ? mo_ptr->bi_key.tval() : ItemKindType::SWORD);
201 bi_id = lookup_baseitem_id({ tval });
202 const auto &baseitem = baseitems_info[bi_id];
203 const auto sval = baseitem.bi_key.sval();
204 if (tval == ItemKindType::SWORD) {
205 if ((sval == SV_BROKEN_DAGGER) || (sval == SV_BROKEN_SWORD) || (sval == SV_DIAMOND_EDGE) || (sval == SV_POISON_NEEDLE)) {
210 if (tval == ItemKindType::POLEARM) {
211 if ((sval == SV_DEATH_SCYTHE) || (sval == SV_TSURIZAO)) {
216 if (tval == ItemKindType::HAFTED) {
217 if ((sval == SV_GROND) || (sval == SV_WIZSTAFF) || (sval == SV_NAMAKE_HAMMER)) {
226 auto dd_bonus = o_ptr->dd - baseitems_info[o_ptr->bi_id].dd;
227 auto ds_bonus = o_ptr->ds - baseitems_info[o_ptr->bi_id].ds;
228 dd_bonus += mo_ptr->dd - baseitems_info[mo_ptr->bi_id].dd;
229 ds_bonus += mo_ptr->ds - baseitems_info[mo_ptr->bi_id].ds;
231 const auto &baseitem = baseitems_info[bi_id];
232 o_ptr->bi_id = bi_id;
233 o_ptr->weight = baseitem.weight;
234 o_ptr->bi_key = baseitem.bi_key;
235 o_ptr->dd = baseitem.dd;
236 o_ptr->ds = baseitem.ds;
237 o_ptr->art_flags.set(baseitem.flags);
239 o_ptr->pval = std::max<short>(o_ptr->pval, randint1(baseitem.pval));
242 if (baseitem.flags.has(TR_ACTIVATE)) {
243 o_ptr->activation_id = baseitem.act_idx;
248 for (int i = 1; i < dd_bonus; i++) {
249 if (one_in_(o_ptr->dd + i)) {
257 for (int i = 1; i < ds_bonus; i++) {
258 if (one_in_(o_ptr->ds + i)) {
264 if (baseitem.flags.has(TR_BLOWS)) {
265 auto bmax = std::min<short>(3, std::max<short>(1, 40 / (o_ptr->dd * o_ptr->ds)));
266 o_ptr->pval = std::min<short>(o_ptr->pval, bmax);
269 give_one_ability_of_object(o_ptr, mo_ptr);
270 o_ptr->to_d += std::max(0, (mo_ptr->to_d / 3));
271 o_ptr->to_h += std::max<short>(0, (mo_ptr->to_h / 3));
272 o_ptr->to_a += std::max<short>(0, (mo_ptr->to_a));
274 const auto is_narsil = o_ptr->is_specific_artifact(FixedArtifactId::NARSIL);
275 if (is_narsil || (o_ptr->is_random_artifact() && one_in_(1)) || (o_ptr->is_ego() && one_in_(7))) {
276 if (o_ptr->is_ego()) {
277 o_ptr->art_flags.set(TR_IGNORE_FIRE);
278 o_ptr->art_flags.set(TR_IGNORE_ACID);
281 give_one_ability_of_object(o_ptr, mo_ptr);
282 if (activation_index(o_ptr) == RandomArtActType::NONE) {
283 one_activation(o_ptr);
287 one_high_resistance(o_ptr);
291 msg_print(_("これはかなりの業物だったようだ。", "This blade seems to be exceptional."));
294 display_repair_success_message(player_ptr, o_ptr, cost);
295 o_ptr->ident &= ~(IDENT_BROKEN);
296 o_ptr->discount = 99;
298 calc_android_exp(player_ptr);
299 inven_item_increase(player_ptr, mater, -1);
300 inven_item_optimize(player_ptr, mater);
302 player_ptr->update |= PU_BONUS;
303 handle_stuff(player_ptr);
308 * @brief アイテム修復処理の過渡ルーチン / Repair broken weapon
309 * @param player_ptr プレイヤーへの参照ポインタ
310 * @param bcost 基本鑑定費用
313 int repair_broken_weapon(PlayerType *player_ptr, PRICE bcost)
317 cost = repair_broken_weapon_aux(player_ptr, bcost);