OSDN Git Service

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