OSDN Git Service

[Refactor] #40653 Separated mind-archer.c/h from spells-object.c/h
[hengband/hengband.git] / src / mind / mind-force-trainer.c
1 #include "mind/mind-force-trainer.h"
2 #include "cmd-action/cmd-pet.h"
3 #include "core/disturbance.h"
4 #include "core/player-redraw-types.h"
5 #include "core/player-update-types.h"
6 #include "core/stuff-handler.h"
7 #include "effect/spells-effect-util.h"
8 #include "floor/cave.h"
9 #include "floor/geometry.h"
10 #include "game-option/disturbance-options.h"
11 #include "grid/grid.h"
12 #include "mind/mind-magic-resistance.h"
13 #include "mind/mind-numbers.h"
14 #include "monster-floor/monster-summon.h"
15 #include "monster-floor/place-monster-types.h"
16 #include "monster-race/monster-race.h"
17 #include "monster-race/race-flags7.h"
18 #include "monster/monster-describer.h"
19 #include "monster/monster-status.h"
20 #include "monster/monster-update.h"
21 #include "player-info/avatar.h"
22 #include "player/player-damage.h"
23 #include "spell-kind/spells-launcher.h"
24 #include "spell-kind/spells-lite.h"
25 #include "spell/spells-summon.h"
26 #include "spell/spell-types.h"
27 #include "status/temporary-resistance.h"
28 #include "system/floor-type-definition.h"
29 #include "target/projection-path-calculator.h"
30 #include "target/target-checker.h"
31 #include "target/target-getter.h"
32 #include "target/target-setter.h"
33 #include "target/target-types.h"
34 #include "view/display-messages.h"
35
36 /*!
37  * @brief 練気術師が「練気」で溜めた気の量を返す
38  * @param caster_ptr プレーヤーの参照ポインタ
39  * @return 現在溜まっている気の量
40  */
41 MAGIC_NUM1 get_current_ki(player_type *caster_ptr) { return caster_ptr->magic_num1[0]; }
42
43 /*!
44  * @brief 練気術師において、気を溜める
45  * @param caster_ptr プレーヤーの参照ポインタ
46  * @param is_reset TRUEなら気の量をkiにセットし、FALSEなら加減算を行う
47  * @param ki 気の量
48  * @return なし
49  */
50 void set_current_ki(player_type *caster_ptr, bool is_reset, MAGIC_NUM1 ki)
51 {
52     if (is_reset) {
53         caster_ptr->magic_num1[0] = ki;
54         return;
55     }
56
57     caster_ptr->magic_num1[0] += ki;
58 }
59
60 bool clear_mind(player_type *creature_ptr)
61 {
62     if (total_friends) {
63         msg_print(_("今はペットを操ることに集中していないと。", "Your pets demand all of your attention."));
64         return FALSE;
65     }
66
67     msg_print(_("少し頭がハッキリした。", "You feel your head clear a little."));
68
69     creature_ptr->csp += (3 + creature_ptr->lev / 20);
70     if (creature_ptr->csp >= creature_ptr->msp) {
71         creature_ptr->csp = creature_ptr->msp;
72         creature_ptr->csp_frac = 0;
73     }
74
75     creature_ptr->redraw |= (PR_MANA);
76     return TRUE;
77 }
78
79 /*!
80  * @brief 光速移動の継続時間をセットする / Set "lightspeed", notice observable changes
81  * @param v 継続時間
82  * @param do_dec 現在の継続時間より長い値のみ上書きする
83  * @return なし
84  */
85 void set_lightspeed(player_type *creature_ptr, TIME_EFFECT v, bool do_dec)
86 {
87     bool notice = FALSE;
88     v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
89
90     if (creature_ptr->is_dead)
91         return;
92
93     if (creature_ptr->wild_mode)
94         v = 0;
95
96     if (v) {
97         if (creature_ptr->lightspeed && !do_dec) {
98             if (creature_ptr->lightspeed > v)
99                 return;
100         } else if (!creature_ptr->lightspeed) {
101             msg_print(_("非常に素早く動けるようになった!", "You feel yourself moving extremely fast!"));
102             notice = TRUE;
103             chg_virtue(creature_ptr, V_PATIENCE, -1);
104             chg_virtue(creature_ptr, V_DILIGENCE, 1);
105         }
106     } else {
107         if (creature_ptr->lightspeed) {
108             msg_print(_("動きの素早さがなくなったようだ。", "You feel yourself slow down."));
109             notice = TRUE;
110         }
111     }
112
113     creature_ptr->lightspeed = v;
114
115     if (!notice)
116         return;
117
118     if (disturb_state)
119         disturb(creature_ptr, FALSE, FALSE);
120     creature_ptr->update |= (PU_BONUS);
121     handle_stuff(creature_ptr);
122 }
123
124 /*!
125  * @brief 一時的闘気のオーラの継続時間をセットする / Set "tim_sh_touki", notice observable changes
126  * @param v 継続時間
127  * @param do_dec 現在の継続時間より長い値のみ上書きする
128  * @return ステータスに影響を及ぼす変化があった場合TRUEを返す。
129  */
130 bool set_tim_sh_force(player_type *creature_ptr, TIME_EFFECT v, bool do_dec)
131 {
132     bool notice = FALSE;
133     v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
134
135     if (creature_ptr->is_dead)
136         return FALSE;
137
138     if (v) {
139         if (creature_ptr->tim_sh_touki && !do_dec) {
140             if (creature_ptr->tim_sh_touki > v)
141                 return FALSE;
142         } else if (!creature_ptr->tim_sh_touki) {
143             msg_print(_("体が闘気のオーラで覆われた。", "You are enveloped by an aura of the Force!"));
144             notice = TRUE;
145         }
146     } else {
147         if (creature_ptr->tim_sh_touki) {
148             msg_print(_("闘気が消えた。", "The aura of the Force disappeared."));
149             notice = TRUE;
150         }
151     }
152
153     creature_ptr->tim_sh_touki = v;
154     creature_ptr->redraw |= (PR_STATUS);
155
156     if (!notice)
157         return FALSE;
158
159     if (disturb_state)
160         disturb(creature_ptr, FALSE, FALSE);
161     handle_stuff(creature_ptr);
162     return TRUE;
163 }
164
165 /*!
166  * @brief 衝波
167  * @param caster_ptr プレーヤーへの参照ポインタ
168  * @return 命中したらTRUE
169  */
170 bool shock_power(player_type *caster_ptr)
171 {
172     int boost = get_current_ki(caster_ptr);
173     if (heavy_armor(caster_ptr))
174         boost /= 2;
175
176     project_length = 1;
177     DIRECTION dir;
178     if (!get_aim_dir(caster_ptr, &dir))
179         return FALSE;
180
181     POSITION y = caster_ptr->y + ddy[dir];
182     POSITION x = caster_ptr->x + ddx[dir];
183     PLAYER_LEVEL plev = caster_ptr->lev;
184     HIT_POINT dam = damroll(8 + ((plev - 5) / 4) + boost / 12, 8);
185     fire_beam(caster_ptr, GF_MISSILE, dir, dam);
186     if (!caster_ptr->current_floor_ptr->grid_array[y][x].m_idx)
187         return TRUE;
188
189     POSITION ty = y, tx = x;
190     POSITION oy = y, ox = x;
191     MONSTER_IDX m_idx = caster_ptr->current_floor_ptr->grid_array[y][x].m_idx;
192     monster_type *m_ptr = &caster_ptr->current_floor_ptr->m_list[m_idx];
193     monster_race *r_ptr = &r_info[m_ptr->r_idx];
194     GAME_TEXT m_name[MAX_NLEN];
195     monster_desc(caster_ptr, m_name, m_ptr, 0);
196
197     if (randint1(r_ptr->level * 3 / 2) > randint0(dam / 2) + dam / 2) {
198         msg_format(_("%sは飛ばされなかった。", "%^s was not blown away."), m_name);
199         return TRUE;
200     }
201
202     for (int i = 0; i < 5; i++) {
203         y += ddy[dir];
204         x += ddx[dir];
205         if (is_cave_empty_bold(caster_ptr, y, x)) {
206             ty = y;
207             tx = x;
208         } else {
209             break;
210         }
211     }
212
213     bool is_shock_successful = ty != oy;
214     is_shock_successful |= tx != ox;
215     if (is_shock_successful)
216         return TRUE;
217
218     msg_format(_("%sを吹き飛ばした!", "You blow %s away!"), m_name);
219     caster_ptr->current_floor_ptr->grid_array[oy][ox].m_idx = 0;
220     caster_ptr->current_floor_ptr->grid_array[ty][tx].m_idx = m_idx;
221     m_ptr->fy = ty;
222     m_ptr->fx = tx;
223
224     update_monster(caster_ptr, m_idx, TRUE);
225     lite_spot(caster_ptr, oy, ox);
226     lite_spot(caster_ptr, ty, tx);
227
228     if (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
229         caster_ptr->update |= (PU_MON_LITE);
230
231     return TRUE;
232 }
233
234 /*!
235  * @brief 練気術の発動 /
236  * do_cmd_cast calls this function if the player's class is 'ForceTrainer'.
237  * @param spell 発動する特殊技能のID
238  * @return 処理を実行したらTRUE、キャンセルした場合FALSEを返す。
239  */
240 bool cast_force_spell(player_type *caster_ptr, mind_force_trainer_type spell)
241 {
242     DIRECTION dir;
243     PLAYER_LEVEL plev = caster_ptr->lev;
244     int boost = get_current_ki(caster_ptr);
245     if (heavy_armor(caster_ptr))
246         boost /= 2;
247
248     switch (spell) {
249     case SMALL_FORCE_BALL:
250         if (!get_aim_dir(caster_ptr, &dir))
251             return FALSE;
252
253         fire_ball(caster_ptr, GF_MISSILE, dir, damroll(3 + ((plev - 1) / 5) + boost / 12, 4), 0);
254         break;
255     case FLASH_LIGHT:
256         (void)lite_area(caster_ptr, damroll(2, (plev / 2)), (plev / 10) + 1);
257         break;
258     case FLYING_TECHNIQUE:
259         set_tim_levitation(caster_ptr, randint1(30) + 30 + boost / 5, FALSE);
260         break;
261     case KAMEHAMEHA:
262         project_length = plev / 8 + 3;
263         if (!get_aim_dir(caster_ptr, &dir))
264             return FALSE;
265
266         fire_beam(caster_ptr, GF_MISSILE, dir, damroll(5 + ((plev - 1) / 5) + boost / 10, 5));
267         break;
268     case MAGIC_RESISTANCE:
269         set_resist_magic(caster_ptr, randint1(20) + 20 + boost / 5, FALSE);
270         break;
271     case IMPROVE_FORCE:
272         msg_print(_("気を練った。", "You improved the Force."));
273         set_current_ki(caster_ptr, FALSE, 70 + plev);
274         caster_ptr->update |= (PU_BONUS);
275         if (randint1(get_current_ki(caster_ptr)) > (plev * 4 + 120)) {
276             msg_print(_("気が暴走した!", "The Force exploded!"));
277             fire_ball(caster_ptr, GF_MANA, 0, get_current_ki(caster_ptr) / 2, 10);
278             take_hit(caster_ptr, DAMAGE_LOSELIFE, caster_ptr->magic_num1[0] / 2, _("気の暴走", "Explosion of the Force"), -1);
279         } else
280             return TRUE;
281
282         break;
283     case AURA_OF_FORCE:
284         set_tim_sh_force(caster_ptr, randint1(plev / 2) + 15 + boost / 7, FALSE);
285         break;
286     case SHOCK_POWER:
287         return shock_power(caster_ptr);
288         break;
289     case LARGE_FORCE_BALL:
290         if (!get_aim_dir(caster_ptr, &dir))
291             return FALSE;
292
293         fire_ball(caster_ptr, GF_MISSILE, dir, damroll(10, 6) + plev * 3 / 2 + boost * 3 / 5, (plev < 30) ? 2 : 3);
294         break;
295     case DISPEL_MAGIC: {
296         if (!target_set(caster_ptr, TARGET_KILL))
297             return FALSE;
298
299         MONSTER_IDX m_idx = caster_ptr->current_floor_ptr->grid_array[target_row][target_col].m_idx;
300         if ((m_idx == 0) || !player_has_los_bold(caster_ptr, target_row, target_col)
301             || !projectable(caster_ptr, caster_ptr->y, caster_ptr->x, target_row, target_col))
302             break;
303
304         dispel_monster_status(caster_ptr, m_idx);
305         break;
306     }
307     case SUMMON_GHOST: {
308         bool success = FALSE;
309         for (int i = 0; i < 1 + boost / 100; i++)
310             if (summon_specific(caster_ptr, -1, caster_ptr->y, caster_ptr->x, plev, SUMMON_PHANTOM, PM_FORCE_PET))
311                 success = TRUE;
312
313         if (success)
314             msg_print(_("御用でございますが、御主人様?", "'Your wish, master?'"));
315         else
316             msg_print(_("何も現れなかった。", "Nothing happen."));
317
318         break;
319     }
320     case EXPLODING_FLAME:
321         fire_ball(caster_ptr, GF_FIRE, 0, 200 + (2 * plev) + boost * 2, 10);
322         break;
323     case SUPER_KAMEHAMEHA:
324         if (!get_aim_dir(caster_ptr, &dir))
325             return FALSE;
326
327         fire_beam(caster_ptr, GF_MANA, dir, damroll(10 + (plev / 2) + boost * 3 / 10, 15));
328         break;
329     case LIGHT_SPEED:
330         set_lightspeed(caster_ptr, randint1(16) + 16 + boost / 20, FALSE);
331         break;
332     default:
333         msg_print(_("なに?", "Zap?"));
334     }
335
336     set_current_ki(caster_ptr, TRUE, 0);
337     caster_ptr->update |= PU_BONUS;
338     return TRUE;
339 }