OSDN Git Service

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