OSDN Git Service

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