OSDN Git Service

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