OSDN Git Service

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