OSDN Git Service

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