1 #include "specific-object/chest.h"
2 #include "floor/cave.h"
3 #include "floor/floor-object.h"
6 #include "main/sound-definitions-table.h"
7 #include "main/sound-of-music.h"
8 #include "monster-floor/monster-summon.h"
9 #include "monster-floor/place-monster-types.h"
10 #include "object-enchant/item-apply-magic.h"
11 #include "object/object-generator.h"
12 #include "perception/object-perception.h"
13 #include "player/player-class.h"
14 #include "player/player-damage.h"
15 #include "player/player-status-flags.h"
16 #include "spell-kind/spells-equipment.h"
17 #include "spell-kind/spells-launcher.h"
18 #include "spell-kind/spells-sight.h"
19 #include "spell/spells-summon.h"
20 #include "spell/summon-types.h"
21 #include "spell/spell-types.h"
22 #include "status/bad-status-setter.h"
23 #include "status/base-status.h"
24 #include "status/element-resistance.h"
25 #include "sv-definition/sv-other-types.h"
26 #include "system/floor-type-definition.h"
27 #include "system/object-type-definition.h"
28 #include "view/display-messages.h"
30 /*!< この値以降の小項目IDを持った箱は大型の箱としてドロップ数を増やす / Special "sval" limit -- first "large" chest */
31 #define SV_CHEST_MIN_LARGE 4
34 * @brief 箱からアイテムを引き出す /
35 * Allocates objects upon opening a chest -BEN-
36 * @param scatter TRUEならばトラップによるアイテムの拡散処理
37 * @param y 箱の存在するマスのY座標
38 * @param x 箱の存在するマスのX座標
39 * @param o_idx 箱のオブジェクトID
43 * Disperse treasures from the given chest, centered at (x,y).
45 * Small chests often contain "gold", while Large chests always contain
46 * items. Wooden chests contain 2 items, Iron chests contain 4 items,
47 * and Steel chests contain 6 items. The "value" of the items in a
48 * chest is based on the "power" of the chest, which is in turn based
49 * on the level on which the chest is generated.
52 void chest_death(player_type *owner_ptr, bool scatter, POSITION y, POSITION x, OBJECT_IDX o_idx)
57 BIT_FLAGS mode = AM_GOOD | AM_FORBID_CHEST;
62 floor_type *floor_ptr = owner_ptr->current_floor_ptr;
63 object_type *o_ptr = &floor_ptr->o_list[o_idx];
65 /* Small chests often hold "gold" */
66 small = (o_ptr->sval < SV_CHEST_MIN_LARGE);
68 /* Determine how much to drop (see above) */
69 number = (o_ptr->sval % SV_CHEST_MIN_LARGE) * 2;
71 if (o_ptr->sval == SV_CHEST_KANDUME)
76 floor_ptr->object_level = o_ptr->xtra3;
80 /* Determine the "value" of the items */
81 floor_ptr->object_level = ABS(o_ptr->pval) + 10;
84 /* Zero pval means empty chest */
85 if (!o_ptr->pval) number = 0;
88 /* Drop some objects (non-chests) */
89 for (; number > 0; --number)
94 /* Small chests often drop gold */
95 if (small && (randint0(100) < 25))
98 if (!make_gold(owner_ptr, q_ptr)) continue;
101 /* Otherwise drop an item */
104 /* Make a good object */
105 if (!make_object(owner_ptr, q_ptr, mode)) continue;
108 /* If chest scatters its contents, pick any floor square. */
112 for (i = 0; i < 200; i++)
114 /* Pick a totally random spot. */
115 y = randint0(MAX_HGT);
116 x = randint0(MAX_WID);
118 /* Must be an empty floor. */
119 if (!is_cave_empty_bold(owner_ptr, y, x)) continue;
121 /* Place the object there. */
122 (void)drop_near(owner_ptr, q_ptr, -1, y, x);
128 /* Normally, drop object near the chest. */
129 else (void)drop_near(owner_ptr, q_ptr, -1, y, x);
132 /* Reset the object level */
133 floor_ptr->object_level = floor_ptr->base_level;
145 * Chests have traps too.
146 * @param y 箱の存在するマスのY座標
147 * @param x 箱の存在するマスのX座標
148 * @param o_idx 箱のオブジェクトID
152 * Exploding chest destroys contents (and traps).
153 * Note that the chest itself is never destroyed.
156 void chest_trap(player_type *target_ptr, POSITION y, POSITION x, OBJECT_IDX o_idx)
160 object_type *o_ptr = &target_ptr->current_floor_ptr->o_list[o_idx];
162 int mon_level = o_ptr->xtra3;
164 /* Ignore disarmed chests */
165 if (o_ptr->pval <= 0) return;
167 /* Obtain the traps */
168 trap = chest_traps[o_ptr->pval];
171 if (trap & (CHEST_LOSE_STR))
173 msg_print(_("仕掛けられていた小さな針に刺されてしまった!", "A small needle has pricked you!"));
174 take_hit(target_ptr, DAMAGE_NOESCAPE, damroll(1, 4), _("毒針", "a poison needle"), -1);
175 (void)do_dec_stat(target_ptr, A_STR);
178 /* Lose constitution */
179 if (trap & (CHEST_LOSE_CON))
181 msg_print(_("仕掛けられていた小さな針に刺されてしまった!", "A small needle has pricked you!"));
182 take_hit(target_ptr, DAMAGE_NOESCAPE, damroll(1, 4), _("毒針", "a poison needle"), -1);
183 (void)do_dec_stat(target_ptr, A_CON);
187 if (trap & (CHEST_POISON))
189 msg_print(_("突如吹き出した緑色のガスに包み込まれた!", "A puff of green gas surrounds you!"));
190 if (!(has_resist_pois(target_ptr) || is_oppose_pois(target_ptr)))
192 (void)set_poisoned(target_ptr, target_ptr->poisoned + 10 + randint1(20));
197 if (trap & (CHEST_PARALYZE))
199 msg_print(_("突如吹き出した黄色いガスに包み込まれた!", "A puff of yellow gas surrounds you!"));
200 if (!target_ptr->free_act)
202 (void)set_paralyzed(target_ptr, target_ptr->paralyzed + 10 + randint1(20));
206 /* Summon monsters */
207 if (trap & (CHEST_SUMMON))
209 int num = 2 + randint1(3);
210 msg_print(_("突如吹き出した煙に包み込まれた!", "You are enveloped in a cloud of smoke!"));
211 for (i = 0; i < num; i++)
213 if (randint1(100)<target_ptr->current_floor_ptr->dun_level)
214 activate_hi_summon(target_ptr, target_ptr->y, target_ptr->x, FALSE);
216 (void)summon_specific(target_ptr, 0, y, x, mon_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
220 /* Elemental summon. */
221 if (trap & (CHEST_E_SUMMON))
223 msg_print(_("宝を守るためにエレメンタルが現れた!", "Elemental beings appear to protect their treasures!"));
224 for (i = 0; i < randint1(3) + 5; i++)
226 (void)summon_specific(target_ptr, 0, y, x, mon_level, SUMMON_ELEMENTAL, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
230 /* Force clouds, then summon birds. */
231 if (trap & (CHEST_BIRD_STORM))
233 msg_print(_("鳥の群れがあなたを取り巻いた!", "A storm of birds swirls around you!"));
235 for (i = 0; i < randint1(3) + 3; i++)
236 (void)fire_meteor(target_ptr, -1, GF_FORCE, y, x, o_ptr->pval / 5, 7);
238 for (i = 0; i < randint1(5) + o_ptr->pval / 5; i++)
240 (void)summon_specific(target_ptr, 0, y, x, mon_level, SUMMON_BIRD, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
244 /* Various colorful summonings. */
245 if (trap & (CHEST_H_SUMMON))
250 msg_print(_("炎と硫黄の雲の中に悪魔が姿を現した!", "Demons materialize in clouds of fire and brimstone!"));
251 for (i = 0; i < randint1(3) + 2; i++)
253 (void)fire_meteor(target_ptr, -1, GF_FIRE, y, x, 10, 5);
254 (void)summon_specific(target_ptr, 0, y, x, mon_level, SUMMON_DEMON, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
258 /* Summon dragons. */
261 msg_print(_("暗闇にドラゴンの影がぼんやりと現れた!", "Draconic forms loom out of the darkness!"));
262 for (i = 0; i < randint1(3) + 2; i++)
264 (void)summon_specific(target_ptr, 0, y, x, mon_level, SUMMON_DRAGON, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
268 /* Summon hybrids. */
271 msg_print(_("奇妙な姿の怪物が襲って来た!", "Creatures strange and twisted assault you!"));
272 for (i = 0; i < randint1(5) + 3; i++)
274 (void)summon_specific(target_ptr, 0, y, x, mon_level, SUMMON_HYBRID, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
278 /* Summon vortices (scattered) */
281 msg_print(_("渦巻が合体し、破裂した!", "Vortices coalesce and wreak destruction!"));
282 for (i = 0; i < randint1(3) + 2; i++)
284 (void)summon_specific(target_ptr, 0, y, x, mon_level, SUMMON_VORTEX, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
290 if ((trap & (CHEST_RUNES_OF_EVIL)) && o_ptr->k_idx)
292 /* Determine how many nasty tricks can be played. */
293 int nasty_tricks_count = 4 + randint0(3);
295 msg_print(_("恐ろしい声が響いた: 「暗闇が汝をつつまん!」", "Hideous voices bid: 'Let the darkness have thee!'"));
296 /* This is gonna hurt... */
297 for (; nasty_tricks_count > 0; nasty_tricks_count--)
299 /* ...but a high saving throw does help a little. */
300 if (randint1(100 + o_ptr->pval * 2) > target_ptr->skill_sav)
302 if (one_in_(6)) take_hit(target_ptr, DAMAGE_NOESCAPE, damroll(5, 20), _("破滅のトラップの宝箱", "a chest dispel-player trap"), -1);
303 else if (one_in_(5)) (void)set_cut(target_ptr,target_ptr->cut + 200);
306 if (!target_ptr->free_act)
307 (void)set_paralyzed(target_ptr, target_ptr->paralyzed + 2 +
310 (void)set_stun(target_ptr, target_ptr->stun + 10 +
313 else if (one_in_(3)) apply_disenchant(target_ptr, 0);
316 (void)do_dec_stat(target_ptr, A_STR);
317 (void)do_dec_stat(target_ptr, A_DEX);
318 (void)do_dec_stat(target_ptr, A_CON);
319 (void)do_dec_stat(target_ptr, A_INT);
320 (void)do_dec_stat(target_ptr, A_WIS);
321 (void)do_dec_stat(target_ptr, A_CHR);
323 else (void)fire_meteor(target_ptr, -1, GF_NETHER, y, x, 150, 1);
328 /* Aggravate monsters. */
329 if (trap & (CHEST_ALARM))
331 msg_print(_("けたたましい音が鳴り響いた!", "An alarm sounds!"));
332 aggravate_monsters(target_ptr, 0);
336 if ((trap & (CHEST_EXPLODE)) && o_ptr->k_idx)
338 msg_print(_("突然、箱が爆発した!", "There is a sudden explosion!"));
339 msg_print(_("箱の中の物はすべて粉々に砕け散った!", "Everything inside the chest is destroyed!"));
341 sound(SOUND_EXPLODE);
342 take_hit(target_ptr, DAMAGE_ATTACK, damroll(5, 8), _("爆発する箱", "an exploding chest"), -1);
344 /* Scatter contents. */
345 if ((trap & (CHEST_SCATTER)) && o_ptr->k_idx)
347 msg_print(_("宝箱の中身はダンジョンじゅうに散乱した!", "The contents of the chest scatter all over the dungeon!"));
348 chest_death(target_ptr, TRUE, y, x, o_idx);