OSDN Git Service

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