OSDN Git Service

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