OSDN Git Service

[Refactor] ItemEntity::marked を FlagGroup 化する
[hengbandforosx/hengbandosx.git] / src / spell-kind / spells-enchant.cpp
1 #include "spell-kind/spells-enchant.h"
2 #include "artifact/random-art-generator.h"
3 #include "avatar/avatar.h"
4 #include "flavor/flavor-describer.h"
5 #include "flavor/object-flavor-types.h"
6 #include "floor/floor-object.h"
7 #include "game-option/disturbance-options.h"
8 #include "game-option/play-record-options.h"
9 #include "inventory/inventory-object.h"
10 #include "io/write-diary.h"
11 #include "object-hook/hook-perception.h"
12 #include "object-hook/hook-weapon.h"
13 #include "object/item-tester-hooker.h"
14 #include "object/item-use-flags.h"
15 #include "racial/racial-android.h"
16 #include "system/item-entity.h"
17 #include "system/player-type-definition.h"
18 #include "term/screen-processor.h"
19 #include "view/display-messages.h"
20
21 #include <memory>
22
23 /*!
24  * @brief アーティファクト生成の巻物処理 /
25  * @param player_ptr プレイヤーへの参照ポインタ
26  * @return 生成が実際に試みられたらTRUEを返す
27  */
28 bool artifact_scroll(PlayerType *player_ptr)
29 {
30     concptr q = _("どのアイテムを強化しますか? ", "Enchant which item? ");
31     concptr s = _("強化できるアイテムがない。", "You have nothing to enchant.");
32     ItemEntity *o_ptr;
33     OBJECT_IDX item;
34     o_ptr = choose_object(player_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), FuncItemTester(object_is_nameless_weapon_armour));
35     if (!o_ptr) {
36         return false;
37     }
38
39     GAME_TEXT o_name[MAX_NLEN];
40     describe_flavor(player_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
41 #ifdef JP
42     msg_format("%s は眩い光を発した!", o_name);
43 #else
44     msg_format("%s %s radiate%s a blinding light!", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "" : "s"));
45 #endif
46
47     bool okay = false;
48     if (o_ptr->is_artifact()) {
49 #ifdef JP
50         msg_format("%sは既に伝説のアイテムです!", o_name);
51 #else
52         msg_format("The %s %s already %s!", o_name, ((o_ptr->number > 1) ? "are" : "is"), ((o_ptr->number > 1) ? "artifacts" : "an artifact"));
53 #endif
54         okay = false;
55     } else if (o_ptr->is_ego()) {
56 #ifdef JP
57         msg_format("%sは既に名のあるアイテムです!", o_name);
58 #else
59         msg_format("The %s %s already %s!", o_name, ((o_ptr->number > 1) ? "are" : "is"), ((o_ptr->number > 1) ? "ego items" : "an ego item"));
60 #endif
61         okay = false;
62     } else if (o_ptr->is_smith()) {
63 #ifdef JP
64         msg_format("%sは既に強化されています!", o_name);
65 #else
66         msg_format("The %s %s already %s!", o_name, ((o_ptr->number > 1) ? "are" : "is"), ((o_ptr->number > 1) ? "customized items" : "a customized item"));
67 #endif
68     } else {
69         if (o_ptr->number > 1) {
70             msg_print(_("複数のアイテムに魔法をかけるだけのエネルギーはありません!", "Not enough energy to enchant more than one object!"));
71 #ifdef JP
72             msg_format("%d 個の%sが壊れた!", (o_ptr->number) - 1, o_name);
73 #else
74             msg_format("%d of your %s %s destroyed!", (o_ptr->number) - 1, o_name, (o_ptr->number > 2 ? "were" : "was"));
75 #endif
76
77             if (item >= 0) {
78                 inven_item_increase(player_ptr, item, 1 - (o_ptr->number));
79             } else {
80                 floor_item_increase(player_ptr, 0 - item, 1 - (o_ptr->number));
81             }
82         }
83
84         okay = become_random_artifact(player_ptr, o_ptr, true);
85     }
86
87     if (!okay) {
88         if (flush_failure) {
89             flush();
90         }
91
92         msg_print(_("強化に失敗した。", "The enchantment failed."));
93         if (one_in_(3)) {
94             chg_virtue(player_ptr, V_ENCHANT, -1);
95         }
96
97         calc_android_exp(player_ptr);
98         return true;
99     }
100
101     if (record_rand_art) {
102         describe_flavor(player_ptr, o_name, o_ptr, OD_NAME_ONLY);
103         exe_write_diary(player_ptr, DIARY_ART_SCROLL, 0, o_name);
104     }
105
106     chg_virtue(player_ptr, V_ENCHANT, 1);
107     calc_android_exp(player_ptr);
108     return true;
109 }
110
111 /*!
112  * @brief アイテム凡庸化のメインルーチン処理 /
113  * Identify an object in the inventory (or on the floor)
114  * @param player_ptr プレイヤーへの参照ポインタ
115  * @param only_equip 装備品のみを対象とするならばTRUEを返す
116  * @return 実際に凡庸化をを行ったならばTRUEを返す
117  * @details
118  * <pre>
119  * Mundanify an object in the inventory (or on the floor)
120  * This routine does *not* automatically combine objects.
121  * Returns TRUE if something was mundanified, else FALSE.
122  * </pre>
123  */
124 bool mundane_spell(PlayerType *player_ptr, bool only_equip)
125 {
126     std::unique_ptr<ItemTester> item_tester = std::make_unique<AllMatchItemTester>();
127     if (only_equip) {
128         item_tester = std::make_unique<FuncItemTester>(&ItemEntity::is_weapon_armour_ammo);
129     }
130
131     OBJECT_IDX item;
132     ItemEntity *o_ptr;
133     concptr q = _("どのアイテムを凡庸化しますか?", "Mundanify which item? ");
134     concptr s = _("凡庸化できるアイテムがない。", "You have nothing to mundanify.");
135
136     o_ptr = choose_object(player_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), *item_tester);
137     if (!o_ptr) {
138         return false;
139     }
140
141     msg_print(_("まばゆい閃光が走った!", "There is a bright flash of light!"));
142     POSITION iy = o_ptr->iy;
143     POSITION ix = o_ptr->ix;
144     auto marked = o_ptr->marked;
145     uint16_t inscription = o_ptr->inscription;
146
147     o_ptr->prep(o_ptr->bi_id);
148
149     o_ptr->iy = iy;
150     o_ptr->ix = ix;
151     o_ptr->marked = marked;
152     o_ptr->inscription = inscription;
153
154     calc_android_exp(player_ptr);
155     return true;
156 }