OSDN Git Service

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