OSDN Git Service

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