OSDN Git Service

[Fix] #41188 影フェアリーの反感装備ペナが機能していない
[hengband/hengband.git] / src / mind / mind-ninja.c
1 #include "mind/mind-ninja.h"
2 #include "cmd-action/cmd-attack.h"
3 #include "cmd-item/cmd-throw.h"
4 #include "combat/combat-options-type.h"
5 #include "core/disturbance.h"
6 #include "core/player-redraw-types.h"
7 #include "effect/effect-characteristics.h"
8 #include "effect/effect-processor.h"
9 #include "effect/spells-effect-util.h"
10 #include "floor/cave.h"
11 #include "floor/floor-object.h"
12 #include "floor/floor-util.h"
13 #include "game-option/disturbance-options.h"
14 #include "grid/feature.h"
15 #include "inventory/inventory-slot-types.h"
16 #include "mind/mind-mirror-master.h"
17 #include "mind/mind-numbers.h"
18 #include "mind/mind-warrior.h"
19 #include "monster-race/monster-race.h"
20 #include "monster-race/race-flags-resistance.h"
21 #include "monster-race/race-indice-types.h"
22 #include "monster/monster-describer.h"
23 #include "monster/monster-status.h"
24 #include "monster/monster-update.h"
25 #include "object-enchant/trc-types.h"
26 #include "object/object-generator.h"
27 #include "object/object-kind-hook.h"
28 #include "player/attack-defense-types.h"
29 #include "player/special-defense-types.h"
30 #include "spell-kind/spells-detection.h"
31 #include "spell-kind/spells-fetcher.h"
32 #include "spell-kind/spells-floor.h"
33 #include "spell-kind/spells-grid.h"
34 #include "spell-kind/spells-launcher.h"
35 #include "spell-kind/spells-lite.h"
36 #include "spell-kind/spells-perception.h"
37 #include "spell-kind/spells-teleport.h"
38 #include "spell/spell-types.h"
39 #include "spell/spells-status.h"
40 #include "status/action-setter.h"
41 #include "status/body-improvement.h"
42 #include "status/element-resistance.h"
43 #include "status/temporary-resistance.h"
44 #include "system/floor-type-definition.h"
45 #include "target/projection-path-calculator.h"
46 #include "target/target-checker.h"
47 #include "target/target-getter.h"
48 #include "util/bit-flags-calculator.h"
49 #include "view/display-messages.h"
50
51 /*!
52  * @brief 変わり身処理
53  * @param caster_ptr プレーヤーへの参照ポインタ
54  * @param success 判定成功上の処理ならばTRUE
55  * @return 作用が実際にあった場合TRUEを返す
56  */
57 bool kawarimi(player_type *caster_ptr, bool success)
58 {
59     object_type forge;
60     object_type *q_ptr = &forge;
61
62     if (caster_ptr->is_dead)
63         return FALSE;
64     if (caster_ptr->confused || caster_ptr->blind || caster_ptr->paralyzed || caster_ptr->image)
65         return FALSE;
66     if (randint0(200) < caster_ptr->stun)
67         return FALSE;
68
69     if (!success && one_in_(3)) {
70         msg_print(_("失敗!逃げられなかった。", "Failed! You couldn't run away."));
71         caster_ptr->special_defense &= ~(NINJA_KAWARIMI);
72         caster_ptr->redraw |= (PR_STATUS);
73         return FALSE;
74     }
75
76     POSITION y = caster_ptr->y;
77     POSITION x = caster_ptr->x;
78
79     teleport_player(caster_ptr, 10 + randint1(90), TELEPORT_SPONTANEOUS);
80     object_wipe(q_ptr);
81     const int SV_WOODEN_STATUE = 0;
82     object_prep(caster_ptr, q_ptr, lookup_kind(TV_STATUE, SV_WOODEN_STATUE));
83
84     q_ptr->pval = MON_NINJA;
85     (void)drop_near(caster_ptr, q_ptr, -1, y, x);
86
87     if (success)
88         msg_print(_("攻撃を受ける前に素早く身をひるがえした。", "You have turned around just before the attack hit you."));
89     else
90         msg_print(_("失敗!攻撃を受けてしまった。", "Failed! You are hit by the attack."));
91
92     caster_ptr->special_defense &= ~(NINJA_KAWARIMI);
93     caster_ptr->redraw |= (PR_STATUS);
94     return TRUE;
95 }
96
97 /*!
98  * @brief 入身処理 / "Rush Attack" routine for Samurai or Ninja
99  * @param caster_ptr プレーヤーへの参照ポインタ
100  * @param mdeath 目標モンスターが死亡したかを返す
101  * @return 作用が実際にあった場合TRUEを返す /  Return value is for checking "done"
102  */
103 bool rush_attack(player_type *attacker_ptr, bool *mdeath)
104 {
105     if (mdeath)
106         *mdeath = FALSE;
107
108     project_length = 5;
109     DIRECTION dir;
110     if (!get_aim_dir(attacker_ptr, &dir))
111         return FALSE;
112
113     int tx = attacker_ptr->x + project_length * ddx[dir];
114     int ty = attacker_ptr->y + project_length * ddy[dir];
115
116     if ((dir == 5) && target_okay(attacker_ptr)) {
117         tx = target_col;
118         ty = target_row;
119     }
120
121     int tm_idx = 0;
122     floor_type *floor_ptr = attacker_ptr->current_floor_ptr;
123     if (in_bounds(floor_ptr, ty, tx))
124         tm_idx = floor_ptr->grid_array[ty][tx].m_idx;
125
126     u16b path_g[32];
127     int path_n = projection_path(attacker_ptr, path_g, project_length, attacker_ptr->y, attacker_ptr->x, ty, tx, PROJECT_STOP | PROJECT_KILL);
128     project_length = 0;
129     if (!path_n)
130         return TRUE;
131
132     ty = attacker_ptr->y;
133     tx = attacker_ptr->x;
134     bool tmp_mdeath = FALSE;
135     bool moved = FALSE;
136     for (int i = 0; i < path_n; i++) {
137         monster_type *m_ptr;
138
139         int ny = get_grid_y(path_g[i]);
140         int nx = get_grid_x(path_g[i]);
141
142         if (is_cave_empty_bold(attacker_ptr, ny, nx) && player_can_enter(attacker_ptr, floor_ptr->grid_array[ny][nx].feat, 0)) {
143             ty = ny;
144             tx = nx;
145             continue;
146         }
147
148         if (!floor_ptr->grid_array[ny][nx].m_idx) {
149             if (tm_idx) {
150                 msg_print(_("失敗!", "Failed!"));
151             } else {
152                 msg_print(_("ここには入身では入れない。", "You can't move to that place."));
153             }
154
155             break;
156         }
157
158         if (!player_bold(attacker_ptr, ty, tx))
159             teleport_player_to(attacker_ptr, ty, tx, TELEPORT_NONMAGICAL);
160         update_monster(attacker_ptr, floor_ptr->grid_array[ny][nx].m_idx, TRUE);
161
162         m_ptr = &floor_ptr->m_list[floor_ptr->grid_array[ny][nx].m_idx];
163         if (tm_idx != floor_ptr->grid_array[ny][nx].m_idx) {
164 #ifdef JP
165             msg_format("%s%sが立ちふさがっている!", tm_idx ? "別の" : "", m_ptr->ml ? "モンスター" : "何か");
166 #else
167             msg_format("There is %s in the way!", m_ptr->ml ? (tm_idx ? "another monster" : "a monster") : "someone");
168 #endif
169         } else if (!player_bold(attacker_ptr, ty, tx)) {
170             GAME_TEXT m_name[MAX_NLEN];
171             monster_desc(attacker_ptr, m_name, m_ptr, 0);
172             msg_format(_("素早く%sの懐に入り込んだ!", "You quickly jump in and attack %s!"), m_name);
173         }
174
175         if (!player_bold(attacker_ptr, ty, tx))
176             teleport_player_to(attacker_ptr, ty, tx, TELEPORT_NONMAGICAL);
177         moved = TRUE;
178         tmp_mdeath = do_cmd_attack(attacker_ptr, ny, nx, HISSATSU_NYUSIN);
179
180         break;
181     }
182
183     if (!moved && !player_bold(attacker_ptr, ty, tx))
184         teleport_player_to(attacker_ptr, ty, tx, TELEPORT_NONMAGICAL);
185
186     if (mdeath)
187         *mdeath = tmp_mdeath;
188     return TRUE;
189 }
190
191 /*!
192  * @brief 盗賊と忍者における不意打ち
193  * @param attacker_ptr プレーヤーへの参照ポインタ
194  * @param pa_ptr 直接攻撃構造体への参照ポインタ
195  * @return なし
196  */
197 void process_surprise_attack(player_type *attacker_ptr, player_attack_type *pa_ptr)
198 {
199     monster_race *r_ptr = &r_info[pa_ptr->m_ptr->r_idx];
200     if (!has_melee_weapon(attacker_ptr, INVEN_RARM + pa_ptr->hand) || attacker_ptr->icky_wield[pa_ptr->hand])
201         return;
202
203     int tmp = attacker_ptr->lev * 6 + (attacker_ptr->skill_stl + 10) * 4;
204     if (attacker_ptr->monlite && (pa_ptr->mode != HISSATSU_NYUSIN))
205         tmp /= 3;
206     if (has_aggravate(attacker_ptr))
207         tmp /= 2;
208     if (r_ptr->level > (attacker_ptr->lev * attacker_ptr->lev / 20 + 10))
209         tmp /= 3;
210     if (monster_csleep_remaining(pa_ptr->m_ptr) && pa_ptr->m_ptr->ml) {
211         /* Can't backstab creatures that we can't see, right? */
212         pa_ptr->backstab = TRUE;
213     } else if ((attacker_ptr->special_defense & NINJA_S_STEALTH) && (randint0(tmp) > (r_ptr->level + 20)) && pa_ptr->m_ptr->ml
214         && !(r_ptr->flagsr & RFR_RES_ALL)) {
215         pa_ptr->surprise_attack = TRUE;
216     } else if (monster_fear_remaining(pa_ptr->m_ptr) && pa_ptr->m_ptr->ml) {
217         pa_ptr->stab_fleeing = TRUE;
218     }
219 }
220
221 void print_surprise_attack(player_attack_type *pa_ptr)
222 {
223     if (pa_ptr->backstab)
224         msg_format(_("あなたは冷酷にも眠っている無力な%sを突き刺した!", "You cruelly stab the helpless, sleeping %s!"), pa_ptr->m_name);
225     else if (pa_ptr->surprise_attack)
226         msg_format(_("不意を突いて%sに強烈な一撃を喰らわせた!", "You make surprise attack, and hit %s with a powerful blow!"), pa_ptr->m_name);
227     else if (pa_ptr->stab_fleeing)
228         msg_format(_("逃げる%sを背中から突き刺した!", "You backstab the fleeing %s!"), pa_ptr->m_name);
229     else if (!pa_ptr->monk_attack)
230         msg_format(_("%sを攻撃した。", "You hit %s."), pa_ptr->m_name);
231 }
232
233 /*!
234  * @brief 盗賊と忍者における不意打ちのダメージ計算
235  * @param attacker_ptr プレーヤーへの参照ポインタ
236  * @param pa_ptr 直接攻撃構造体への参照ポインタ
237  * @return なし
238  */
239 void calc_surprise_attack_damage(player_type *attacker_ptr, player_attack_type *pa_ptr)
240 {
241     if (pa_ptr->backstab) {
242         pa_ptr->attack_damage *= (3 + (attacker_ptr->lev / 20));
243         return;
244     }
245
246     if (pa_ptr->surprise_attack) {
247         pa_ptr->attack_damage = pa_ptr->attack_damage * (5 + (attacker_ptr->lev * 2 / 25)) / 2;
248         return;
249     }
250
251     if (pa_ptr->stab_fleeing)
252         pa_ptr->attack_damage = (3 * pa_ptr->attack_damage) / 2;
253 }
254
255 /*!
256  * @brief 速駆け処理
257  * @param creature_ptr プレーヤーへの参照ポインタ
258  * @return 常にTRUE
259  */
260 bool hayagake(player_type *creature_ptr)
261 {
262     if (creature_ptr->action == ACTION_HAYAGAKE) {
263         set_action(creature_ptr, ACTION_NONE);
264         creature_ptr->energy_use = 0;
265         return TRUE;
266     }
267
268     grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x];
269     feature_type *f_ptr = &f_info[g_ptr->feat];
270
271     if (!has_flag(f_ptr->flags, FF_PROJECT) || (!creature_ptr->levitation && has_flag(f_ptr->flags, FF_DEEP))) {
272         msg_print(_("ここでは素早く動けない。", "You cannot run in here."));
273     } else {
274         set_action(creature_ptr, ACTION_HAYAGAKE);
275     }
276
277     creature_ptr->energy_use = 0;
278     return TRUE;
279 }
280
281 /*!
282  * @brief 超隠密状態をセットする
283  * @param set TRUEならば超隠密状態になる。
284  * @return ステータスに影響を及ぼす変化があった場合TRUEを返す。
285  */
286 bool set_superstealth(player_type *creature_ptr, bool set)
287 {
288     bool notice = FALSE;
289
290     if (creature_ptr->is_dead)
291         return FALSE;
292
293     if (set) {
294         if (!(creature_ptr->special_defense & NINJA_S_STEALTH)) {
295             if (creature_ptr->current_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x].info & CAVE_MNLT) {
296                 msg_print(_("敵の目から薄い影の中に覆い隠された。", "You are mantled in weak shadow from ordinary eyes."));
297                 creature_ptr->monlite = creature_ptr->old_monlite = TRUE;
298             } else {
299                 msg_print(_("敵の目から影の中に覆い隠された!", "You are mantled in shadow from ordinary eyes!"));
300                 creature_ptr->monlite = creature_ptr->old_monlite = FALSE;
301             }
302
303             notice = TRUE;
304             creature_ptr->special_defense |= NINJA_S_STEALTH;
305         }
306     } else {
307         if (creature_ptr->special_defense & NINJA_S_STEALTH) {
308             msg_print(_("再び敵の目にさらされるようになった。", "You are exposed to common sight once more."));
309             notice = TRUE;
310             creature_ptr->special_defense &= ~(NINJA_S_STEALTH);
311         }
312     }
313
314     if (!notice)
315         return FALSE;
316     creature_ptr->redraw |= (PR_STATUS);
317
318     if (disturb_state)
319         disturb(creature_ptr, FALSE, FALSE);
320     return TRUE;
321 }
322
323 /*!
324  * @brief 忍術の発動 /
325  * do_cmd_cast calls this function if the player's class is 'ninja'.
326  * @param caster_ptr プレーヤーへの参照ポインタ
327  * @param spell 発動する特殊技能のID
328  * @return 処理を実行したらTRUE、キャンセルした場合FALSEを返す。
329  */
330 bool cast_ninja_spell(player_type *caster_ptr, mind_ninja_type spell)
331 {
332     POSITION x = 0, y = 0;
333     DIRECTION dir;
334     PLAYER_LEVEL plev = caster_ptr->lev;
335     switch (spell) {
336     case DARKNESS_CREATION:
337         (void)unlite_area(caster_ptr, 0, 3);
338         break;
339     case DETECT_NEAR:
340         if (plev > 44)
341             wiz_lite(caster_ptr, TRUE);
342
343         detect_monsters_normal(caster_ptr, DETECT_RAD_DEFAULT);
344         if (plev > 4) {
345             detect_traps(caster_ptr, DETECT_RAD_DEFAULT, TRUE);
346             detect_doors(caster_ptr, DETECT_RAD_DEFAULT);
347             detect_stairs(caster_ptr, DETECT_RAD_DEFAULT);
348         }
349
350         if (plev > 14)
351             detect_objects_normal(caster_ptr, DETECT_RAD_DEFAULT);
352
353         break;
354     case HIDE_LEAVES:
355         teleport_player(caster_ptr, 10, TELEPORT_SPONTANEOUS);
356         break;
357     case KAWARIMI:
358         if (!(caster_ptr->special_defense & NINJA_KAWARIMI)) {
359             msg_print(_("敵の攻撃に対して敏感になった。", "You are now prepared to evade any attacks."));
360             caster_ptr->special_defense |= NINJA_KAWARIMI;
361             caster_ptr->redraw |= (PR_STATUS);
362         }
363
364         break;
365     case ABSCONDING:
366         teleport_player(caster_ptr, caster_ptr->lev * 5, TELEPORT_SPONTANEOUS);
367         break;
368     case HIT_AND_AWAY:
369         if (!hit_and_away(caster_ptr))
370             return FALSE;
371
372         break;
373     case BIND_MONSTER:
374         if (!get_aim_dir(caster_ptr, &dir))
375             return FALSE;
376
377         (void)stasis_monster(caster_ptr, dir);
378         break;
379     case ANCIENT_KNOWLEDGE:
380         return ident_spell(caster_ptr, FALSE, 0);
381     case FLOATING:
382         set_tim_levitation(caster_ptr, randint1(20) + 20, FALSE);
383         break;
384     case HIDE_FLAMES:
385         fire_ball(caster_ptr, GF_FIRE, 0, 50 + plev, plev / 10 + 2);
386         teleport_player(caster_ptr, 30, TELEPORT_SPONTANEOUS);
387         set_oppose_fire(caster_ptr, (TIME_EFFECT)plev, FALSE);
388         break;
389     case NYUSIN:
390         return rush_attack(caster_ptr, NULL);
391     case SYURIKEN_SPREADING: {
392         for (int i = 0; i < 8; i++) {
393             OBJECT_IDX slot;
394
395             for (slot = 0; slot < INVEN_PACK; slot++) {
396                 if (caster_ptr->inventory_list[slot].tval == TV_SPIKE)
397                     break;
398             }
399
400             if (slot == INVEN_PACK) {
401                 if (!i)
402                     msg_print(_("くさびを持っていない。", "You have no Iron Spikes."));
403                 else
404                     msg_print(_("くさびがなくなった。", "You have no more Iron Spikes."));
405
406                 return FALSE;
407             }
408
409             do_cmd_throw(caster_ptr, 1, FALSE, slot);
410             take_turn(caster_ptr, 100);
411         }
412
413         break;
414     }
415     case CHAIN_HOOK:
416         (void)fetch_monster(caster_ptr);
417         break;
418     case SMOKE_BALL:
419         if (!get_aim_dir(caster_ptr, &dir))
420             return FALSE;
421
422         fire_ball(caster_ptr, GF_OLD_CONF, dir, plev * 3, 3);
423         break;
424     case SWAP_POSITION:
425         project_length = -1;
426         if (!get_aim_dir(caster_ptr, &dir)) {
427             project_length = 0;
428             return FALSE;
429         }
430
431         project_length = 0;
432         (void)teleport_swap(caster_ptr, dir);
433         break;
434     case EXPLOSION_GLYPH:
435         explosive_rune(caster_ptr, caster_ptr->y, caster_ptr->x);
436         break;
437     case HIDE_MUD:
438         (void)set_pass_wall(caster_ptr, randint1(plev / 2) + plev / 2, FALSE);
439         set_oppose_acid(caster_ptr, (TIME_EFFECT)plev, FALSE);
440         break;
441     case HIDE_MIST:
442         fire_ball(caster_ptr, GF_POIS, 0, 75 + plev * 2 / 3, plev / 5 + 2);
443         fire_ball(caster_ptr, GF_HYPODYNAMIA, 0, 75 + plev * 2 / 3, plev / 5 + 2);
444         fire_ball(caster_ptr, GF_CONFUSION, 0, 75 + plev * 2 / 3, plev / 5 + 2);
445         teleport_player(caster_ptr, 30, TELEPORT_SPONTANEOUS);
446         break;
447     case PURGATORY_FLAME: {
448         int num = damroll(3, 9);
449         for (int k = 0; k < num; k++) {
450             EFFECT_ID typ = one_in_(2) ? GF_FIRE : one_in_(3) ? GF_NETHER : GF_PLASMA;
451             int attempts = 1000;
452             while (attempts--) {
453                 scatter(caster_ptr, &y, &x, caster_ptr->y, caster_ptr->x, 4, PROJECT_NONE);
454                 if (!player_bold(caster_ptr, y, x))
455                     break;
456             }
457
458             project(caster_ptr, 0, 0, y, x, damroll(6 + plev / 8, 10), typ, (PROJECT_BEAM | PROJECT_THRU | PROJECT_GRID | PROJECT_KILL), -1);
459         }
460
461         break;
462     }
463     case ALTER_EGO:
464         set_multishadow(caster_ptr, 6 + randint1(6), FALSE);
465         break;
466     default:
467         msg_print(_("なに?", "Zap?"));
468         break;
469     }
470     return TRUE;
471 }