OSDN Git Service

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