OSDN Git Service

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