2 * @brief 魔法によるプレイヤーへの効果まとめ
7 #include "effect/effect-player.h"
8 #include "core/disturbance.h"
9 #include "effect/attribute-types.h"
10 #include "effect/effect-characteristics.h"
11 #include "effect/effect-player-switcher.h"
12 #include "effect/effect-player.h"
13 #include "effect/effect-processor.h"
14 #include "effect/spells-effect-util.h"
15 #include "floor/cave.h"
16 #include "main/sound-definitions-table.h"
17 #include "main/sound-of-music.h"
18 #include "mind/mind-ninja.h"
19 #include "monster-race/monster-race.h"
20 #include "monster/monster-describer.h"
21 #include "monster/monster-description-types.h"
22 #include "player-base/player-class.h"
23 #include "player-info/samurai-data-type.h"
24 #include "player/player-status-flags.h"
25 #include "player/special-defense-types.h"
26 #include "realm/realm-hex-numbers.h"
27 #include "spell-realm/spells-crusade.h"
28 #include "spell-realm/spells-hex.h"
29 #include "spell/spells-util.h"
30 #include "system/floor-type-definition.h"
31 #include "system/monster-race-definition.h"
32 #include "system/monster-type-definition.h"
33 #include "system/player-type-definition.h"
34 #include "target/projection-path-calculator.h"
35 #include "timed-effect/player-blindness.h"
36 #include "timed-effect/timed-effects.h"
37 #include "util/bit-flags-calculator.h"
38 #include "view/display-messages.h"
42 * @brief EffectPlayerType構造体を初期化する
43 * @param ep_ptr 初期化前の構造体
44 * @param who 魔法を唱えたモンスター (0ならプレイヤー自身)
46 * @param attribute 効果属性
48 * @param monspell 効果元のモンスター魔法ID
49 * @return 初期化後の構造体ポインタ
51 EffectPlayerType::EffectPlayerType(MONSTER_IDX who, int dam, AttributeType attribute, BIT_FLAGS flag)
59 , attribute(attribute)
66 * @param player_ptr プレイヤーへの参照ポインタ
67 * @param ep_ptr プレイヤー効果構造体への参照ポインタ
68 * @return 当たったらFALSE、反射したらTRUE
70 static bool process_bolt_reflection(PlayerType *player_ptr, EffectPlayerType *ep_ptr, project_func project)
72 auto can_reflect = (has_reflect(player_ptr) != 0);
73 can_reflect &= any_bits(ep_ptr->flag, PROJECT_REFLECTABLE);
74 can_reflect &= !one_in_(10);
79 auto max_attempts = 10;
83 if (player_ptr->effects()->blindness()->is_blind()) {
84 mes = _("何かが跳ね返った!", "Something bounces!");
85 } else if (PlayerClass(player_ptr).samurai_stance_is(SamuraiStanceType::FUUJIN)) {
86 mes = _("風の如く武器を振るって弾き返した!", "The attack bounces!");
88 mes = _("攻撃が跳ね返った!", "The attack bounces!");
94 if (ep_ptr->who > 0) {
95 auto *floor_ptr = player_ptr->current_floor_ptr;
96 auto *m_ptr = &floor_ptr->m_list[ep_ptr->who];
98 t_y = m_ptr->fy - 1 + randint1(3);
99 t_x = m_ptr->fx - 1 + randint1(3);
101 } while (max_attempts && in_bounds2u(floor_ptr, t_y, t_x) && !projectable(player_ptr, player_ptr->y, player_ptr->x, t_y, t_x));
103 if (max_attempts < 1) {
108 t_y = player_ptr->y - 1 + randint1(3);
109 t_x = player_ptr->x - 1 + randint1(3);
112 (*project)(player_ptr, 0, 0, t_y, t_x, ep_ptr->dam, ep_ptr->attribute, (PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE), std::nullopt);
113 disturb(player_ptr, true, true);
118 * @brief 反射・忍者の変わり身などでそもそも当たらない状況を判定する
119 * @param player_ptr プレイヤーへの参照ポインタ
120 * @param ep_ptr プレイヤー効果構造体への参照ポインタ
123 * @return 当たらなかったらFALSE、反射したらTRUE、当たったらCONTINUE
125 static ProcessResult check_continue_player_effect(PlayerType *player_ptr, EffectPlayerType *ep_ptr, POSITION y, POSITION x, project_func project)
127 if (!player_bold(player_ptr, y, x)) {
128 return ProcessResult::PROCESS_FALSE;
131 auto is_effective = ep_ptr->dam > 0;
132 is_effective &= randint0(55) < (player_ptr->lev * 3 / 5 + 20);
133 is_effective &= ep_ptr->who > 0;
134 is_effective &= ep_ptr->who != player_ptr->riding;
135 if (is_effective && kawarimi(player_ptr, true)) {
136 return ProcessResult::PROCESS_FALSE;
139 if ((ep_ptr->who == 0) || (ep_ptr->who == player_ptr->riding)) {
140 return ProcessResult::PROCESS_FALSE;
143 if (process_bolt_reflection(player_ptr, ep_ptr, project)) {
144 return ProcessResult::PROCESS_TRUE;
147 return ProcessResult::PROCESS_CONTINUE;
151 * @brief 魔法を発したモンスター名を記述する
152 * @param player_ptr プレイヤーへの参照ポインタ
153 * @param ep_ptr プレイヤー効果構造体への参照ポインタ
154 * @param who_name モンスター名
156 static void describe_effect_source(PlayerType *player_ptr, EffectPlayerType *ep_ptr, concptr who_name)
158 if (ep_ptr->who > 0) {
159 ep_ptr->m_ptr = &player_ptr->current_floor_ptr->m_list[ep_ptr->who];
160 ep_ptr->rlev = (&monraces_info[ep_ptr->m_ptr->r_idx])->level >= 1 ? (&monraces_info[ep_ptr->m_ptr->r_idx])->level : 1;
161 monster_desc(player_ptr, ep_ptr->m_name, ep_ptr->m_ptr, 0);
162 strcpy(ep_ptr->killer, who_name);
166 switch (ep_ptr->who) {
167 case PROJECT_WHO_UNCTRL_POWER:
168 strcpy(ep_ptr->killer, _("制御できない力の氾流", "uncontrollable power storm"));
170 case PROJECT_WHO_GLASS_SHARDS:
171 strcpy(ep_ptr->killer, _("ガラスの破片", "shards of glass"));
174 strcpy(ep_ptr->killer, _("罠", "a trap"));
178 strcpy(ep_ptr->m_name, ep_ptr->killer);
182 * @brief 汎用的なビーム/ボルト/ボール系によるプレイヤーへの効果処理 / Helper function for "project()" below.
183 * @param who 魔法を発動したモンスター(0ならばプレイヤー、負値ならば自然発生) / Index of "source" monster (zero for "player")
184 * @param who_name 効果を起こしたモンスターの名前
185 * @param r 効果半径(ビーム/ボルト = 0 / ボール = 1以上) / Radius of explosion (0 = beam/bolt, 1 to 9 = ball)
186 * @param y 目標Y座標 / Target y location (or location to travel "towards")
187 * @param x 目標X座標 / Target x location (or location to travel "towards")
188 * @param dam 基本威力 / Base damage roll to apply to affected monsters (or player)
189 * @param attribute 効果属性 / Type of damage to apply to monsters (and objects)
191 * @param monspell 効果元のモンスター魔法ID
192 * @return 何か一つでも効力があればTRUEを返す / TRUE if any "effects" of the projection were observed, else FALSE
194 bool affect_player(MONSTER_IDX who, PlayerType *player_ptr, concptr who_name, int r, POSITION y, POSITION x, int dam, AttributeType attribute,
195 BIT_FLAGS flag, project_func project)
197 EffectPlayerType tmp_effect(who, dam, attribute, flag);
198 auto *ep_ptr = &tmp_effect;
199 auto check_result = check_continue_player_effect(player_ptr, ep_ptr, y, x, project);
200 if (check_result != ProcessResult::PROCESS_CONTINUE) {
201 return check_result == ProcessResult::PROCESS_TRUE;
204 if (ep_ptr->dam > 1600) {
208 ep_ptr->dam = (ep_ptr->dam + r) / (r + 1);
209 describe_effect_source(player_ptr, ep_ptr, who_name);
210 switch_effects_player(player_ptr, ep_ptr);
212 SpellHex(player_ptr).store_vengeful_damage(ep_ptr->get_damage);
213 if ((player_ptr->tim_eyeeye || SpellHex(player_ptr).is_spelling_specific(HEX_EYE_FOR_EYE)) && (ep_ptr->get_damage > 0) && !player_ptr->is_dead && (ep_ptr->who > 0)) {
214 GAME_TEXT m_name_self[MAX_MONSTER_NAME];
215 monster_desc(player_ptr, m_name_self, ep_ptr->m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE | MD_OBJECTIVE);
216 msg_format(_("攻撃が%s自身を傷つけた!", "The attack of %s has wounded %s!"), ep_ptr->m_name, m_name_self);
217 (*project)(player_ptr, 0, 0, ep_ptr->m_ptr->fy, ep_ptr->m_ptr->fx, ep_ptr->get_damage, AttributeType::MISSILE, PROJECT_KILL, std::nullopt);
218 if (player_ptr->tim_eyeeye) {
219 set_tim_eyeeye(player_ptr, player_ptr->tim_eyeeye - 5, true);
223 if (player_ptr->riding && ep_ptr->dam > 0) {
224 rakubadam_p = (ep_ptr->dam > 200) ? 200 : ep_ptr->dam;
227 disturb(player_ptr, true, true);
228 if (ep_ptr->dam && ep_ptr->who && (ep_ptr->who != player_ptr->riding)) {
229 (void)kawarimi(player_ptr, false);