OSDN Git Service

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