OSDN Git Service

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