OSDN Git Service

Merge pull request #3192 from Hourier/Divide-IsAutopickMatch
[hengbandforosx/hengbandosx.git] / src / spell-realm / spells-craft.cpp
1 #include "spell-realm/spells-craft.h"
2 #include "avatar/avatar.h"
3 #include "core/disturbance.h"
4 #include "core/player-redraw-types.h"
5 #include "core/player-update-types.h"
6 #include "core/stuff-handler.h"
7 #include "flavor/flavor-describer.h"
8 #include "flavor/object-flavor-types.h"
9 #include "floor/floor-object.h"
10 #include "game-option/disturbance-options.h"
11 #include "inventory/inventory-slot-types.h"
12 #include "io/input-key-acceptor.h"
13 #include "object-enchant/object-ego.h"
14 #include "object/item-use-flags.h"
15 #include "object/object-flags.h"
16 #include "player-info/equipment-info.h"
17 #include "player/attack-defense-types.h"
18 #include "player/special-defense-types.h"
19 #include "racial/racial-android.h"
20 #include "spell/spells-object.h"
21 #include "sv-definition/sv-protector-types.h"
22 #include "system/item-entity.h"
23 #include "system/player-type-definition.h"
24 #include "term/screen-processor.h"
25 #include "term/term-color-types.h"
26 #include "view/display-messages.h"
27
28 /*!
29  * @brief 一時的元素スレイの継続時間をセットする / Set a temporary elemental brand. Clear all other brands. Print status messages. -LM-
30  * @param attack_type スレイのタイプID
31  * @param v 継続時間
32  * @return ステータスに影響を及ぼす変化があった場合TRUEを返す。
33  */
34 bool set_ele_attack(PlayerType *player_ptr, uint32_t attack_type, TIME_EFFECT v)
35 {
36     v = (v > 10000) ? 10000 : (v < 0) ? 0
37                                       : v;
38
39     if ((player_ptr->special_attack & (ATTACK_ACID)) && (attack_type != ATTACK_ACID)) {
40         player_ptr->special_attack &= ~(ATTACK_ACID);
41         msg_print(_("酸で攻撃できなくなった。", "Your temporary acidic brand fades away."));
42     }
43
44     if ((player_ptr->special_attack & (ATTACK_ELEC)) && (attack_type != ATTACK_ELEC)) {
45         player_ptr->special_attack &= ~(ATTACK_ELEC);
46         msg_print(_("電撃で攻撃できなくなった。", "Your temporary electrical brand fades away."));
47     }
48
49     if ((player_ptr->special_attack & (ATTACK_FIRE)) && (attack_type != ATTACK_FIRE)) {
50         player_ptr->special_attack &= ~(ATTACK_FIRE);
51         msg_print(_("火炎で攻撃できなくなった。", "Your temporary fiery brand fades away."));
52     }
53
54     if ((player_ptr->special_attack & (ATTACK_COLD)) && (attack_type != ATTACK_COLD)) {
55         player_ptr->special_attack &= ~(ATTACK_COLD);
56         msg_print(_("冷気で攻撃できなくなった。", "Your temporary frost brand fades away."));
57     }
58
59     if ((player_ptr->special_attack & (ATTACK_POIS)) && (attack_type != ATTACK_POIS)) {
60         player_ptr->special_attack &= ~(ATTACK_POIS);
61         msg_print(_("毒で攻撃できなくなった。", "Your temporary poison brand fades away."));
62     }
63
64     if ((v) && (attack_type)) {
65         player_ptr->special_attack |= (attack_type);
66         player_ptr->ele_attack = v;
67 #ifdef JP
68         msg_format("%sで攻撃できるようになった!",
69             ((attack_type == ATTACK_ACID)
70                     ? "酸"
71                     : ((attack_type == ATTACK_ELEC)
72                               ? "電撃"
73                               : ((attack_type == ATTACK_FIRE) ? "火炎"
74                                                               : ((attack_type == ATTACK_COLD) ? "冷気" : ((attack_type == ATTACK_POIS) ? "毒" : "(なし)"))))));
75 #else
76         msg_format("For a while, the blows you deal will %s",
77             ((attack_type == ATTACK_ACID)
78                     ? "melt with acid!"
79                     : ((attack_type == ATTACK_ELEC)
80                               ? "shock your foes!"
81                               : ((attack_type == ATTACK_FIRE)
82                                         ? "burn with fire!"
83                                         : ((attack_type == ATTACK_COLD) ? "chill to the bone!"
84                                                                         : ((attack_type == ATTACK_POIS) ? "poison your enemies!" : "do nothing special."))))));
85 #endif
86     }
87
88     if (disturb_state) {
89         disturb(player_ptr, false, false);
90     }
91     player_ptr->redraw |= (PR_STATUS);
92     player_ptr->update |= (PU_BONUS);
93     handle_stuff(player_ptr);
94
95     return true;
96 }
97
98 /*!
99  * @brief 一時的元素免疫の継続時間をセットする / Set a temporary elemental brand.  Clear all other brands.  Print status messages. -LM-
100  * @param immune_type 免疫のタイプID
101  * @param v 継続時間
102  * @return ステータスに影響を及ぼす変化があった場合TRUEを返す。
103  */
104 bool set_ele_immune(PlayerType *player_ptr, uint32_t immune_type, TIME_EFFECT v)
105 {
106     v = (v > 10000) ? 10000 : (v < 0) ? 0
107                                       : v;
108
109     if ((player_ptr->special_defense & (DEFENSE_ACID)) && (immune_type != DEFENSE_ACID)) {
110         player_ptr->special_defense &= ~(DEFENSE_ACID);
111         msg_print(_("酸の攻撃で傷つけられるようになった。。", "You are no longer immune to acid."));
112     }
113
114     if ((player_ptr->special_defense & (DEFENSE_ELEC)) && (immune_type != DEFENSE_ELEC)) {
115         player_ptr->special_defense &= ~(DEFENSE_ELEC);
116         msg_print(_("電撃の攻撃で傷つけられるようになった。。", "You are no longer immune to electricity."));
117     }
118
119     if ((player_ptr->special_defense & (DEFENSE_FIRE)) && (immune_type != DEFENSE_FIRE)) {
120         player_ptr->special_defense &= ~(DEFENSE_FIRE);
121         msg_print(_("火炎の攻撃で傷つけられるようになった。。", "You are no longer immune to fire."));
122     }
123
124     if ((player_ptr->special_defense & (DEFENSE_COLD)) && (immune_type != DEFENSE_COLD)) {
125         player_ptr->special_defense &= ~(DEFENSE_COLD);
126         msg_print(_("冷気の攻撃で傷つけられるようになった。。", "You are no longer immune to cold."));
127     }
128
129     if ((player_ptr->special_defense & (DEFENSE_POIS)) && (immune_type != DEFENSE_POIS)) {
130         player_ptr->special_defense &= ~(DEFENSE_POIS);
131         msg_print(_("毒の攻撃で傷つけられるようになった。。", "You are no longer immune to poison."));
132     }
133
134     if ((v) && (immune_type)) {
135         player_ptr->special_defense |= (immune_type);
136         player_ptr->ele_immune = v;
137         msg_format(_("%sの攻撃を受けつけなくなった!", "For a while, you are immune to %s"),
138             ((immune_type == DEFENSE_ACID)
139                     ? _("酸", "acid!")
140                     : ((immune_type == DEFENSE_ELEC)
141                               ? _("電撃", "electricity!")
142                               : ((immune_type == DEFENSE_FIRE)
143                                         ? _("火炎", "fire!")
144                                         : ((immune_type == DEFENSE_COLD)
145                                                   ? _("冷気", "cold!")
146                                                   : ((immune_type == DEFENSE_POIS) ? _("毒", "poison!") : _("(なし)", "nothing special.")))))));
147     }
148
149     if (disturb_state) {
150         disturb(player_ptr, false, false);
151     }
152     player_ptr->redraw |= (PR_STATUS);
153     player_ptr->update |= (PU_BONUS);
154     handle_stuff(player_ptr);
155
156     return true;
157 }
158
159 /*
160  * Choose a warrior-mage elemental attack. -LM-
161  */
162 bool choose_ele_attack(PlayerType *player_ptr)
163 {
164     if (!has_melee_weapon(player_ptr, INVEN_MAIN_HAND) && !has_melee_weapon(player_ptr, INVEN_SUB_HAND)) {
165         msg_format(_("武器を持たないと魔法剣は使えない。", "You cannot use temporary branding with no weapon."));
166         return false;
167     }
168
169     screen_save();
170     int num = (player_ptr->lev - 20) / 5;
171     c_prt(TERM_RED, _("        a) 焼棄", "        a) Fire Brand"), 2, 14);
172
173     if (num >= 2) {
174         c_prt(TERM_L_WHITE, _("        b) 凍結", "        b) Cold Brand"), 3, 14);
175     } else {
176         prt("", 3, 14);
177     }
178
179     if (num >= 3) {
180         c_prt(TERM_GREEN, _("        c) 毒殺", "        c) Poison Brand"), 4, 14);
181     } else {
182         prt("", 4, 14);
183     }
184
185     if (num >= 4) {
186         c_prt(TERM_L_DARK, _("        d) 溶解", "        d) Acid Brand"), 5, 14);
187     } else {
188         prt("", 5, 14);
189     }
190
191     if (num >= 5) {
192         c_prt(TERM_BLUE, _("        e) 電撃", "        e) Elec Brand"), 6, 14);
193     } else {
194         prt("", 6, 14);
195     }
196
197     prt("", 7, 14);
198     prt("", 8, 14);
199     prt("", 9, 14);
200
201     prt("", 1, 0);
202     prt(_("        どの元素攻撃をしますか?", "        Choose a temporary elemental brand "), 1, 14);
203
204     char choice = inkey();
205
206     if ((choice == 'a') || (choice == 'A')) {
207         set_ele_attack(player_ptr, ATTACK_FIRE, player_ptr->lev / 2 + randint1(player_ptr->lev / 2));
208     } else if (((choice == 'b') || (choice == 'B')) && (num >= 2)) {
209         set_ele_attack(player_ptr, ATTACK_COLD, player_ptr->lev / 2 + randint1(player_ptr->lev / 2));
210     } else if (((choice == 'c') || (choice == 'C')) && (num >= 3)) {
211         set_ele_attack(player_ptr, ATTACK_POIS, player_ptr->lev / 2 + randint1(player_ptr->lev / 2));
212     } else if (((choice == 'd') || (choice == 'D')) && (num >= 4)) {
213         set_ele_attack(player_ptr, ATTACK_ACID, player_ptr->lev / 2 + randint1(player_ptr->lev / 2));
214     } else if (((choice == 'e') || (choice == 'E')) && (num >= 5)) {
215         set_ele_attack(player_ptr, ATTACK_ELEC, player_ptr->lev / 2 + randint1(player_ptr->lev / 2));
216     } else {
217         msg_print(_("魔法剣を使うのをやめた。", "You cancel the temporary branding."));
218         screen_load();
219         return false;
220     }
221
222     screen_load();
223     return true;
224 }
225 /*
226  * Choose a elemental immune. -LM-
227  */
228 bool choose_ele_immune(PlayerType *player_ptr, TIME_EFFECT immune_turn)
229 {
230     screen_save();
231
232     c_prt(TERM_RED, _("        a) 火炎", "        a) Immunity to fire"), 2, 14);
233     c_prt(TERM_L_WHITE, _("        b) 冷気", "        b) Immunity to cold"), 3, 14);
234     c_prt(TERM_L_DARK, _("        c) 酸", "        c) Immunity to acid"), 4, 14);
235     c_prt(TERM_BLUE, _("        d) 電撃", "        d) Immunity to elec"), 5, 14);
236
237     prt("", 6, 14);
238     prt("", 7, 14);
239     prt("", 8, 14);
240     prt("", 9, 14);
241
242     prt("", 1, 0);
243     prt(_("        どの元素の免疫をつけますか?", "        Choose a temporary elemental immunity "), 1, 14);
244
245     char choice = inkey();
246
247     if ((choice == 'a') || (choice == 'A')) {
248         set_ele_immune(player_ptr, DEFENSE_FIRE, immune_turn);
249     } else if ((choice == 'b') || (choice == 'B')) {
250         set_ele_immune(player_ptr, DEFENSE_COLD, immune_turn);
251     } else if ((choice == 'c') || (choice == 'C')) {
252         set_ele_immune(player_ptr, DEFENSE_ACID, immune_turn);
253     } else if ((choice == 'd') || (choice == 'D')) {
254         set_ele_immune(player_ptr, DEFENSE_ELEC, immune_turn);
255     } else {
256         msg_print(_("免疫を付けるのをやめた。", "You cancel the temporary immunity."));
257         screen_load();
258         return false;
259     }
260
261     screen_load();
262     return true;
263 }
264
265 /*!
266  * @brief 盾磨き処理 /
267  * pulish shield
268  * @return ターン消費を要する処理を行ったならばTRUEを返す
269  */
270 bool pulish_shield(PlayerType *player_ptr)
271 {
272     const auto q = _("どの盾を磨きますか?", "Polish which shield? ");
273     const auto s = _("磨く盾がありません。", "You have no shield to polish.");
274     const auto options = USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT;
275     short item;
276     auto *o_ptr = choose_object(player_ptr, &item, q, s, options, TvalItemTester(ItemKindType::SHIELD));
277     if (o_ptr == nullptr) {
278         return false;
279     }
280
281     const auto item_name = describe_flavor(player_ptr, o_ptr, OD_OMIT_PREFIX | OD_NAME_ONLY);
282     auto is_pulish_successful = o_ptr->is_valid() && !o_ptr->is_fixed_or_random_artifact() && !o_ptr->is_ego();
283     is_pulish_successful &= !o_ptr->is_cursed();
284     is_pulish_successful &= (o_ptr->bi_key.sval() != SV_MIRROR_SHIELD);
285     if (is_pulish_successful) {
286 #ifdef JP
287         msg_format("%sは輝いた!", item_name.data());
288 #else
289         msg_format("%s %s shine%s!", ((item >= 0) ? "Your" : "The"), item_name.data(), ((o_ptr->number > 1) ? "" : "s"));
290 #endif
291         o_ptr->ego_idx = EgoType::REFLECTION;
292         enchant_equipment(player_ptr, o_ptr, randint0(3) + 4, ENCH_TOAC);
293         o_ptr->discount = 99;
294         chg_virtue(player_ptr, Virtue::ENCHANT, 2);
295         return true;
296     }
297
298     if (flush_failure) {
299         flush();
300     }
301
302     msg_print(_("失敗した。", "Failed."));
303     chg_virtue(player_ptr, Virtue::ENCHANT, -2);
304     calc_android_exp(player_ptr);
305     return false;
306 }