OSDN Git Service

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