OSDN Git Service

[Refactor] #38844 current_floor_ptr を player_type 構造体に加え, max_o_idx, max_m_idx を...
[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 sval オブジェクトのsval
21 * @param dir 発動の方向ID
22 * @param powerful 強力発動上の処理ならばTRUE
23 * @param magic 魔道具術上の処理ならばTRUE
24 * @return 発動により効果内容が確定したならばTRUEを返す
25 */
26 bool wand_effect(player_type *creature_ptr, OBJECT_SUBTYPE_VALUE sval, DIRECTION dir, bool powerful, bool magic)
27 {
28         bool ident = FALSE;
29         PLAYER_LEVEL lev = powerful ? creature_ptr->lev * 2 : creature_ptr->lev;
30         POSITION rad = powerful ? 3 : 2;
31
32         /* XXX Hack -- Wand of wonder can do anything before it */
33         if (sval == SV_WAND_WONDER)
34         {
35                 int vir = virtue_number(creature_ptr, V_CHANCE);
36                 sval = (OBJECT_SUBTYPE_VALUE)randint0(SV_WAND_WONDER);
37
38                 if (vir)
39                 {
40                         if (creature_ptr->virtues[vir - 1] > 0)
41                         {
42                                 while (randint1(300) < creature_ptr->virtues[vir - 1]) sval++;
43                                 if (sval > SV_WAND_COLD_BALL) sval = randint0(4) + SV_WAND_ACID_BALL;
44                         }
45                         else
46                         {
47                                 while (randint1(300) < (0 - creature_ptr->virtues[vir - 1])) sval--;
48                                 if (sval < SV_WAND_HEAL_MONSTER) sval = randint0(3) + SV_WAND_HEAL_MONSTER;
49                         }
50                 }
51                 if (sval < SV_WAND_TELEPORT_AWAY)
52                         chg_virtue(creature_ptr, V_CHANCE, 1);
53         }
54
55         /* Analyze the wand */
56         switch (sval)
57         {
58                 case SV_WAND_HEAL_MONSTER:
59                 {
60                         HIT_POINT dam = damroll((powerful ? 20 : 10), 10);
61                         if (heal_monster(dir, dam)) ident = TRUE;
62                         break;
63                 }
64
65                 case SV_WAND_HASTE_MONSTER:
66                 {
67                         if (speed_monster(dir, lev)) ident = TRUE;
68                         break;
69                 }
70
71                 case SV_WAND_CLONE_MONSTER:
72                 {
73                         if (clone_monster(dir)) ident = TRUE;
74                         break;
75                 }
76
77                 case SV_WAND_TELEPORT_AWAY:
78                 {
79                         int distance = MAX_SIGHT * (powerful ? 8 : 5);
80                         if (teleport_monster(dir, distance)) ident = TRUE;
81                         break;
82                 }
83
84                 case SV_WAND_DISARMING:
85                 {
86                         if (disarm_trap(dir)) ident = TRUE;
87                         if (powerful && disarm_traps_touch()) ident = TRUE;
88                         break;
89                 }
90
91                 case SV_WAND_TRAP_DOOR_DEST:
92                 {
93                         if (destroy_door(dir)) ident = TRUE;
94                         if (powerful && destroy_doors_touch()) ident = TRUE;
95                         break;
96                 }
97
98                 case SV_WAND_STONE_TO_MUD:
99                 {
100                         HIT_POINT dam = powerful ? 40 + randint1(60) : 20 + randint1(30);
101                         if (wall_to_mud(dir, dam)) ident = TRUE;
102                         break;
103                 }
104
105                 case SV_WAND_LITE:
106                 {
107                         HIT_POINT dam = damroll((powerful ? 12 : 6), 8);
108                         msg_print(_("青く輝く光線が放たれた。", "A line of blue shimmering light appears."));
109                         (void)lite_line(dir, dam);
110                         ident = TRUE;
111                         break;
112                 }
113
114                 case SV_WAND_SLEEP_MONSTER:
115                 {
116                         if (sleep_monster(dir, lev)) ident = TRUE;
117                         break;
118                 }
119
120                 case SV_WAND_SLOW_MONSTER:
121                 {
122                         if (slow_monster(dir, lev)) ident = TRUE;
123                         break;
124                 }
125
126                 case SV_WAND_CONFUSE_MONSTER:
127                 {
128                         if (confuse_monster(dir, lev)) ident = TRUE;
129                         break;
130                 }
131
132                 case SV_WAND_FEAR_MONSTER:
133                 {
134                         if (fear_monster(dir, lev)) ident = TRUE;
135                         break;
136                 }
137
138                 case SV_WAND_HYPODYNAMIA:
139                 {
140                         if (hypodynamic_bolt(dir, 80 + lev)) ident = TRUE;
141                         break;
142                 }
143
144                 case SV_WAND_POLYMORPH:
145                 {
146                         if (poly_monster(dir, lev)) ident = TRUE;
147                         break;
148                 }
149
150                 case SV_WAND_STINKING_CLOUD:
151                 {
152                         fire_ball(GF_POIS, dir, 12 + lev / 4, rad);
153                         ident = TRUE;
154                         break;
155                 }
156
157                 case SV_WAND_MAGIC_MISSILE:
158                 {
159                         fire_bolt_or_beam(20, GF_MISSILE, dir, damroll(2 + lev / 10, 6));
160                         ident = TRUE;
161                         break;
162                 }
163
164                 case SV_WAND_ACID_BOLT:
165                 {
166                         fire_bolt_or_beam(20, GF_ACID, dir, damroll(6 + lev / 7, 8));
167                         ident = TRUE;
168                         break;
169                 }
170
171                 case SV_WAND_CHARM_MONSTER:
172                 {
173                         if (charm_monster(dir, MAX(20, lev)))
174                                 ident = TRUE;
175                         break;
176                 }
177
178                 case SV_WAND_FIRE_BOLT:
179                 {
180                         fire_bolt_or_beam(20, GF_FIRE, dir, damroll(7 + lev / 6, 8));
181                         ident = TRUE;
182                         break;
183                 }
184
185                 case SV_WAND_COLD_BOLT:
186                 {
187                         fire_bolt_or_beam(20, GF_COLD, dir, damroll(5 + lev / 8, 8));
188                         ident = TRUE;
189                         break;
190                 }
191
192                 case SV_WAND_ACID_BALL:
193                 {
194                         fire_ball(GF_ACID, dir, 60 + 3 * lev / 4, rad);
195                         ident = TRUE;
196                         break;
197                 }
198
199                 case SV_WAND_ELEC_BALL:
200                 {
201                         fire_ball(GF_ELEC, dir, 40 + 3 * lev / 4, rad);
202                         ident = TRUE;
203                         break;
204                 }
205
206                 case SV_WAND_FIRE_BALL:
207                 {
208                         fire_ball(GF_FIRE, dir, 70 + 3 * lev / 4, rad);
209                         ident = TRUE;
210                         break;
211                 }
212
213                 case SV_WAND_COLD_BALL:
214                 {
215                         fire_ball(GF_COLD, dir, 50 + 3 * lev / 4, rad);
216                         ident = TRUE;
217                         break;
218                 }
219
220                 case SV_WAND_WONDER:
221                 {
222                         msg_print(_("おっと、謎の魔法棒を始動させた。", "Oops.  Wand of wonder activated."));
223                         break;
224                 }
225
226                 case SV_WAND_DRAGON_FIRE:
227                 {
228                         fire_breath(GF_FIRE, dir, (powerful ? 300 : 200), 3);
229                         ident = TRUE;
230                         break;
231                 }
232
233                 case SV_WAND_DRAGON_COLD:
234                 {
235                         fire_breath(GF_COLD, dir, (powerful ? 270 : 180), 3);
236                         ident = TRUE;
237                         break;
238                 }
239
240                 case SV_WAND_DRAGON_BREATH:
241                 {
242                         HIT_POINT dam;
243                         EFFECT_ID typ;
244
245                         switch (randint1(5))
246                         {
247                         case 1:
248                                 dam = 240;
249                                 typ = GF_ACID;
250                                 break;
251                         case 2:
252                                 dam = 210;
253                                 typ = GF_ELEC;
254                                 break;
255                         case 3:
256                                 dam = 240;
257                                 typ = GF_FIRE;
258                                 break;
259                         case 4:
260                                 dam = 210;
261                                 typ = GF_COLD;
262                                 break;
263                         default:
264                                 dam = 180;
265                                 typ = GF_POIS;
266                                 break;
267                         }
268
269                         if (powerful) dam = (dam * 3) / 2;
270
271                         fire_breath(typ, dir, dam, 3);
272
273                         ident = TRUE;
274                         break;
275                 }
276
277                 case SV_WAND_DISINTEGRATE:
278                 {
279                         fire_ball(GF_DISINTEGRATE, dir, 200 + randint1(lev * 2), rad);
280                         ident = TRUE;
281                         break;
282                 }
283
284                 case SV_WAND_ROCKETS:
285                 {
286                         msg_print(_("ロケットを発射した!", "You launch a rocket!"));
287                         fire_rocket(GF_ROCKET, dir, 250 + lev * 3, rad);
288                         ident = TRUE;
289                         break;
290                 }
291
292                 case SV_WAND_STRIKING:
293                 {
294                         fire_bolt(GF_METEOR, dir, damroll(15 + lev / 3, 13));
295                         ident = TRUE;
296                         break;
297                 }
298
299                 case SV_WAND_GENOCIDE:
300                 {
301                         fire_ball_hide(GF_GENOCIDE, dir, magic ? lev + 50 : 250, 0);
302                         ident = TRUE;
303                         break;
304                 }
305         }
306         return ident;
307 }
308
309 /*!
310 * @brief 魔法棒を使うコマンドのサブルーチン /
311 * Aim a wand (from the pack or floor).
312 * @param item 使うオブジェクトの所持品ID
313 * @return なし
314 * @details
315 * <pre>
316 * Use a single charge from a single item.
317 * Handle "unstacking" in a logical manner.
318 * For simplicity, you cannot use a stack of items from the
319 * ground.  This would require too much nasty code.
320 * There are no wands which can "destroy" themselves, in the p_ptr->inventory_list
321 * or on the ground, so we can ignore this possibility.  Note that this
322 * required giving "wand of wonder" the ability to ignore destruction
323 * by electric balls.
324 * All wands can be "cancelled" at the "Direction?" prompt for free.
325 * Note that the basic "bolt" wands do slightly less damage than the
326 * basic "bolt" rods, but the basic "ball" wands do the same damage
327 * as the basic "ball" rods.
328 * </pre>
329 */
330 void exe_aim_wand(player_type *creature_ptr, INVENTORY_IDX item)
331 {
332         DEPTH lev;
333         int ident, chance;
334         DIRECTION dir;
335         object_type *o_ptr;
336         bool old_target_pet = target_pet;
337
338         o_ptr = REF_ITEM(creature_ptr, p_ptr->current_floor_ptr, item);
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(creature_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 = creature_ptr->skill_dev;
367
368         /* Confusion hurts skill */
369         if (creature_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(creature_ptr)) return;
381
382         /* Roll for usage */
383         if ((chance < USE_DEVICE) || (randint1(chance) < USE_DEVICE) || (creature_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                 creature_ptr->update |= (PU_COMBINE | PU_REORDER);
398                 creature_ptr->window |= (PW_INVEN);
399
400                 return;
401         }
402
403         sound(SOUND_ZAP);
404
405         ident = wand_effect(creature_ptr, o_ptr->sval, dir, FALSE, FALSE);
406         creature_ptr->update |= (PU_COMBINE | PU_REORDER);
407
408         if (!(object_is_aware(o_ptr)))
409         {
410                 chg_virtue(creature_ptr, V_PATIENCE, -1);
411                 chg_virtue(creature_ptr, V_CHANCE, 1);
412                 chg_virtue(creature_ptr, 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(creature_ptr, (lev + (creature_ptr->lev >> 1)) / creature_ptr->lev);
423         }
424
425         creature_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(player_type *creature_ptr)
449 {
450         OBJECT_IDX item;
451         concptr q, s;
452
453         if (creature_ptr->wild_mode) return;
454         if (cmd_limit_arena(creature_ptr)) return;
455         if (creature_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
456         {
457                 set_action(creature_ptr, ACTION_NONE);
458         }
459
460         q = _("どの魔法棒で狙いますか? ", "Aim which wand? ");
461         s = _("使える魔法棒がない。", "You have no wand to aim.");
462         if (!choose_object(p_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), TV_WAND)) return;
463
464         exe_aim_wand(creature_ptr, item);
465 }