OSDN Git Service

[Refactor] #38997 wall_stone()、destroy_doors_touch()、disarm_traps_touch()、sleep_monst...
[hengband/hengband.git] / src / cmd / cmd-usestaff.c
1 #include "angband.h"
2 #include "util.h"
3
4 #include "player-race.h"
5 #include "spells-summon.h"
6 #include "avatar.h"
7 #include "player-status.h"
8 #include "player-effects.h"
9 #include "player-class.h"
10 #include "player-inventory.h"
11 #include "spells.h"
12 #include "spells-status.h"
13 #include "spells-floor.h"
14 #include "object-hook.h"
15 #include "cmd-basic.h"
16 #include "floor.h"
17 #include "objectkind.h"
18 #include "view-mainwindow.h"
19
20
21 /*!
22 * @brief 杖の効果を発動する
23 * @param creature_ptr プレーヤーへの参照ポインタ
24 * @param sval オブジェクトのsval
25 * @param use_charge 使用回数を消費したかどうかを返す参照ポインタ
26 * @param powerful 強力発動上の処理ならばTRUE
27 * @param magic 魔道具術上の処理ならばTRUE
28 * @param known 判明済ならばTRUE
29 * @return 発動により効果内容が確定したならばTRUEを返す
30 */
31 int staff_effect(player_type *creature_ptr, OBJECT_SUBTYPE_VALUE sval, bool *use_charge, bool powerful, bool magic, bool known)
32 {
33         int k;
34         int ident = FALSE;
35         PLAYER_LEVEL lev = powerful ? creature_ptr->lev * 2 : creature_ptr->lev;
36         POSITION detect_rad = powerful ? DETECT_RAD_DEFAULT * 3 / 2 : DETECT_RAD_DEFAULT;
37
38         /* Analyze the staff */
39         switch (sval)
40         {
41                 case SV_STAFF_DARKNESS:
42                 {
43                         if (!(creature_ptr->resist_blind) && !(creature_ptr->resist_dark))
44                         {
45                                 if (set_blind(creature_ptr, creature_ptr->blind + 3 + randint1(5))) ident = TRUE;
46                         }
47                         if (unlite_area(creature_ptr, 10, (powerful ? 6 : 3))) ident = TRUE;
48                         break;
49                 }
50
51                 case SV_STAFF_SLOWNESS:
52                 {
53                         if (set_slow(creature_ptr, creature_ptr->slow + randint1(30) + 15, FALSE)) ident = TRUE;
54                         break;
55                 }
56
57                 case SV_STAFF_HASTE_MONSTERS:
58                 {
59                         if (speed_monsters(creature_ptr)) ident = TRUE;
60                         break;
61                 }
62
63                 case SV_STAFF_SUMMONING:
64                 {
65                         const int times = randint1(powerful ? 8 : 4);
66                         for (k = 0; k < times; k++)
67                         {
68                                 if (summon_specific(0, creature_ptr->y, creature_ptr->x, creature_ptr->current_floor_ptr->dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
69                                 {
70                                         ident = TRUE;
71                                 }
72                         }
73                         break;
74                 }
75
76                 case SV_STAFF_TELEPORTATION:
77                 {
78                         teleport_player(creature_ptr, (powerful ? 150 : 100), 0L);
79                         ident = TRUE;
80                         break;
81                 }
82
83                 case SV_STAFF_IDENTIFY:
84                 {
85                         if (powerful) {
86                                 if (!identify_fully(FALSE)) *use_charge = FALSE;
87                         }
88                         else {
89                                 if (!ident_spell(creature_ptr, FALSE)) *use_charge = FALSE;
90                         }
91                         ident = TRUE;
92                         break;
93                 }
94
95                 case SV_STAFF_REMOVE_CURSE:
96                 {
97                         bool result = powerful ? remove_all_curse(creature_ptr) : remove_curse(creature_ptr);
98                         if (result)
99                         {
100                                 ident = TRUE;
101                         }
102                         break;
103                 }
104
105                 case SV_STAFF_STARLITE:
106                         ident = starlight(creature_ptr, magic);
107                         break;
108
109                 case SV_STAFF_LITE:
110                 {
111                         if (lite_area(creature_ptr, damroll(2, 8), (powerful ? 4 : 2))) ident = TRUE;
112                         break;
113                 }
114
115                 case SV_STAFF_MAPPING:
116                 {
117                         map_area(creature_ptr, powerful ? DETECT_RAD_MAP * 3 / 2 : DETECT_RAD_MAP);
118                         ident = TRUE;
119                         break;
120                 }
121
122                 case SV_STAFF_DETECT_GOLD:
123                 {
124                         if (detect_treasure(creature_ptr, detect_rad)) ident = TRUE;
125                         if (detect_objects_gold(creature_ptr, detect_rad)) ident = TRUE;
126                         break;
127                 }
128
129                 case SV_STAFF_DETECT_ITEM:
130                 {
131                         if (detect_objects_normal(creature_ptr, detect_rad)) ident = TRUE;
132                         break;
133                 }
134
135                 case SV_STAFF_DETECT_TRAP:
136                 {
137                         if (detect_traps(creature_ptr, detect_rad, known)) ident = TRUE;
138                         break;
139                 }
140
141                 case SV_STAFF_DETECT_DOOR:
142                 {
143                         if (detect_doors(creature_ptr, detect_rad)) ident = TRUE;
144                         if (detect_stairs(creature_ptr, detect_rad)) ident = TRUE;
145                         break;
146                 }
147
148                 case SV_STAFF_DETECT_INVIS:
149                 {
150                         if (detect_monsters_invis(creature_ptr, detect_rad)) ident = TRUE;
151                         break;
152                 }
153
154                 case SV_STAFF_DETECT_EVIL:
155                 {
156                         if (detect_monsters_evil(creature_ptr, detect_rad)) ident = TRUE;
157                         break;
158                 }
159
160                 case SV_STAFF_CURE_LIGHT:
161                 {
162                         ident = cure_light_wounds(creature_ptr, (powerful ? 4 : 2), 8);
163                         break;
164                 }
165
166                 case SV_STAFF_CURING:
167                 {
168                         ident = true_healing(creature_ptr, 0);
169                         if (set_shero(creature_ptr, 0, TRUE)) ident = TRUE;
170                         break;
171                 }
172
173                 case SV_STAFF_HEALING:
174                 {
175                         if (cure_critical_wounds(creature_ptr, powerful ? 500 : 300)) ident = TRUE;
176                         break;
177                 }
178
179                 case SV_STAFF_THE_MAGI:
180                 {
181                         if (do_res_stat(creature_ptr, A_INT)) ident = TRUE;
182                         ident |= restore_mana(creature_ptr, FALSE);
183                         if (set_shero(creature_ptr, 0, TRUE)) ident = TRUE;
184                         break;
185                 }
186
187                 case SV_STAFF_SLEEP_MONSTERS:
188                 {
189                         if (sleep_monsters(creature_ptr, lev)) ident = TRUE;
190                         break;
191                 }
192
193                 case SV_STAFF_SLOW_MONSTERS:
194                 {
195                         if (slow_monsters(creature_ptr, lev)) ident = TRUE;
196                         break;
197                 }
198
199                 case SV_STAFF_SPEED:
200                 {
201                         if (set_fast(creature_ptr, randint1(30) + (powerful ? 30 : 15), FALSE)) ident = TRUE;
202                         break;
203                 }
204
205                 case SV_STAFF_PROBING:
206                 {
207                         ident = probing(creature_ptr);
208                         break;
209                 }
210
211                 case SV_STAFF_DISPEL_EVIL:
212                 {
213                         ident = dispel_evil(creature_ptr, powerful ? 120 : 80);
214                         break;
215                 }
216
217                 case SV_STAFF_POWER:
218                 {
219                         ident = dispel_monsters(creature_ptr, powerful ? 225 : 150) ;
220                         break;
221                 }
222
223                 case SV_STAFF_HOLINESS:
224                 {
225                         ident = cleansing_nova(creature_ptr, magic, powerful);
226                         break;
227                 }
228
229                 case SV_STAFF_GENOCIDE:
230                 {
231                         ident = symbol_genocide(creature_ptr, (magic ? lev + 50 : 200), TRUE);
232                         break;
233                 }
234
235                 case SV_STAFF_EARTHQUAKES:
236                 {
237                         if (earthquake(creature_ptr, creature_ptr->y, creature_ptr->x, (powerful ? 15 : 10), 0))
238                                 ident = TRUE;
239                         else
240                                 msg_print(_("ダンジョンが揺れた。", "The dungeon trembles."));
241
242                         break;
243                 }
244
245                 case SV_STAFF_DESTRUCTION:
246                 {
247                         ident = destroy_area(creature_ptr->current_floor_ptr, creature_ptr->y, creature_ptr->x, (powerful ? 18 : 13) + randint0(5), FALSE);
248                         break;
249                 }
250
251                 case SV_STAFF_ANIMATE_DEAD:
252                 {
253                         ident = animate_dead(creature_ptr, 0, creature_ptr->y, creature_ptr->x);
254                         break;
255                 }
256
257                 case SV_STAFF_MSTORM:
258                 {
259                         ident = unleash_mana_storm(creature_ptr, powerful);
260                         break;
261                 }
262
263                 case SV_STAFF_NOTHING:
264                 {
265                         msg_print(_("何も起らなかった。", "Nothing happen."));
266                         if (PRACE_IS_(creature_ptr, RACE_SKELETON) || PRACE_IS_(creature_ptr, RACE_GOLEM) ||
267                                 PRACE_IS_(creature_ptr, RACE_ZOMBIE) || PRACE_IS_(creature_ptr, RACE_SPECTRE))
268                                 msg_print(_("もったいない事をしたような気がする。食べ物は大切にしなくては。", "What a waste.  It's your food!"));
269                         break;
270                 }
271         }
272         return ident;
273 }
274
275
276 /*!
277  * @brief 杖を使うコマンドのサブルーチン /
278  * Use a staff.                 -RAK-
279  * @param item 使うオブジェクトの所持品ID
280  * @return なし
281  * @details
282  * One charge of one staff disappears.
283  * Hack -- staffs of identify can be "cancelled".
284  */
285 void exe_use_staff(player_type *creature_ptr, INVENTORY_IDX item)
286 {
287         int         ident, chance, lev;
288         object_type *o_ptr;
289
290                 /* Hack -- let staffs of identify get aborted */
291         bool use_charge = TRUE;
292
293         o_ptr = REF_ITEM(creature_ptr, creature_ptr->current_floor_ptr, item);
294
295         /* Mega-Hack -- refuse to use a pile from the ground */
296         if ((item < 0) && (o_ptr->number > 1))
297         {
298                 msg_print(_("まずは杖を拾わなければ。", "You must first pick up the staffs."));
299                 return;
300         }
301
302                 take_turn(creature_ptr, 100);
303
304         lev = k_info[o_ptr->k_idx].level;
305         if (lev > 50) lev = 50 + (lev - 50) / 2;
306
307         /* Base chance of success */
308         chance = creature_ptr->skill_dev;
309
310         /* Confusion hurts skill */
311         if (creature_ptr->confused) chance = chance / 2;
312
313         /* Hight level objects are harder */
314         chance = chance - lev;
315
316         /* Give everyone a (slight) chance */
317         if ((chance < USE_DEVICE) && one_in_(USE_DEVICE - chance + 1))
318         {
319                 chance = USE_DEVICE;
320         }
321
322         if (cmd_limit_time_walk(creature_ptr)) return;
323
324         /* Roll for usage */
325         if ((chance < USE_DEVICE) || (randint1(chance) < USE_DEVICE) || (creature_ptr->pclass == CLASS_BERSERKER))
326         {
327                 if (flush_failure) flush();
328                 msg_print(_("杖をうまく使えなかった。", "You failed to use the staff properly."));
329                 sound(SOUND_FAIL);
330                 return;
331         }
332
333         /* Notice empty staffs */
334         if (o_ptr->pval <= 0)
335         {
336                 if (flush_failure) flush();
337                 msg_print(_("この杖にはもう魔力が残っていない。", "The staff has no charges left."));
338                 o_ptr->ident |= (IDENT_EMPTY);
339                 creature_ptr->update |= (PU_COMBINE | PU_REORDER);
340                 creature_ptr->window |= (PW_INVEN);
341
342                 return;
343         }
344
345         sound(SOUND_ZAP);
346
347         ident = staff_effect(creature_ptr, o_ptr->sval, &use_charge, FALSE, FALSE, object_is_aware(o_ptr));
348
349         if (!(object_is_aware(o_ptr)))
350         {
351                 chg_virtue(creature_ptr, V_PATIENCE, -1);
352                 chg_virtue(creature_ptr, V_CHANCE, 1);
353                 chg_virtue(creature_ptr, V_KNOWLEDGE, -1);
354         }
355         creature_ptr->update |= (PU_COMBINE | PU_REORDER);
356
357         /* Tried the item */
358         object_tried(o_ptr);
359
360         /* An identification was made */
361         if (ident && !object_is_aware(o_ptr))
362         {
363                 object_aware(o_ptr);
364                 gain_exp(creature_ptr, (lev + (creature_ptr->lev >> 1)) / creature_ptr->lev);
365         }
366
367         creature_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
368
369
370         /* Hack -- some uses are "free" */
371         if (!use_charge) return;
372
373
374         /* Use a single charge */
375         o_ptr->pval--;
376
377         /* XXX Hack -- unstack if necessary */
378         if ((item >= 0) && (o_ptr->number > 1))
379         {
380                 object_type forge;
381                 object_type *q_ptr;
382                 q_ptr = &forge;
383                 object_copy(q_ptr, o_ptr);
384
385                 /* Modify quantity */
386                 q_ptr->number = 1;
387
388                 /* Restore the charges */
389                 o_ptr->pval++;
390
391                 /* Unstack the used item */
392                 o_ptr->number--;
393                 creature_ptr->total_weight -= q_ptr->weight;
394                 item = inven_carry(q_ptr);
395
396                 msg_print(_("杖をまとめなおした。", "You unstack your staff."));
397         }
398
399         /* Describe charges in the pack */
400         if (item >= 0)
401         {
402                 inven_item_charges(item);
403         }
404
405         /* Describe charges on the floor */
406         else
407         {
408                 floor_item_charges(0 - item);
409         }
410 }
411
412
413 /*!
414 * @brief 杖を使うコマンドのメインルーチン /
415 * @return なし
416 */
417 void do_cmd_use_staff(player_type *creature_ptr)
418 {
419         OBJECT_IDX item;
420         concptr q, s;
421
422         if (creature_ptr->wild_mode)
423         {
424                 return;
425         }
426
427         if (cmd_limit_arena(creature_ptr)) return;
428
429         if (creature_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
430         {
431                 set_action(creature_ptr, ACTION_NONE);
432         }
433
434         q = _("どの杖を使いますか? ", "Use which staff? ");
435         s = _("使える杖がない。", "You have no staff to use.");
436         if (!choose_object(creature_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), TV_STAFF)) return;
437
438         exe_use_staff(creature_ptr, item);
439 }