OSDN Git Service

[Refactor] #38862 Moved spells-* to spell/
[hengband/hengband.git] / src / cmd / cmd-zapwand.c
1 #include "system/angband.h"
2 #include "util.h"
3 #include "main/sound-definitions-table.h"
4
5 #include "avatar.h"
6 #include "spell/spells-type.h"
7 #include "spell/spells-status.h"
8 #include "player/player-status.h"
9 #include "player/player-effects.h"
10 #include "player/player-class.h"
11 #include "player-inventory.h"
12 #include "object/object-kind.h"
13 #include "object/object-hook.h"
14 #include "cmd-basic.h"
15 #include "floor/floor.h"
16 #include "targeting.h"
17 #include "view/display-main-window.h"
18 #include "spell/spells2.h"
19 #include "spell/spells3.h"
20
21 /*!
22 * @brief 魔法棒の効果を発動する
23 * @param creature_ptr プレーヤーへの参照ポインタ
24 * @param sval オブジェクトのsval
25 * @param dir 発動の方向ID
26 * @param powerful 強力発動上の処理ならばTRUE
27 * @param magic 魔道具術上の処理ならばTRUE
28 * @return 発動により効果内容が確定したならばTRUEを返す
29 */
30 bool wand_effect(player_type *creature_ptr, OBJECT_SUBTYPE_VALUE sval, DIRECTION dir, bool powerful, bool magic)
31 {
32         bool ident = FALSE;
33         PLAYER_LEVEL lev = powerful ? creature_ptr->lev * 2 : creature_ptr->lev;
34         POSITION rad = powerful ? 3 : 2;
35
36         /* XXX Hack -- Wand of wonder can do anything before it */
37         if (sval == SV_WAND_WONDER)
38         {
39                 int vir = virtue_number(creature_ptr, V_CHANCE);
40                 sval = (OBJECT_SUBTYPE_VALUE)randint0(SV_WAND_WONDER);
41
42                 if (vir)
43                 {
44                         if (creature_ptr->virtues[vir - 1] > 0)
45                         {
46                                 while (randint1(300) < creature_ptr->virtues[vir - 1]) sval++;
47                                 if (sval > SV_WAND_COLD_BALL) sval = randint0(4) + SV_WAND_ACID_BALL;
48                         }
49                         else
50                         {
51                                 while (randint1(300) < (0 - creature_ptr->virtues[vir - 1])) sval--;
52                                 if (sval < SV_WAND_HEAL_MONSTER) sval = randint0(3) + SV_WAND_HEAL_MONSTER;
53                         }
54                 }
55                 if (sval < SV_WAND_TELEPORT_AWAY)
56                         chg_virtue(creature_ptr, V_CHANCE, 1);
57         }
58
59         /* Analyze the wand */
60         switch (sval)
61         {
62                 case SV_WAND_HEAL_MONSTER:
63                 {
64                         HIT_POINT dam = damroll((powerful ? 20 : 10), 10);
65                         if (heal_monster(creature_ptr, dir, dam)) ident = TRUE;
66                         break;
67                 }
68
69                 case SV_WAND_HASTE_MONSTER:
70                 {
71                         if (speed_monster(creature_ptr, dir, lev)) ident = TRUE;
72                         break;
73                 }
74
75                 case SV_WAND_CLONE_MONSTER:
76                 {
77                         if (clone_monster(creature_ptr, dir)) ident = TRUE;
78                         break;
79                 }
80
81                 case SV_WAND_TELEPORT_AWAY:
82                 {
83                         int distance = MAX_SIGHT * (powerful ? 8 : 5);
84                         if (teleport_monster(creature_ptr, dir, distance)) ident = TRUE;
85                         break;
86                 }
87
88                 case SV_WAND_DISARMING:
89                 {
90                         if (disarm_trap(creature_ptr, dir)) ident = TRUE;
91                         if (powerful && disarm_traps_touch(creature_ptr)) ident = TRUE;
92                         break;
93                 }
94
95                 case SV_WAND_TRAP_DOOR_DEST:
96                 {
97                         if (destroy_door(creature_ptr, dir)) ident = TRUE;
98                         if (powerful && destroy_doors_touch(creature_ptr)) ident = TRUE;
99                         break;
100                 }
101
102                 case SV_WAND_STONE_TO_MUD:
103                 {
104                         HIT_POINT dam = powerful ? 40 + randint1(60) : 20 + randint1(30);
105                         if (wall_to_mud(creature_ptr, dir, dam)) ident = TRUE;
106                         break;
107                 }
108
109                 case SV_WAND_LITE:
110                 {
111                         HIT_POINT dam = damroll((powerful ? 12 : 6), 8);
112                         msg_print(_("青く輝く光線が放たれた。", "A line of blue shimmering light appears."));
113                         (void)lite_line(creature_ptr, dir, dam);
114                         ident = TRUE;
115                         break;
116                 }
117
118                 case SV_WAND_SLEEP_MONSTER:
119                 {
120                         if (sleep_monster(creature_ptr, dir, lev)) ident = TRUE;
121                         break;
122                 }
123
124                 case SV_WAND_SLOW_MONSTER:
125                 {
126                         if (slow_monster(creature_ptr, dir, lev)) ident = TRUE;
127                         break;
128                 }
129
130                 case SV_WAND_CONFUSE_MONSTER:
131                 {
132                         if (confuse_monster(creature_ptr, dir, lev)) ident = TRUE;
133                         break;
134                 }
135
136                 case SV_WAND_FEAR_MONSTER:
137                 {
138                         if (fear_monster(creature_ptr, dir, lev)) ident = TRUE;
139                         break;
140                 }
141
142                 case SV_WAND_HYPODYNAMIA:
143                 {
144                         if (hypodynamic_bolt(creature_ptr, dir, 80 + lev)) ident = TRUE;
145                         break;
146                 }
147
148                 case SV_WAND_POLYMORPH:
149                 {
150                         if (poly_monster(creature_ptr, dir, lev)) ident = TRUE;
151                         break;
152                 }
153
154                 case SV_WAND_STINKING_CLOUD:
155                 {
156                         fire_ball(creature_ptr, GF_POIS, dir, 12 + lev / 4, rad);
157                         ident = TRUE;
158                         break;
159                 }
160
161                 case SV_WAND_MAGIC_MISSILE:
162                 {
163                         fire_bolt_or_beam(creature_ptr, 20, GF_MISSILE, dir, damroll(2 + lev / 10, 6));
164                         ident = TRUE;
165                         break;
166                 }
167
168                 case SV_WAND_ACID_BOLT:
169                 {
170                         fire_bolt_or_beam(creature_ptr, 20, GF_ACID, dir, damroll(6 + lev / 7, 8));
171                         ident = TRUE;
172                         break;
173                 }
174
175                 case SV_WAND_CHARM_MONSTER:
176                 {
177                         if (charm_monster(creature_ptr, dir, MAX(20, lev)))
178                                 ident = TRUE;
179                         break;
180                 }
181
182                 case SV_WAND_FIRE_BOLT:
183                 {
184                         fire_bolt_or_beam(creature_ptr, 20, GF_FIRE, dir, damroll(7 + lev / 6, 8));
185                         ident = TRUE;
186                         break;
187                 }
188
189                 case SV_WAND_COLD_BOLT:
190                 {
191                         fire_bolt_or_beam(creature_ptr, 20, GF_COLD, dir, damroll(5 + lev / 8, 8));
192                         ident = TRUE;
193                         break;
194                 }
195
196                 case SV_WAND_ACID_BALL:
197                 {
198                         fire_ball(creature_ptr, GF_ACID, dir, 60 + 3 * lev / 4, rad);
199                         ident = TRUE;
200                         break;
201                 }
202
203                 case SV_WAND_ELEC_BALL:
204                 {
205                         fire_ball(creature_ptr, GF_ELEC, dir, 40 + 3 * lev / 4, rad);
206                         ident = TRUE;
207                         break;
208                 }
209
210                 case SV_WAND_FIRE_BALL:
211                 {
212                         fire_ball(creature_ptr, GF_FIRE, dir, 70 + 3 * lev / 4, rad);
213                         ident = TRUE;
214                         break;
215                 }
216
217                 case SV_WAND_COLD_BALL:
218                 {
219                         fire_ball(creature_ptr, GF_COLD, dir, 50 + 3 * lev / 4, rad);
220                         ident = TRUE;
221                         break;
222                 }
223
224                 case SV_WAND_WONDER:
225                 {
226                         msg_print(_("おっと、謎の魔法棒を始動させた。", "Oops.  Wand of wonder activated."));
227                         break;
228                 }
229
230                 case SV_WAND_DRAGON_FIRE:
231                 {
232                         fire_breath(creature_ptr, GF_FIRE, dir, (powerful ? 300 : 200), 3);
233                         ident = TRUE;
234                         break;
235                 }
236
237                 case SV_WAND_DRAGON_COLD:
238                 {
239                         fire_breath(creature_ptr, GF_COLD, dir, (powerful ? 270 : 180), 3);
240                         ident = TRUE;
241                         break;
242                 }
243
244                 case SV_WAND_DRAGON_BREATH:
245                 {
246                         HIT_POINT dam;
247                         EFFECT_ID typ;
248
249                         switch (randint1(5))
250                         {
251                         case 1:
252                                 dam = 240;
253                                 typ = GF_ACID;
254                                 break;
255                         case 2:
256                                 dam = 210;
257                                 typ = GF_ELEC;
258                                 break;
259                         case 3:
260                                 dam = 240;
261                                 typ = GF_FIRE;
262                                 break;
263                         case 4:
264                                 dam = 210;
265                                 typ = GF_COLD;
266                                 break;
267                         default:
268                                 dam = 180;
269                                 typ = GF_POIS;
270                                 break;
271                         }
272
273                         if (powerful) dam = (dam * 3) / 2;
274
275                         fire_breath(creature_ptr, typ, dir, dam, 3);
276
277                         ident = TRUE;
278                         break;
279                 }
280
281                 case SV_WAND_DISINTEGRATE:
282                 {
283                         fire_ball(creature_ptr, GF_DISINTEGRATE, dir, 200 + randint1(lev * 2), rad);
284                         ident = TRUE;
285                         break;
286                 }
287
288                 case SV_WAND_ROCKETS:
289                 {
290                         msg_print(_("ロケットを発射した!", "You launch a rocket!"));
291                         fire_rocket(creature_ptr, GF_ROCKET, dir, 250 + lev * 3, rad);
292                         ident = TRUE;
293                         break;
294                 }
295
296                 case SV_WAND_STRIKING:
297                 {
298                         fire_bolt(creature_ptr, GF_METEOR, dir, damroll(15 + lev / 3, 13));
299                         ident = TRUE;
300                         break;
301                 }
302
303                 case SV_WAND_GENOCIDE:
304                 {
305                         fire_ball_hide(creature_ptr, GF_GENOCIDE, dir, magic ? lev + 50 : 250, 0);
306                         ident = TRUE;
307                         break;
308                 }
309         }
310         return ident;
311 }
312
313 /*!
314 * @brief 魔法棒を使うコマンドのサブルーチン /
315 * Aim a wand (from the pack or floor).
316 * @param item 使うオブジェクトの所持品ID
317 * @return なし
318 * @details
319 * <pre>
320 * Use a single charge from a single item.
321 * Handle "unstacking" in a logical manner.
322 * For simplicity, you cannot use a stack of items from the
323 * ground.  This would require too much nasty code.
324 * There are no wands which can "destroy" themselves, in the inventory
325 * or on the ground, so we can ignore this possibility.  Note that this
326 * required giving "wand of wonder" the ability to ignore destruction
327 * by electric balls.
328 * All wands can be "cancelled" at the "Direction?" prompt for free.
329 * Note that the basic "bolt" wands do slightly less damage than the
330 * basic "bolt" rods, but the basic "ball" wands do the same damage
331 * as the basic "ball" rods.
332 * </pre>
333 */
334 void exe_aim_wand(player_type *creature_ptr, INVENTORY_IDX item)
335 {
336         DEPTH lev;
337         int ident, chance;
338         DIRECTION dir;
339         object_type *o_ptr;
340         bool old_target_pet = target_pet;
341
342         o_ptr = REF_ITEM(creature_ptr, creature_ptr->current_floor_ptr, item);
343
344         /* Mega-Hack -- refuse to aim a pile from the ground */
345         if ((item < 0) && (o_ptr->number > 1))
346         {
347                 msg_print(_("まずは魔法棒を拾わなければ。", "You must first pick up the wands."));
348                 return;
349         }
350
351
352         /* Allow direction to be cancelled for free */
353         if (object_is_aware(o_ptr) && (o_ptr->sval == SV_WAND_HEAL_MONSTER
354                 || o_ptr->sval == SV_WAND_HASTE_MONSTER))
355                 target_pet = TRUE;
356         if (!get_aim_dir(creature_ptr, &dir))
357         {
358                 target_pet = old_target_pet;
359                 return;
360         }
361         target_pet = old_target_pet;
362
363         take_turn(creature_ptr, 100);
364
365         /* Get the level */
366         lev = k_info[o_ptr->k_idx].level;
367         if (lev > 50) lev = 50 + (lev - 50) / 2;
368
369         /* Base chance of success */
370         chance = creature_ptr->skill_dev;
371
372         /* Confusion hurts skill */
373         if (creature_ptr->confused) chance = chance / 2;
374
375         /* Hight level objects are harder */
376         chance = chance - lev;
377
378         /* Give everyone a (slight) chance */
379         if ((chance < USE_DEVICE) && one_in_(USE_DEVICE - chance + 1))
380         {
381                 chance = USE_DEVICE;
382         }
383
384         if (cmd_limit_time_walk(creature_ptr)) return;
385
386         /* Roll for usage */
387         if ((chance < USE_DEVICE) || (randint1(chance) < USE_DEVICE) || (creature_ptr->pclass == CLASS_BERSERKER))
388         {
389                 if (flush_failure) flush();
390                 msg_print(_("魔法棒をうまく使えなかった。", "You failed to use the wand properly."));
391                 sound(SOUND_FAIL);
392                 return;
393         }
394
395         /* The wand is already empty! */
396         if (o_ptr->pval <= 0)
397         {
398                 if (flush_failure) flush();
399                 msg_print(_("この魔法棒にはもう魔力が残っていない。", "The wand has no charges left."));
400                 o_ptr->ident |= (IDENT_EMPTY);
401                 creature_ptr->update |= (PU_COMBINE | PU_REORDER);
402                 creature_ptr->window |= (PW_INVEN);
403
404                 return;
405         }
406
407         sound(SOUND_ZAP);
408
409         ident = wand_effect(creature_ptr, o_ptr->sval, dir, FALSE, FALSE);
410         
411         /*
412          * Temporarily remove the flags for updating the inventory so
413          * gain_exp() does not reorder the inventory before the charge
414          * is deducted from the wand.
415          */
416         BIT_FLAGS inventory_flags = (PU_COMBINE | PU_REORDER | (creature_ptr->update & PU_AUTODESTROY));
417         creature_ptr->update &= ~(PU_COMBINE | PU_REORDER | PU_AUTODESTROY);
418
419         if (!(object_is_aware(o_ptr)))
420         {
421                 chg_virtue(creature_ptr, V_PATIENCE, -1);
422                 chg_virtue(creature_ptr, V_CHANCE, 1);
423                 chg_virtue(creature_ptr, V_KNOWLEDGE, -1);
424         }
425
426         /* Mark it as tried */
427         object_tried(o_ptr);
428
429         /* Apply identification */
430         if (ident && !object_is_aware(o_ptr))
431         {
432                 object_aware(creature_ptr, o_ptr);
433                 gain_exp(creature_ptr, (lev + (creature_ptr->lev >> 1)) / creature_ptr->lev);
434         }
435
436         creature_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
437         creature_ptr->update |= inventory_flags;
438
439         /* Use a single charge */
440         o_ptr->pval--;
441
442         if (item >= 0)
443         {
444                 inven_item_charges(creature_ptr, item);
445                 return;
446         }
447
448         floor_item_charges(creature_ptr->current_floor_ptr, 0 - item);
449 }
450
451 /*!
452 * @brief 魔法棒を使うコマンドのメインルーチン /
453 * @return なし
454 */
455 void do_cmd_aim_wand(player_type *creature_ptr)
456 {
457         OBJECT_IDX item;
458         concptr q, s;
459
460         if (creature_ptr->wild_mode) return;
461         if (cmd_limit_arena(creature_ptr)) return;
462         if (creature_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
463         {
464                 set_action(creature_ptr, ACTION_NONE);
465         }
466
467         q = _("どの魔法棒で狙いますか? ", "Aim which wand? ");
468         s = _("使える魔法棒がない。", "You have no wand to aim.");
469         if (!choose_object(creature_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), TV_WAND)) return;
470
471         exe_aim_wand(creature_ptr, item);
472 }