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-tester-hooker.h"
16 #include "object/item-use-flags.h"
17 #include "object/object-info.h"
18 #include "object/object-kind.h"
19 #include "perception/object-perception.h"
20 #include "player-info/class-info.h"
21 #include "player-info/race-info.h"
22 #include "player-info/race-types.h"
23 #include "player-status/player-energy.h"
24 #include "player/attack-defense-types.h"
25 #include "player/player-status-flags.h"
26 #include "player/special-defense-types.h"
27 #include "spell-kind/earthquake.h"
28 #include "spell-kind/spells-curse-removal.h"
29 #include "spell-kind/spells-detection.h"
30 #include "spell-kind/spells-floor.h"
31 #include "spell-kind/spells-genocide.h"
32 #include "spell-kind/spells-lite.h"
33 #include "spell-kind/spells-neighbor.h"
34 #include "spell-kind/spells-perception.h"
35 #include "spell-kind/spells-sight.h"
36 #include "spell-kind/spells-teleport.h"
37 #include "spell/spells-staff-only.h"
38 #include "spell/spells-status.h"
39 #include "spell/spells-summon.h"
40 #include "spell/summon-types.h"
41 #include "status/action-setter.h"
42 #include "status/bad-status-setter.h"
43 #include "status/base-status.h"
44 #include "status/buff-setter.h"
45 #include "status/experience.h"
46 #include "status/shape-changer.h"
47 #include "status/sight-setter.h"
48 #include "sv-definition/sv-staff-types.h"
49 #include "system/floor-type-definition.h"
50 #include "system/object-type-definition.h"
51 #include "system/player-type-definition.h"
52 #include "term/screen-processor.h"
53 #include "util/bit-flags-calculator.h"
54 #include "view/display-messages.h"
55 #include "view/object-describer.h"
59 * @param player_ptr プレイヤーへの参照ポインタ
60 * @param sval オブジェクトのsval
61 * @param use_charge 使用回数を消費したかどうかを返す参照ポインタ
62 * @param powerful 強力発動上の処理ならばTRUE
63 * @param magic 魔道具術上の処理ならばTRUE
64 * @param known 判明済ならばTRUE
65 * @return 発動により効果内容が確定したならばTRUEを返す
67 int staff_effect(player_type *player_ptr, OBJECT_SUBTYPE_VALUE sval, bool *use_charge, bool powerful, bool magic, bool known)
71 PLAYER_LEVEL lev = powerful ? player_ptr->lev * 2 : player_ptr->lev;
72 POSITION detect_rad = powerful ? DETECT_RAD_DEFAULT * 3 / 2 : DETECT_RAD_DEFAULT;
74 BadStatusSetter bss(player_ptr);
76 case SV_STAFF_DARKNESS:
77 if (!has_resist_blind(player_ptr) && !has_resist_dark(player_ptr)) {
78 if (bss.mod_blindness(3 + randint1(5))) {
83 if (unlite_area(player_ptr, 10, (powerful ? 6 : 3))) {
88 case SV_STAFF_SLOWNESS: {
89 if (bss.mod_slowness(randint1(30) + 15, false))
94 case SV_STAFF_HASTE_MONSTERS: {
95 if (speed_monsters(player_ptr))
100 case SV_STAFF_SUMMONING: {
101 const int times = randint1(powerful ? 8 : 4);
102 for (k = 0; k < times; k++) {
103 if (summon_specific(player_ptr, 0, player_ptr->y, player_ptr->x, player_ptr->current_floor_ptr->dun_level, SUMMON_NONE,
104 (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET))) {
111 case SV_STAFF_TELEPORTATION: {
112 teleport_player(player_ptr, (powerful ? 150 : 100), 0L);
117 case SV_STAFF_IDENTIFY: {
119 if (!identify_fully(player_ptr, false))
122 if (!ident_spell(player_ptr, false))
129 case SV_STAFF_REMOVE_CURSE: {
130 bool result = (powerful ? remove_all_curse(player_ptr) : remove_curse(player_ptr)) != 0;
137 case SV_STAFF_STARLITE:
138 ident = starlight(player_ptr, magic);
141 case SV_STAFF_LITE: {
142 if (lite_area(player_ptr, damroll(2, 8), (powerful ? 4 : 2)))
147 case SV_STAFF_MAPPING: {
148 map_area(player_ptr, powerful ? DETECT_RAD_MAP * 3 / 2 : DETECT_RAD_MAP);
153 case SV_STAFF_DETECT_GOLD: {
154 if (detect_treasure(player_ptr, detect_rad))
156 if (detect_objects_gold(player_ptr, detect_rad))
161 case SV_STAFF_DETECT_ITEM: {
162 if (detect_objects_normal(player_ptr, detect_rad))
167 case SV_STAFF_DETECT_TRAP: {
168 if (detect_traps(player_ptr, detect_rad, known))
173 case SV_STAFF_DETECT_DOOR: {
174 if (detect_doors(player_ptr, detect_rad))
176 if (detect_stairs(player_ptr, detect_rad))
181 case SV_STAFF_DETECT_INVIS: {
182 if (set_tim_invis(player_ptr, player_ptr->tim_invis + 12 + randint1(12), false))
187 case SV_STAFF_DETECT_EVIL: {
188 if (detect_monsters_evil(player_ptr, detect_rad))
193 case SV_STAFF_CURE_LIGHT: {
194 ident = cure_light_wounds(player_ptr, (powerful ? 4 : 2), 8);
198 case SV_STAFF_CURING: {
199 ident = true_healing(player_ptr, 0);
200 if (set_shero(player_ptr, 0, true))
205 case SV_STAFF_HEALING: {
206 if (cure_critical_wounds(player_ptr, powerful ? 500 : 300))
211 case SV_STAFF_THE_MAGI: {
212 if (do_res_stat(player_ptr, A_INT))
214 ident |= restore_mana(player_ptr, false);
215 if (set_shero(player_ptr, 0, true))
220 case SV_STAFF_SLEEP_MONSTERS: {
221 if (sleep_monsters(player_ptr, lev))
226 case SV_STAFF_SLOW_MONSTERS: {
227 if (slow_monsters(player_ptr, lev))
232 case SV_STAFF_SPEED: {
233 if (set_fast(player_ptr, randint1(30) + (powerful ? 30 : 15), false))
238 case SV_STAFF_PROBING: {
239 ident = probing(player_ptr);
243 case SV_STAFF_DISPEL_EVIL: {
244 ident = dispel_evil(player_ptr, powerful ? 120 : 80);
248 case SV_STAFF_POWER: {
249 ident = dispel_monsters(player_ptr, powerful ? 225 : 150);
253 case SV_STAFF_HOLINESS: {
254 ident = cleansing_nova(player_ptr, magic, powerful);
258 case SV_STAFF_GENOCIDE: {
259 ident = symbol_genocide(player_ptr, (magic ? lev + 50 : 200), true);
263 case SV_STAFF_EARTHQUAKES: {
264 if (earthquake(player_ptr, player_ptr->y, player_ptr->x, (powerful ? 15 : 10), 0))
267 msg_print(_("ダンジョンが揺れた。", "The dungeon trembles."));
272 case SV_STAFF_DESTRUCTION: {
273 ident = destroy_area(player_ptr, player_ptr->y, player_ptr->x, (powerful ? 18 : 13) + randint0(5), false);
277 case SV_STAFF_ANIMATE_DEAD: {
278 ident = animate_dead(player_ptr, 0, player_ptr->y, player_ptr->x);
282 case SV_STAFF_MSTORM: {
283 ident = unleash_mana_storm(player_ptr, powerful);
287 case SV_STAFF_NOTHING: {
288 msg_print(_("何も起らなかった。", "Nothing happens."));
289 if (player_race_food(player_ptr) == PlayerRaceFood::MANA)
290 msg_print(_("もったいない事をしたような気がする。食べ物は大切にしなくては。", "What a waste. It's your food!"));
298 * @brief 杖を使うコマンドのサブルーチン /
300 * @param item 使うオブジェクトの所持品ID
302 * One charge of one staff disappears.
303 * Hack -- staffs of identify can be "cancelled".
305 void exe_use_staff(player_type *player_ptr, INVENTORY_IDX item)
307 int ident, chance, lev;
310 /* Hack -- let staffs of identify get aborted */
311 bool use_charge = true;
313 o_ptr = ref_item(player_ptr, item);
315 /* Mega-Hack -- refuse to use a pile from the ground */
316 if ((item < 0) && (o_ptr->number > 1)) {
317 msg_print(_("まずは杖を拾わなければ。", "You must first pick up the staffs."));
321 PlayerEnergy(player_ptr).set_player_turn_energy(100);
323 lev = k_info[o_ptr->k_idx].level;
325 lev = 50 + (lev - 50) / 2;
327 /* Base chance of success */
328 chance = player_ptr->skill_dev;
330 /* Confusion hurts skill */
331 if (player_ptr->confused)
334 /* Hight level objects are harder */
335 chance = chance - lev;
337 /* Give everyone a (slight) chance */
338 if ((chance < USE_DEVICE) && one_in_(USE_DEVICE - chance + 1)) {
342 if (cmd_limit_time_walk(player_ptr))
346 if ((chance < USE_DEVICE) || (randint1(chance) < USE_DEVICE) || (player_ptr->pclass == CLASS_BERSERKER)) {
349 msg_print(_("杖をうまく使えなかった。", "You failed to use the staff properly."));
354 /* Notice empty staffs */
355 if (o_ptr->pval <= 0) {
358 msg_print(_("この杖にはもう魔力が残っていない。", "The staff has no charges left."));
359 o_ptr->ident |= (IDENT_EMPTY);
360 player_ptr->update |= (PU_COMBINE | PU_REORDER);
361 player_ptr->window_flags |= (PW_INVEN);
368 ident = staff_effect(player_ptr, o_ptr->sval, &use_charge, false, false, o_ptr->is_aware());
370 if (!(o_ptr->is_aware())) {
371 chg_virtue(player_ptr, V_PATIENCE, -1);
372 chg_virtue(player_ptr, V_CHANCE, 1);
373 chg_virtue(player_ptr, V_KNOWLEDGE, -1);
377 * Temporarily remove the flags for updating the inventory so
378 * gain_exp() does not reorder the inventory before the charge
379 * is deducted from the staff.
381 BIT_FLAGS inventory_flags = (PU_COMBINE | PU_REORDER | (player_ptr->update & PU_AUTODESTROY));
382 reset_bits(player_ptr->update, PU_COMBINE | PU_REORDER | PU_AUTODESTROY);
387 /* An identification was made */
388 if (ident && !o_ptr->is_aware()) {
389 object_aware(player_ptr, o_ptr);
390 gain_exp(player_ptr, (lev + (player_ptr->lev >> 1)) / player_ptr->lev);
393 set_bits(player_ptr->window_flags, PW_INVEN | PW_EQUIP | PW_PLAYER | PW_FLOOR_ITEM_LIST);
394 set_bits(player_ptr->update, inventory_flags);
396 /* Hack -- some uses are "free" */
400 /* Use a single charge */
403 /* XXX Hack -- unstack if necessary */
404 if ((item >= 0) && (o_ptr->number > 1)) {
408 q_ptr->copy_from(o_ptr);
410 /* Modify quantity */
413 /* Restore the charges */
416 /* Unstack the used item */
418 item = store_item_to_inventory(player_ptr, q_ptr);
420 msg_print(_("杖をまとめなおした。", "You unstack your staff."));
423 /* Describe charges in the pack */
425 inven_item_charges(player_ptr, item);
428 /* Describe charges on the floor */
430 floor_item_charges(player_ptr->current_floor_ptr, 0 - item);
435 * @brief 杖を使うコマンドのメインルーチン /
437 void do_cmd_use_staff(player_type *player_ptr)
442 if (player_ptr->wild_mode) {
446 if (cmd_limit_arena(player_ptr))
449 if (player_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN)) {
450 set_action(player_ptr, ACTION_NONE);
453 q = _("どの杖を使いますか? ", "Use which staff? ");
454 s = _("使える杖がない。", "You have no staff to use.");
455 if (!choose_object(player_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), TvalItemTester(TV_STAFF)))
458 exe_use_staff(player_ptr, item);