OSDN Git Service

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