OSDN Git Service

[Refactor] #40413 Changed macro function PRACE_IS_() to is_specific_player_race()
[hengband/hengband.git] / src / cmd-item / cmd-usestaff.c
1 #include "cmd-item/cmd-usestaff.h"
2 #include "cmd/cmd-basic.h"
3 #include "floor/floor-object.h"
4 #include "floor/floor.h"
5 #include "game-option/disturbance-options.h"
6 #include "inventory/inventory-object.h"
7 #include "inventory/player-inventory.h"
8 #include "main/sound-definitions-table.h"
9 #include "monster-floor/monster-summon.h"
10 #include "monster-floor/place-monster-types.h"
11 #include "object-enchant/special-object-flags.h"
12 #include "object/item-use-flags.h"
13 #include "object/object-generator.h"
14 #include "object/object-hook.h"
15 #include "object/object-info.h"
16 #include "object/object-kind.h"
17 #include "perception/object-perception.h"
18 #include "player/avatar.h"
19 #include "player/player-class.h"
20 #include "player/player-effects.h"
21 #include "player/player-races-types.h"
22 #include "player/player-status.h"
23 #include "spell-kind/earthquake.h"
24 #include "spell-kind/spells-detection.h"
25 #include "spell-kind/spells-floor.h"
26 #include "spell-kind/spells-genocide.h"
27 #include "spell-kind/spells-lite.h"
28 #include "spell-kind/spells-neighbor.h"
29 #include "spell-kind/spells-sight.h"
30 #include "spell-kind/spells-teleport.h"
31 #include "spell/spells-staff-only.h"
32 #include "spell/spells-status.h"
33 #include "spell/spells-summon.h"
34 #include "spell/spells3.h"
35 #include "sv-definition/sv-staff-types.h"
36 #include "util/util.h"
37 #include "view/display-main-window.h"
38 #include "view/object-describer.h"
39
40 /*!
41 * @brief 杖の効果を発動する
42 * @param creature_ptr プレーヤーへの参照ポインタ
43 * @param sval オブジェクトのsval
44 * @param use_charge 使用回数を消費したかどうかを返す参照ポインタ
45 * @param powerful 強力発動上の処理ならばTRUE
46 * @param magic 魔道具術上の処理ならばTRUE
47 * @param known 判明済ならばTRUE
48 * @return 発動により効果内容が確定したならばTRUEを返す
49 */
50 int staff_effect(player_type *creature_ptr, OBJECT_SUBTYPE_VALUE sval, bool *use_charge, bool powerful, bool magic, bool known)
51 {
52         int k;
53         int ident = FALSE;
54         PLAYER_LEVEL lev = powerful ? creature_ptr->lev * 2 : creature_ptr->lev;
55         POSITION detect_rad = powerful ? DETECT_RAD_DEFAULT * 3 / 2 : DETECT_RAD_DEFAULT;
56
57         /* Analyze the staff */
58         switch (sval)
59         {
60                 case SV_STAFF_DARKNESS:
61                 {
62                         if (!(creature_ptr->resist_blind) && !(creature_ptr->resist_dark))
63                         {
64                                 if (set_blind(creature_ptr, creature_ptr->blind + 3 + randint1(5))) ident = TRUE;
65                         }
66                         if (unlite_area(creature_ptr, 10, (powerful ? 6 : 3))) ident = TRUE;
67                         break;
68                 }
69
70                 case SV_STAFF_SLOWNESS:
71                 {
72                         if (set_slow(creature_ptr, creature_ptr->slow + randint1(30) + 15, FALSE)) ident = TRUE;
73                         break;
74                 }
75
76                 case SV_STAFF_HASTE_MONSTERS:
77                 {
78                         if (speed_monsters(creature_ptr)) ident = TRUE;
79                         break;
80                 }
81
82                 case SV_STAFF_SUMMONING:
83                 {
84                         const int times = randint1(powerful ? 8 : 4);
85                         for (k = 0; k < times; k++)
86                         {
87                                 if (summon_specific(creature_ptr, 0, creature_ptr->y, creature_ptr->x, creature_ptr->current_floor_ptr->dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
88                                 {
89                                         ident = TRUE;
90                                 }
91                         }
92                         break;
93                 }
94
95                 case SV_STAFF_TELEPORTATION:
96                 {
97                         teleport_player(creature_ptr, (powerful ? 150 : 100), 0L);
98                         ident = TRUE;
99                         break;
100                 }
101
102                 case SV_STAFF_IDENTIFY:
103                 {
104                         if (powerful) {
105                                 if (!identify_fully(creature_ptr, FALSE, 0)) *use_charge = FALSE;
106                         }
107                         else {
108                                 if (!ident_spell(creature_ptr, FALSE, 0)) *use_charge = FALSE;
109                         }
110                         ident = TRUE;
111                         break;
112                 }
113
114                 case SV_STAFF_REMOVE_CURSE:
115                 {
116                         bool result = powerful ? remove_all_curse(creature_ptr) : remove_curse(creature_ptr);
117                         if (result)
118                         {
119                                 ident = TRUE;
120                         }
121                         break;
122                 }
123
124                 case SV_STAFF_STARLITE:
125                         ident = starlight(creature_ptr, magic);
126                         break;
127
128                 case SV_STAFF_LITE:
129                 {
130                         if (lite_area(creature_ptr, damroll(2, 8), (powerful ? 4 : 2))) ident = TRUE;
131                         break;
132                 }
133
134                 case SV_STAFF_MAPPING:
135                 {
136                         map_area(creature_ptr, powerful ? DETECT_RAD_MAP * 3 / 2 : DETECT_RAD_MAP);
137                         ident = TRUE;
138                         break;
139                 }
140
141                 case SV_STAFF_DETECT_GOLD:
142                 {
143                         if (detect_treasure(creature_ptr, detect_rad)) ident = TRUE;
144                         if (detect_objects_gold(creature_ptr, detect_rad)) ident = TRUE;
145                         break;
146                 }
147
148                 case SV_STAFF_DETECT_ITEM:
149                 {
150                         if (detect_objects_normal(creature_ptr, detect_rad)) ident = TRUE;
151                         break;
152                 }
153
154                 case SV_STAFF_DETECT_TRAP:
155                 {
156                         if (detect_traps(creature_ptr, detect_rad, known)) ident = TRUE;
157                         break;
158                 }
159
160                 case SV_STAFF_DETECT_DOOR:
161                 {
162                         if (detect_doors(creature_ptr, detect_rad)) ident = TRUE;
163                         if (detect_stairs(creature_ptr, detect_rad)) ident = TRUE;
164                         break;
165                 }
166
167                 case SV_STAFF_DETECT_INVIS:
168                 {
169                         if (detect_monsters_invis(creature_ptr, detect_rad)) ident = TRUE;
170                         break;
171                 }
172
173                 case SV_STAFF_DETECT_EVIL:
174                 {
175                         if (detect_monsters_evil(creature_ptr, detect_rad)) ident = TRUE;
176                         break;
177                 }
178
179                 case SV_STAFF_CURE_LIGHT:
180                 {
181                         ident = cure_light_wounds(creature_ptr, (powerful ? 4 : 2), 8);
182                         break;
183                 }
184
185                 case SV_STAFF_CURING:
186                 {
187                         ident = true_healing(creature_ptr, 0);
188                         if (set_shero(creature_ptr, 0, TRUE)) ident = TRUE;
189                         break;
190                 }
191
192                 case SV_STAFF_HEALING:
193                 {
194                         if (cure_critical_wounds(creature_ptr, powerful ? 500 : 300)) ident = TRUE;
195                         break;
196                 }
197
198                 case SV_STAFF_THE_MAGI:
199                 {
200                         if (do_res_stat(creature_ptr, A_INT)) ident = TRUE;
201                         ident |= restore_mana(creature_ptr, FALSE);
202                         if (set_shero(creature_ptr, 0, TRUE)) ident = TRUE;
203                         break;
204                 }
205
206                 case SV_STAFF_SLEEP_MONSTERS:
207                 {
208                         if (sleep_monsters(creature_ptr, lev)) ident = TRUE;
209                         break;
210                 }
211
212                 case SV_STAFF_SLOW_MONSTERS:
213                 {
214                         if (slow_monsters(creature_ptr, lev)) ident = TRUE;
215                         break;
216                 }
217
218                 case SV_STAFF_SPEED:
219                 {
220                         if (set_fast(creature_ptr, randint1(30) + (powerful ? 30 : 15), FALSE)) ident = TRUE;
221                         break;
222                 }
223
224                 case SV_STAFF_PROBING:
225                 {
226                         ident = probing(creature_ptr);
227                         break;
228                 }
229
230                 case SV_STAFF_DISPEL_EVIL:
231                 {
232                         ident = dispel_evil(creature_ptr, powerful ? 120 : 80);
233                         break;
234                 }
235
236                 case SV_STAFF_POWER:
237                 {
238                         ident = dispel_monsters(creature_ptr, powerful ? 225 : 150) ;
239                         break;
240                 }
241
242                 case SV_STAFF_HOLINESS:
243                 {
244                         ident = cleansing_nova(creature_ptr, magic, powerful);
245                         break;
246                 }
247
248                 case SV_STAFF_GENOCIDE:
249                 {
250                         ident = symbol_genocide(creature_ptr, (magic ? lev + 50 : 200), TRUE);
251                         break;
252                 }
253
254                 case SV_STAFF_EARTHQUAKES:
255                 {
256                         if (earthquake(creature_ptr, creature_ptr->y, creature_ptr->x, (powerful ? 15 : 10), 0))
257                                 ident = TRUE;
258                         else
259                                 msg_print(_("ダンジョンが揺れた。", "The dungeon trembles."));
260
261                         break;
262                 }
263
264                 case SV_STAFF_DESTRUCTION:
265                 {
266                         ident = destroy_area(creature_ptr, creature_ptr->y, creature_ptr->x, (powerful ? 18 : 13) + randint0(5), FALSE);
267                         break;
268                 }
269
270                 case SV_STAFF_ANIMATE_DEAD:
271                 {
272                         ident = animate_dead(creature_ptr, 0, creature_ptr->y, creature_ptr->x);
273                         break;
274                 }
275
276                 case SV_STAFF_MSTORM:
277                 {
278                         ident = unleash_mana_storm(creature_ptr, powerful);
279                         break;
280                 }
281
282                 case SV_STAFF_NOTHING:
283                 {
284                         msg_print(_("何も起らなかった。", "Nothing happen."));
285                         if (is_specific_player_race(creature_ptr, RACE_SKELETON) || is_specific_player_race(creature_ptr, RACE_GOLEM) ||
286                                 is_specific_player_race(creature_ptr, RACE_ZOMBIE) || is_specific_player_race(creature_ptr, RACE_SPECTRE))
287                                 msg_print(_("もったいない事をしたような気がする。食べ物は大切にしなくては。", "What a waste.  It's your food!"));
288                         break;
289                 }
290         }
291         return ident;
292 }
293
294
295 /*!
296  * @brief 杖を使うコマンドのサブルーチン /
297  * Use a staff.                 -RAK-
298  * @param item 使うオブジェクトの所持品ID
299  * @return なし
300  * @details
301  * One charge of one staff disappears.
302  * Hack -- staffs of identify can be "cancelled".
303  */
304 void exe_use_staff(player_type *creature_ptr, INVENTORY_IDX item)
305 {
306         int         ident, chance, lev;
307         object_type *o_ptr;
308
309                 /* Hack -- let staffs of identify get aborted */
310         bool use_charge = TRUE;
311
312         o_ptr = ref_item(creature_ptr, item);
313
314         /* Mega-Hack -- refuse to use a pile from the ground */
315         if ((item < 0) && (o_ptr->number > 1))
316         {
317                 msg_print(_("まずは杖を拾わなければ。", "You must first pick up the staffs."));
318                 return;
319         }
320
321                 take_turn(creature_ptr, 100);
322
323         lev = k_info[o_ptr->k_idx].level;
324         if (lev > 50) lev = 50 + (lev - 50) / 2;
325
326         /* Base chance of success */
327         chance = creature_ptr->skill_dev;
328
329         /* Confusion hurts skill */
330         if (creature_ptr->confused) chance = chance / 2;
331
332         /* Hight level objects are harder */
333         chance = chance - lev;
334
335         /* Give everyone a (slight) chance */
336         if ((chance < USE_DEVICE) && one_in_(USE_DEVICE - chance + 1))
337         {
338                 chance = USE_DEVICE;
339         }
340
341         if (cmd_limit_time_walk(creature_ptr)) return;
342
343         /* Roll for usage */
344         if ((chance < USE_DEVICE) || (randint1(chance) < USE_DEVICE) || (creature_ptr->pclass == CLASS_BERSERKER))
345         {
346                 if (flush_failure) flush();
347                 msg_print(_("杖をうまく使えなかった。", "You failed to use the staff properly."));
348                 sound(SOUND_FAIL);
349                 return;
350         }
351
352         /* Notice empty staffs */
353         if (o_ptr->pval <= 0)
354         {
355                 if (flush_failure) flush();
356                 msg_print(_("この杖にはもう魔力が残っていない。", "The staff has no charges left."));
357                 o_ptr->ident |= (IDENT_EMPTY);
358                 creature_ptr->update |= (PU_COMBINE | PU_REORDER);
359                 creature_ptr->window |= (PW_INVEN);
360
361                 return;
362         }
363
364         sound(SOUND_ZAP);
365
366         ident = staff_effect(creature_ptr, o_ptr->sval, &use_charge, FALSE, FALSE, object_is_aware(o_ptr));
367
368         if (!(object_is_aware(o_ptr)))
369         {
370                 chg_virtue(creature_ptr, V_PATIENCE, -1);
371                 chg_virtue(creature_ptr, V_CHANCE, 1);
372                 chg_virtue(creature_ptr, V_KNOWLEDGE, -1);
373         }
374
375         /*
376          * Temporarily remove the flags for updating the inventory so
377          * gain_exp() does not reorder the inventory before the charge
378          * is deducted from the staff.
379          */
380         BIT_FLAGS inventory_flags = (PU_COMBINE | PU_REORDER | (creature_ptr->update & PU_AUTODESTROY));
381         creature_ptr->update &= ~(PU_COMBINE | PU_REORDER | PU_AUTODESTROY);
382
383         /* Tried the item */
384         object_tried(o_ptr);
385
386         /* An identification was made */
387         if (ident && !object_is_aware(o_ptr))
388         {
389                 object_aware(creature_ptr, o_ptr);
390                 gain_exp(creature_ptr, (lev + (creature_ptr->lev >> 1)) / creature_ptr->lev);
391         }
392
393         creature_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
394         creature_ptr->update |= inventory_flags;
395
396         /* Hack -- some uses are "free" */
397         if (!use_charge) return;
398
399
400         /* Use a single charge */
401         o_ptr->pval--;
402
403         /* XXX Hack -- unstack if necessary */
404         if ((item >= 0) && (o_ptr->number > 1))
405         {
406                 object_type forge;
407                 object_type *q_ptr;
408                 q_ptr = &forge;
409                 object_copy(q_ptr, o_ptr);
410
411                 /* Modify quantity */
412                 q_ptr->number = 1;
413
414                 /* Restore the charges */
415                 o_ptr->pval++;
416
417                 /* Unstack the used item */
418                 o_ptr->number--;
419                 creature_ptr->total_weight -= q_ptr->weight;
420                 item = store_item_to_inventory(creature_ptr, q_ptr);
421
422                 msg_print(_("杖をまとめなおした。", "You unstack your staff."));
423         }
424
425         /* Describe charges in the pack */
426         if (item >= 0)
427         {
428                 inven_item_charges(creature_ptr, item);
429         }
430
431         /* Describe charges on the floor */
432         else
433         {
434                 floor_item_charges(creature_ptr->current_floor_ptr, 0 - item);
435         }
436 }
437
438
439 /*!
440 * @brief 杖を使うコマンドのメインルーチン /
441 * @return なし
442 */
443 void do_cmd_use_staff(player_type *creature_ptr)
444 {
445         OBJECT_IDX item;
446         concptr q, s;
447
448         if (creature_ptr->wild_mode)
449         {
450                 return;
451         }
452
453         if (cmd_limit_arena(creature_ptr)) return;
454
455         if (creature_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
456         {
457                 set_action(creature_ptr, ACTION_NONE);
458         }
459
460         q = _("どの杖を使いますか? ", "Use which staff? ");
461         s = _("使える杖がない。", "You have no staff to use.");
462         if (!choose_object(creature_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), TV_STAFF)) return;
463
464         exe_use_staff(creature_ptr, item);
465 }