OSDN Git Service

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