OSDN Git Service

15aa7aecd9141d8b49a5a6b89d6366a926fa1eb1
[hengbandforosx/hengbandosx.git] / src / market / building-enchanter.cpp
1 #include "market/building-enchanter.h"
2 #include "flavor/flavor-describer.h"
3 #include "flavor/object-flavor-types.h"
4 #include "floor/floor-object.h"
5 #include "game-option/disturbance-options.h"
6 #include "inventory/inventory-slot-types.h"
7 #include "market/building-util.h"
8 #include "object/item-use-flags.h"
9 #include "racial/racial-android.h"
10 #include "spell/spells-object.h"
11 #include "system/item-entity.h"
12 #include "system/player-type-definition.h"
13 #include "term/screen-processor.h"
14 #include "view/display-messages.h"
15
16 /*!
17  * @brief アイテムの強化を行う。 / Enchant item
18  * @param player_ptr プレイヤーへの参照ポインタ
19  * @param cost 1回毎の費用
20  * @param to_hit 命中をアップさせる量
21  * @param to_dam ダメージをアップさせる量
22  * @param to_ac ACをアップさせる量
23  * @return 実際に行ったらTRUE
24  */
25 bool enchant_item(PlayerType *player_ptr, PRICE cost, HIT_PROB to_hit, int to_dam, ARMOUR_CLASS to_ac, const ItemTester &item_tester)
26 {
27     clear_bldg(4, 18);
28     int maxenchant = (player_ptr->lev / 5);
29     prt(format(_("現在のあなたの技量だと、+%d まで改良できます。", "  Based on your skill, we can improve up to +%d."), maxenchant), 5, 0);
30     prt(format(_(" 改良の料金は一個につき$%d です。", "  The price for the service is %d gold per item."), cost), 7, 0);
31
32     concptr q = _("どのアイテムを改良しますか?", "Improve which item? ");
33     concptr s = _("改良できるものがありません。", "You have nothing to improve.");
34
35     OBJECT_IDX item;
36     ItemEntity *o_ptr;
37     o_ptr = choose_object(player_ptr, &item, q, s, (USE_INVEN | USE_EQUIP | IGNORE_BOTHHAND_SLOT), item_tester);
38     if (!o_ptr) {
39         return false;
40     }
41
42     char tmp_str[MAX_NLEN];
43     const PRICE total_cost = cost * o_ptr->number;
44     if (player_ptr->au < total_cost) {
45         describe_flavor(player_ptr, tmp_str, o_ptr, OD_NAME_ONLY);
46         msg_format(_("%sを改良するだけのゴールドがありません!", "You do not have the gold to improve %s!"), tmp_str);
47         return false;
48     }
49
50     bool okay = false;
51     for (int i = 0; i < to_hit; i++) {
52         if ((o_ptr->to_h < maxenchant) && enchant_equipment(player_ptr, o_ptr, 1, (ENCH_TOHIT | ENCH_FORCE))) {
53             okay = true;
54             break;
55         }
56     }
57
58     for (int i = 0; i < to_dam; i++) {
59         if ((o_ptr->to_d < maxenchant) && enchant_equipment(player_ptr, o_ptr, 1, (ENCH_TODAM | ENCH_FORCE))) {
60             okay = true;
61             break;
62         }
63     }
64
65     for (int i = 0; i < to_ac; i++) {
66         if ((o_ptr->to_a < maxenchant) && enchant_equipment(player_ptr, o_ptr, 1, (ENCH_TOAC | ENCH_FORCE))) {
67             okay = true;
68             break;
69         }
70     }
71
72     if (!okay) {
73         if (flush_failure) {
74             flush();
75         }
76         msg_print(_("改良に失敗した。", "The improvement failed."));
77         return false;
78     }
79
80     describe_flavor(player_ptr, tmp_str, o_ptr, OD_NAME_AND_ENCHANT);
81 #ifdef JP
82     msg_format("$%dで%sに改良しました。", total_cost, tmp_str);
83 #else
84     msg_format("Improved into %s for %d gold.", tmp_str, total_cost);
85 #endif
86
87     player_ptr->au -= total_cost;
88     if (item >= INVEN_MAIN_HAND) {
89         calc_android_exp(player_ptr);
90     }
91     return true;
92 }