OSDN Git Service

7d9b86c06b086445873c9610df25736f29804f3c
[hengbandforosx/hengbandosx.git] / src / spell-realm / spells-crusade.cpp
1 /*!
2  * @brief 破邪魔法処理
3  * @date 2020/06/05
4  * @author Hourier
5  */
6
7 #include "spell-realm/spells-crusade.h"
8 #include "core/disturbance.h"
9 #include "core/player-redraw-types.h"
10 #include "core/player-update-types.h"
11 #include "core/stuff-handler.h"
12 #include "effect/effect-characteristics.h"
13 #include "effect/effect-processor.h"
14 #include "floor/cave.h"
15 #include "floor/geometry.h"
16 #include "game-option/disturbance-options.h"
17 #include "grid/feature-flag-types.h"
18 #include "spell-realm/spells-crusade.h"
19 #include "spell/range-calc.h"
20 #include "effect/attribute-types.h"
21 #include "system/floor-type-definition.h"
22 #include "system/grid-type-definition.h"
23 #include "system/player-type-definition.h"
24 #include "target/projection-path-calculator.h"
25 #include "target/target-checker.h"
26 #include "target/target-getter.h"
27 #include "util/bit-flags-calculator.h"
28 #include "view/display-messages.h"
29
30 /*!
31  * @brief 破邪魔法「神の怒り」の処理としてターゲットを指定した後分解のボールを最大20回発生させる。
32  * @param player_ptr プレイヤーへの参照ポインタ
33  * @param dam ダメージ
34  * @param rad 効力の半径
35  * @return ターゲットを指定し、実行したならばTRUEを返す。
36  */
37 bool cast_wrath_of_the_god(PlayerType *player_ptr, HIT_POINT dam, POSITION rad)
38 {
39     DIRECTION dir;
40     if (!get_aim_dir(player_ptr, &dir))
41         return false;
42
43     POSITION tx = player_ptr->x + 99 * ddx[dir];
44     POSITION ty = player_ptr->y + 99 * ddy[dir];
45     if ((dir == 5) && target_okay(player_ptr)) {
46         tx = target_col;
47         ty = target_row;
48     }
49
50     POSITION x = player_ptr->x;
51     POSITION y = player_ptr->y;
52     POSITION nx, ny;
53     while (true) {
54         if ((y == ty) && (x == tx))
55             break;
56
57         ny = y;
58         nx = x;
59         mmove2(&ny, &nx, player_ptr->y, player_ptr->x, ty, tx);
60         if (get_max_range(player_ptr) <= distance(player_ptr->y, player_ptr->x, ny, nx))
61             break;
62         if (!cave_has_flag_bold(player_ptr->current_floor_ptr, ny, nx, FloorFeatureType::PROJECT))
63             break;
64         if ((dir != 5) && player_ptr->current_floor_ptr->grid_array[ny][nx].m_idx != 0)
65             break;
66
67         x = nx;
68         y = ny;
69     }
70
71     tx = x;
72     ty = y;
73
74     int b = 10 + randint1(10);
75     for (int i = 0; i < b; i++) {
76         int count = 20, d = 0;
77
78         while (count--) {
79             int dx, dy;
80
81             x = tx - 5 + randint0(11);
82             y = ty - 5 + randint0(11);
83
84             dx = (tx > x) ? (tx - x) : (x - tx);
85             dy = (ty > y) ? (ty - y) : (y - ty);
86
87             d = (dy > dx) ? (dy + (dx >> 1)) : (dx + (dy >> 1));
88             if (d < 5)
89                 break;
90         }
91
92         if (count < 0)
93             continue;
94
95         if (!in_bounds(player_ptr->current_floor_ptr, y, x) || cave_stop_disintegration(player_ptr->current_floor_ptr, y, x)
96             || !in_disintegration_range(player_ptr->current_floor_ptr, ty, tx, y, x))
97             continue;
98
99         project(player_ptr, 0, rad, y, x, dam, AttributeType::DISINTEGRATE, PROJECT_JUMP | PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL);
100     }
101
102     return true;
103 }
104
105 /*!
106  * @brief 一時的聖なるのオーラの継続時間をセットする / Set "tim_sh_holy", notice observable changes
107  * @param v 継続時間
108  * @param do_dec 現在の継続時間より長い値のみ上書きする
109  * @return ステータスに影響を及ぼす変化があった場合TRUEを返す。
110  */
111 bool set_tim_sh_holy(PlayerType *player_ptr, TIME_EFFECT v, bool do_dec)
112 {
113     bool notice = false;
114     v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
115
116     if (player_ptr->is_dead)
117         return false;
118
119     if (v) {
120         if (player_ptr->tim_sh_holy && !do_dec) {
121             if (player_ptr->tim_sh_holy > v)
122                 return false;
123         } else if (!player_ptr->tim_sh_holy) {
124             msg_print(_("体が聖なるオーラで覆われた。", "You are enveloped by a holy aura!"));
125             notice = true;
126         }
127     } else {
128         if (player_ptr->tim_sh_holy) {
129             msg_print(_("聖なるオーラが消えた。", "The holy aura disappeared."));
130             notice = true;
131         }
132     }
133
134     player_ptr->tim_sh_holy = v;
135     player_ptr->redraw |= (PR_STATUS);
136
137     if (!notice)
138         return false;
139
140     if (disturb_state)
141         disturb(player_ptr, false, false);
142     player_ptr->update |= (PU_BONUS);
143     handle_stuff(player_ptr);
144     return true;
145 }
146
147 /*!
148  * @brief 目には目をの残り時間をセットする / Set "tim_eyeeye", notice observable changes
149  * @param v 継続時間
150  * @param do_dec 現在の継続時間より長い値のみ上書きする
151  * @return ステータスに影響を及ぼす変化があった場合TRUEを返す
152  * @details 呪術領域でも使えるが、汎用性と行数の兼ね合いを考えて破邪側に入れた
153  */
154 bool set_tim_eyeeye(PlayerType *player_ptr, TIME_EFFECT v, bool do_dec)
155 {
156     bool notice = false;
157     v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
158
159     if (player_ptr->is_dead)
160         return false;
161
162     if (v) {
163         if (player_ptr->tim_eyeeye && !do_dec) {
164             if (player_ptr->tim_eyeeye > v)
165                 return false;
166         } else if (!player_ptr->tim_eyeeye) {
167             msg_print(_("法の守り手になった気がした!", "You feel like a keeper of commandments!"));
168             notice = true;
169         }
170     } else {
171         if (player_ptr->tim_eyeeye) {
172             msg_print(_("懲罰を執行することができなくなった。", "You lost your aura of retribution."));
173             notice = true;
174         }
175     }
176
177     player_ptr->tim_eyeeye = v;
178     player_ptr->redraw |= (PR_STATUS);
179
180     if (!notice)
181         return false;
182
183     if (disturb_state)
184         disturb(player_ptr, false, false);
185     player_ptr->update |= (PU_BONUS);
186     handle_stuff(player_ptr);
187     return true;
188 }