OSDN Git Service

[Refactor] struct player_type を class PlayerType に置換。
[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/object-type-definition.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, HIT_POINT 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     object_type *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     char tmp_str[MAX_NLEN];
42     const PRICE total_cost = cost * o_ptr->number;
43     if (player_ptr->au < total_cost) {
44         describe_flavor(player_ptr, tmp_str, o_ptr, OD_NAME_ONLY);
45         msg_format(_("%sを改良するだけのゴールドがありません!", "You do not have the gold to improve %s!"), tmp_str);
46         return false;
47     }
48
49     bool okay = false;
50     for (int i = 0; i < to_hit; i++) {
51         if ((o_ptr->to_h < maxenchant) && enchant_equipment(player_ptr, o_ptr, 1, (ENCH_TOHIT | ENCH_FORCE))) {
52             okay = true;
53             break;
54         }
55     }
56
57     for (int i = 0; i < to_dam; i++) {
58         if ((o_ptr->to_d < maxenchant) && enchant_equipment(player_ptr, o_ptr, 1, (ENCH_TODAM | ENCH_FORCE))) {
59             okay = true;
60             break;
61         }
62     }
63
64     for (int i = 0; i < to_ac; i++) {
65         if ((o_ptr->to_a < maxenchant) && enchant_equipment(player_ptr, o_ptr, 1, (ENCH_TOAC | ENCH_FORCE))) {
66             okay = true;
67             break;
68         }
69     }
70
71     if (!okay) {
72         if (flush_failure)
73             flush();
74         msg_print(_("改良に失敗した。", "The improvement failed."));
75         return false;
76     }
77
78     describe_flavor(player_ptr, tmp_str, o_ptr, OD_NAME_AND_ENCHANT);
79 #ifdef JP
80     msg_format("$%dで%sに改良しました。", total_cost, tmp_str);
81 #else
82     msg_format("Improved into %s for %d gold.", tmp_str, total_cost);
83 #endif
84
85     player_ptr->au -= total_cost;
86     if (item >= INVEN_MAIN_HAND)
87         calc_android_exp(player_ptr);
88     return true;
89 }