1 #include "effect/effect-item.h"
2 #include "autopick/autopick.h"
3 #include "flavor/flavor-describer.h"
4 #include "flavor/object-flavor-types.h"
5 #include "floor/cave.h"
6 #include "floor/floor-object.h"
8 #include "monster-floor/monster-summon.h"
9 #include "monster-floor/place-monster-types.h"
10 #include "monster/monster-info.h"
11 #include "object-enchant/tr-types.h"
12 #include "object-hook/hook-checker.h"
13 #include "object-hook/hook-enchant.h"
14 #include "object-hook/hook-expendable.h"
15 #include "object/object-broken.h"
16 #include "object/object-flags.h"
17 #include "object/object-mark-types.h"
18 #include "perception/object-perception.h"
19 #include "spell-kind/spells-perception.h"
20 #include "spell/spell-types.h"
21 #include "sv-definition/sv-other-types.h"
22 #include "sv-definition/sv-scroll-types.h"
23 #include "system/floor-type-definition.h"
24 #include "system/grid-type-definition.h"
25 #include "system/monster-type-definition.h"
26 #include "system/object-type-definition.h"
27 #include "system/player-type-definition.h"
28 #include "util/bit-flags-calculator.h"
29 #include "view/display-messages.h"
34 * @brief 汎用的なビーム/ボルト/ボール系によるアイテムオブジェクトへの効果処理 / Handle a beam/bolt/ball causing damage to a monster.
35 * @param caster_ptr プレーヤーへの参照ポインタ
36 * @param who 魔法を発動したモンスター(0ならばプレイヤー) / Index of "source" monster (zero for "player")
37 * @param r 効果半径(ビーム/ボルト = 0 / ボール = 1以上) / Radius of explosion (0 = beam/bolt, 1 to 9 = ball)
38 * @param y 目標Y座標 / Target y location (or location to travel "towards")
39 * @param x 目標X座標 / Target x location (or location to travel "towards")
40 * @param dam 基本威力 / Base damage roll to apply to affected monsters (or player)
41 * @param typ 効果属性 / Type of damage to apply to monsters (and objects)
42 * @return 何か一つでも効力があればTRUEを返す / TRUE if any "effects" of the projection were observed, else FALSE
44 bool affect_item(player_type *caster_ptr, MONSTER_IDX who, POSITION r, POSITION y, POSITION x, HIT_POINT dam, EFFECT_ID typ)
46 grid_type *g_ptr = &caster_ptr->current_floor_ptr->grid_array[y][x];
48 bool is_item_affected = false;
49 bool known = player_has_los_bold(caster_ptr, y, x);
51 dam = (dam + r) / (r + 1);
52 std::set<OBJECT_IDX> processed_list;
53 for (auto it = g_ptr->o_idx_list.begin(); it != g_ptr->o_idx_list.end();) {
54 const OBJECT_IDX this_o_idx = *it++;
56 if (auto pit = processed_list.find(this_o_idx); pit != processed_list.end())
59 processed_list.insert(this_o_idx);
61 object_type *o_ptr = &caster_ptr->current_floor_ptr->o_list[this_o_idx];
64 concptr note_kill = NULL;
68 bool plural = (o_ptr->number > 1);
71 object_flags(o_ptr, flags);
72 bool is_artifact = o_ptr->is_artifact();
75 if (BreakerAcid().hates(o_ptr)) {
77 note_kill = _("融けてしまった!", (plural ? " melt!" : " melts!"));
78 if (has_flag(flags, TR_IGNORE_ACID))
85 if (BreakerElec().hates(o_ptr)) {
87 note_kill = _("壊れてしまった!", (plural ? " are destroyed!" : " is destroyed!"));
88 if (has_flag(flags, TR_IGNORE_ELEC))
95 if (BreakerFire().hates(o_ptr)) {
97 note_kill = _("燃えてしまった!", (plural ? " burn up!" : " burns up!"));
98 if (has_flag(flags, TR_IGNORE_FIRE))
105 if (BreakerCold().hates(o_ptr)) {
106 note_kill = _("砕け散ってしまった!", (plural ? " shatter!" : " shatters!"));
108 if (has_flag(flags, TR_IGNORE_COLD))
115 if (BreakerFire().hates(o_ptr)) {
117 note_kill = _("燃えてしまった!", (plural ? " burn up!" : " burns up!"));
118 if (has_flag(flags, TR_IGNORE_FIRE))
122 if (BreakerElec().hates(o_ptr)) {
125 note_kill = _("壊れてしまった!", (plural ? " are destroyed!" : " is destroyed!"));
126 if (has_flag(flags, TR_IGNORE_ELEC))
133 if (BreakerFire().hates(o_ptr)) {
135 note_kill = _("燃えてしまった!", (plural ? " burn up!" : " burns up!"));
136 if (has_flag(flags, TR_IGNORE_FIRE))
140 if (BreakerCold().hates(o_ptr)) {
143 note_kill = _("砕け散ってしまった!", (plural ? " shatter!" : " shatters!"));
144 if (has_flag(flags, TR_IGNORE_COLD))
154 if (BreakerCold().hates(o_ptr)) {
155 note_kill = _("砕け散ってしまった!", (plural ? " shatter!" : " shatters!"));
165 note_kill = _("壊れてしまった!", (plural ? " are destroyed!" : " is destroyed!"));
168 case GF_DISINTEGRATE: {
170 note_kill = _("蒸発してしまった!", (plural ? " evaporate!" : " evaporates!"));
175 note_kill = _("壊れてしまった!", (plural ? " are destroyed!" : " is destroyed!"));
176 if (has_flag(flags, TR_RES_CHAOS))
178 else if ((o_ptr->tval == TV_SCROLL) && (o_ptr->sval == SV_SCROLL_CHAOS))
184 if (o_ptr->is_cursed()) {
186 note_kill = _("壊れてしまった!", (plural ? " are destroyed!" : " is destroyed!"));
193 note_kill = _("消滅してしまった!", (plural ? " vanish!" : " vanishes!"));
197 identify_item(caster_ptr, o_ptr);
198 autopick_alter_item(caster_ptr, (-this_o_idx), false);
203 if (o_ptr->tval != TV_CHEST)
205 if (o_ptr->pval <= 0)
208 o_ptr->pval = (0 - o_ptr->pval);
210 if (known && (o_ptr->marked & OM_FOUND)) {
211 msg_print(_("カチッと音がした!", "Click!"));
212 is_item_affected = true;
218 if (o_ptr->tval != TV_CORPSE)
222 if (!who || is_pet(&caster_ptr->current_floor_ptr->m_list[who]))
223 mode |= PM_FORCE_PET;
225 for (int i = 0; i < o_ptr->number; i++) {
226 if (((o_ptr->sval == SV_CORPSE) && (randint1(100) > 80)) || ((o_ptr->sval == SV_SKELETON) && (randint1(100) > 60))) {
228 note_kill = _("灰になった。", (plural ? " become dust." : " becomes dust."));
232 } else if (summon_named_creature(caster_ptr, who, y, x, o_ptr->pval, mode)) {
233 note_kill = _("生き返った。", " revived.");
234 } else if (!note_kill) {
235 note_kill = _("灰になった。", (plural ? " become dust." : " becomes dust."));
240 is_item_affected = true;
248 GAME_TEXT o_name[MAX_NLEN];
249 if (known && (o_ptr->marked & OM_FOUND)) {
250 is_item_affected = true;
251 describe_flavor(caster_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
254 if ((is_artifact || ignore)) {
255 if (known && (o_ptr->marked & OM_FOUND))
256 msg_format(_("%sは影響を受けない!", (plural ? "The %s are unaffected!" : "The %s is unaffected!")), o_name);
261 if (known && (o_ptr->marked & OM_FOUND) && note_kill)
262 msg_format(_("%sは%s", "The %s%s"), o_name, note_kill);
264 KIND_OBJECT_IDX k_idx = o_ptr->k_idx;
265 bool is_potion = o_ptr->is_potion();
266 delete_object_idx(caster_ptr, this_o_idx);
268 (void)potion_smash_effect(caster_ptr, who, y, x, k_idx);
270 // 薬の破壊効果によりリストの次のアイテムが破壊された可能性があるのでリストの最初から処理をやり直す
271 // 処理済みのアイテムは processed_list に登録されており、スキップされる
272 it = g_ptr->o_idx_list.begin();
275 lite_spot(caster_ptr, y, x);
278 return is_item_affected;