OSDN Git Service

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