OSDN Git Service

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