OSDN Git Service

[Refactor] enum classの型名変更 PlayerRaceFood -> PlayerRaceFoodType
[hengbandforosx/hengbandosx.git] / src / cmd-item / cmd-usestaff.cpp
1 #include "cmd-item/cmd-usestaff.h"
2 #include "action/action-limited.h"
3 #include "floor/floor-object.h"
4 #include "monster-floor/monster-summon.h"
5 #include "monster-floor/place-monster-types.h"
6 #include "object-use/use-execution.h"
7 #include "object/item-tester-hooker.h"
8 #include "object/item-use-flags.h"
9 #include "player-base/player-class.h"
10 #include "player-base/player-race.h"
11 #include "player-info/class-info.h"
12 #include "player-info/race-info.h"
13 #include "player-info/race-types.h"
14 #include "player-info/samurai-data-type.h"
15 #include "player/attack-defense-types.h"
16 #include "player/player-status-flags.h"
17 #include "player/special-defense-types.h"
18 #include "spell-kind/earthquake.h"
19 #include "spell-kind/spells-curse-removal.h"
20 #include "spell-kind/spells-detection.h"
21 #include "spell-kind/spells-floor.h"
22 #include "spell-kind/spells-genocide.h"
23 #include "spell-kind/spells-lite.h"
24 #include "spell-kind/spells-neighbor.h"
25 #include "spell-kind/spells-perception.h"
26 #include "spell-kind/spells-sight.h"
27 #include "spell-kind/spells-teleport.h"
28 #include "spell/spells-staff-only.h"
29 #include "spell/spells-status.h"
30 #include "spell/spells-summon.h"
31 #include "spell/summon-types.h"
32 #include "status/action-setter.h"
33 #include "status/bad-status-setter.h"
34 #include "status/base-status.h"
35 #include "status/buff-setter.h"
36 #include "status/shape-changer.h"
37 #include "status/sight-setter.h"
38 #include "sv-definition/sv-staff-types.h"
39 #include "system/floor-type-definition.h"
40 #include "system/player-type-definition.h"
41 #include "view/display-messages.h"
42
43 /*!
44  * @brief 杖の効果を発動する
45  * @param player_ptr プレイヤーへの参照ポインタ
46  * @param sval オブジェクトのsval
47  * @param use_charge 使用回数を消費したかどうかを返す参照ポインタ
48  * @param powerful 強力発動上の処理ならばTRUE
49  * @param magic 魔道具術上の処理ならばTRUE
50  * @param known 判明済ならばTRUE
51  * @return 発動により効果内容が確定したならばTRUEを返す
52  */
53 int staff_effect(player_type *player_ptr, OBJECT_SUBTYPE_VALUE sval, bool *use_charge, bool powerful, bool magic, bool known)
54 {
55     int k;
56     bool ident = false;
57     PLAYER_LEVEL lev = powerful ? player_ptr->lev * 2 : player_ptr->lev;
58     POSITION detect_rad = powerful ? DETECT_RAD_DEFAULT * 3 / 2 : DETECT_RAD_DEFAULT;
59
60     BadStatusSetter bss(player_ptr);
61     switch (sval) {
62     case SV_STAFF_DARKNESS:
63         if (!has_resist_blind(player_ptr) && !has_resist_dark(player_ptr)) {
64             if (bss.mod_blindness(3 + randint1(5))) {
65                 ident = true;
66             }
67         }
68
69         if (unlite_area(player_ptr, 10, (powerful ? 6 : 3))) {
70             ident = true;
71         }
72
73         break;
74     case SV_STAFF_SLOWNESS: {
75         if (bss.mod_slowness(randint1(30) + 15, false))
76             ident = true;
77         break;
78     }
79
80     case SV_STAFF_HASTE_MONSTERS: {
81         if (speed_monsters(player_ptr))
82             ident = true;
83         break;
84     }
85
86     case SV_STAFF_SUMMONING: {
87         const int times = randint1(powerful ? 8 : 4);
88         for (k = 0; k < times; k++) {
89             if (summon_specific(player_ptr, 0, player_ptr->y, player_ptr->x, player_ptr->current_floor_ptr->dun_level, SUMMON_NONE,
90                     (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET))) {
91                 ident = true;
92             }
93         }
94         break;
95     }
96
97     case SV_STAFF_TELEPORTATION: {
98         teleport_player(player_ptr, (powerful ? 150 : 100), 0L);
99         ident = true;
100         break;
101     }
102
103     case SV_STAFF_IDENTIFY: {
104         if (powerful) {
105             if (!identify_fully(player_ptr, false))
106                 *use_charge = false;
107         } else {
108             if (!ident_spell(player_ptr, false))
109                 *use_charge = false;
110         }
111         ident = true;
112         break;
113     }
114
115     case SV_STAFF_REMOVE_CURSE: {
116         bool result = (powerful ? remove_all_curse(player_ptr) : remove_curse(player_ptr)) != 0;
117         if (result) {
118             ident = true;
119         }
120         break;
121     }
122
123     case SV_STAFF_STARLITE:
124         ident = starlight(player_ptr, magic);
125         break;
126
127     case SV_STAFF_LITE: {
128         if (lite_area(player_ptr, damroll(2, 8), (powerful ? 4 : 2)))
129             ident = true;
130         break;
131     }
132
133     case SV_STAFF_MAPPING: {
134         map_area(player_ptr, powerful ? DETECT_RAD_MAP * 3 / 2 : DETECT_RAD_MAP);
135         ident = true;
136         break;
137     }
138
139     case SV_STAFF_DETECT_GOLD: {
140         if (detect_treasure(player_ptr, detect_rad))
141             ident = true;
142         if (detect_objects_gold(player_ptr, detect_rad))
143             ident = true;
144         break;
145     }
146
147     case SV_STAFF_DETECT_ITEM: {
148         if (detect_objects_normal(player_ptr, detect_rad))
149             ident = true;
150         break;
151     }
152
153     case SV_STAFF_DETECT_TRAP: {
154         if (detect_traps(player_ptr, detect_rad, known))
155             ident = true;
156         break;
157     }
158
159     case SV_STAFF_DETECT_DOOR: {
160         if (detect_doors(player_ptr, detect_rad))
161             ident = true;
162         if (detect_stairs(player_ptr, detect_rad))
163             ident = true;
164         break;
165     }
166
167     case SV_STAFF_DETECT_INVIS: {
168         if (set_tim_invis(player_ptr, player_ptr->tim_invis + 12 + randint1(12), false))
169             ident = true;
170         break;
171     }
172
173     case SV_STAFF_DETECT_EVIL: {
174         if (detect_monsters_evil(player_ptr, detect_rad))
175             ident = true;
176         break;
177     }
178
179     case SV_STAFF_CURE_LIGHT: {
180         ident = cure_light_wounds(player_ptr, (powerful ? 4 : 2), 8);
181         break;
182     }
183
184     case SV_STAFF_CURING: {
185         ident = true_healing(player_ptr, 0);
186         if (set_shero(player_ptr, 0, true))
187             ident = true;
188         break;
189     }
190
191     case SV_STAFF_HEALING: {
192         if (cure_critical_wounds(player_ptr, powerful ? 500 : 300))
193             ident = true;
194         break;
195     }
196
197     case SV_STAFF_THE_MAGI: {
198         if (do_res_stat(player_ptr, A_INT))
199             ident = true;
200         ident |= restore_mana(player_ptr, false);
201         if (set_shero(player_ptr, 0, true))
202             ident = true;
203         break;
204     }
205
206     case SV_STAFF_SLEEP_MONSTERS: {
207         if (sleep_monsters(player_ptr, lev))
208             ident = true;
209         break;
210     }
211
212     case SV_STAFF_SLOW_MONSTERS: {
213         if (slow_monsters(player_ptr, lev))
214             ident = true;
215         break;
216     }
217
218     case SV_STAFF_SPEED: {
219         if (set_fast(player_ptr, randint1(30) + (powerful ? 30 : 15), false))
220             ident = true;
221         break;
222     }
223
224     case SV_STAFF_PROBING: {
225         ident = probing(player_ptr);
226         break;
227     }
228
229     case SV_STAFF_DISPEL_EVIL: {
230         ident = dispel_evil(player_ptr, powerful ? 120 : 80);
231         break;
232     }
233
234     case SV_STAFF_POWER: {
235         ident = dispel_monsters(player_ptr, powerful ? 225 : 150);
236         break;
237     }
238
239     case SV_STAFF_HOLINESS: {
240         ident = cleansing_nova(player_ptr, magic, powerful);
241         break;
242     }
243
244     case SV_STAFF_GENOCIDE: {
245         ident = symbol_genocide(player_ptr, (magic ? lev + 50 : 200), true);
246         break;
247     }
248
249     case SV_STAFF_EARTHQUAKES: {
250         if (earthquake(player_ptr, player_ptr->y, player_ptr->x, (powerful ? 15 : 10), 0))
251             ident = true;
252         else
253             msg_print(_("ダンジョンが揺れた。", "The dungeon trembles."));
254
255         break;
256     }
257
258     case SV_STAFF_DESTRUCTION: {
259         ident = destroy_area(player_ptr, player_ptr->y, player_ptr->x, (powerful ? 18 : 13) + randint0(5), false);
260         break;
261     }
262
263     case SV_STAFF_ANIMATE_DEAD: {
264         ident = animate_dead(player_ptr, 0, player_ptr->y, player_ptr->x);
265         break;
266     }
267
268     case SV_STAFF_MSTORM: {
269         ident = unleash_mana_storm(player_ptr, powerful);
270         break;
271     }
272
273     case SV_STAFF_NOTHING: {
274         msg_print(_("何も起らなかった。", "Nothing happens."));
275         if (PlayerRace(player_ptr).food() == PlayerRaceFoodType::MANA)
276             msg_print(_("もったいない事をしたような気がする。食べ物は大切にしなくては。", "What a waste.  It's your food!"));
277         break;
278     }
279     }
280     return ident;
281 }
282
283 /*!
284  * @brief 杖を使うコマンドのメインルーチン /
285  */
286 void do_cmd_use_staff(player_type *player_ptr)
287 {
288     OBJECT_IDX item;
289     concptr q, s;
290
291     if (player_ptr->wild_mode) {
292         return;
293     }
294
295     if (cmd_limit_arena(player_ptr))
296         return;
297
298     PlayerClass(player_ptr).break_samurai_stance({ SamuraiStanceType::MUSOU, SamuraiStanceType::KOUKIJIN });
299
300     q = _("どの杖を使いますか? ", "Use which staff? ");
301     s = _("使える杖がない。", "You have no staff to use.");
302     if (!choose_object(player_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), TvalItemTester(ItemKindType::STAFF)))
303         return;
304
305     ObjectUseEntity(player_ptr, item).execute();
306 }