OSDN Git Service

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