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 "floor/geometry.h"
14 #include "game-option/disturbance-options.h"
15 #include "grid/feature.h"
16 #include "grid/grid.h"
17 #include "inventory/inventory-slot-types.h"
18 #include "mind/mind-mirror-master.h"
19 #include "mind/mind-numbers.h"
20 #include "mind/mind-warrior.h"
21 #include "monster-race/monster-race.h"
22 #include "monster-race/race-flags-resistance.h"
23 #include "monster-race/race-indice-types.h"
24 #include "monster/monster-describer.h"
25 #include "monster/monster-status.h"
26 #include "monster/monster-update.h"
27 #include "object-enchant/trc-types.h"
28 #include "object/object-kind-hook.h"
29 #include "player-attack/player-attack-util.h"
30 #include "player-base/player-class.h"
31 #include "player-info/equipment-info.h"
32 #include "player-info/ninja-data-type.h"
33 #include "player-status/player-energy.h"
34 #include "player/attack-defense-types.h"
35 #include "player/player-status-flags.h"
36 #include "player/special-defense-types.h"
37 #include "spell-kind/spells-detection.h"
38 #include "spell-kind/spells-fetcher.h"
39 #include "spell-kind/spells-floor.h"
40 #include "spell-kind/spells-grid.h"
41 #include "spell-kind/spells-launcher.h"
42 #include "spell-kind/spells-lite.h"
43 #include "spell-kind/spells-perception.h"
44 #include "spell-kind/spells-teleport.h"
45 #include "effect/attribute-types.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-stun.h"
61 #include "timed-effect/timed-effects.h"
62 #include "util/bit-flags-calculator.h"
63 #include "view/display-messages.h"
67 * @param player_ptr プレイヤーへの参照ポインタ
68 * @param success 判定成功上の処理ならばTRUE
69 * @return 作用が実際にあった場合TRUEを返す
71 bool kawarimi(player_type *player_ptr, bool success)
73 auto ninja_data = PlayerClass(player_ptr).get_specific_data<ninja_data_type>();
74 if (!ninja_data || !ninja_data->kawarimi) {
79 object_type *q_ptr = &forge;
80 if (player_ptr->is_dead) {
84 auto effects = player_ptr->effects();
85 if (player_ptr->confused || player_ptr->blind || player_ptr->paralyzed || player_ptr->hallucinated) {
89 if (effects->stun()->current() > randint0(200)) {
93 if (!success && one_in_(3)) {
94 msg_print(_("変わり身失敗!逃げられなかった。", "Kawarimi failed! You couldn't run away."));
95 ninja_data->kawarimi = false;
96 player_ptr->redraw |= (PR_STATUS);
100 POSITION y = player_ptr->y;
101 POSITION x = player_ptr->x;
103 teleport_player(player_ptr, 10 + randint1(90), TELEPORT_SPONTANEOUS);
105 const int SV_WOODEN_STATUE = 0;
106 q_ptr->prep(lookup_kind(ItemKindType::STATUE, SV_WOODEN_STATUE));
108 q_ptr->pval = MON_NINJA;
109 (void)drop_near(player_ptr, q_ptr, -1, y, x);
112 msg_print(_("攻撃を受ける前に素早く身をひるがえした。", "You have turned around just before the attack hit you."));
114 msg_print(_("変わり身失敗!攻撃を受けてしまった。", "Kawarimi failed! You are hit by the attack."));
116 ninja_data->kawarimi = false;
117 player_ptr->redraw |= (PR_STATUS);
122 * @brief 入身処理 / "Rush Attack" routine for Samurai or Ninja
123 * @param player_ptr プレイヤーへの参照ポインタ
124 * @param mdeath 目標モンスターが死亡したかを返す
125 * @return 作用が実際にあった場合TRUEを返す / Return value is for checking "done"
127 bool rush_attack(player_type *player_ptr, bool *mdeath)
134 if (!get_aim_dir(player_ptr, &dir))
137 int tx = player_ptr->x + project_length * ddx[dir];
138 int ty = player_ptr->y + project_length * ddy[dir];
140 if ((dir == 5) && target_okay(player_ptr)) {
146 floor_type *floor_ptr = player_ptr->current_floor_ptr;
147 if (in_bounds(floor_ptr, ty, tx))
148 tm_idx = floor_ptr->grid_array[ty][tx].m_idx;
151 int path_n = projection_path(player_ptr, path_g, project_length, player_ptr->y, player_ptr->x, ty, tx, PROJECT_STOP | PROJECT_KILL);
158 bool tmp_mdeath = false;
160 for (int i = 0; i < path_n; i++) {
163 int ny = get_grid_y(path_g[i]);
164 int nx = get_grid_x(path_g[i]);
166 if (is_cave_empty_bold(player_ptr, ny, nx) && player_can_enter(player_ptr, floor_ptr->grid_array[ny][nx].feat, 0)) {
172 if (!floor_ptr->grid_array[ny][nx].m_idx) {
174 msg_print(_("失敗!", "Failed!"));
176 msg_print(_("ここには入身では入れない。", "You can't move to that place."));
182 if (!player_bold(player_ptr, ty, tx))
183 teleport_player_to(player_ptr, ty, tx, TELEPORT_NONMAGICAL);
184 update_monster(player_ptr, floor_ptr->grid_array[ny][nx].m_idx, true);
186 m_ptr = &floor_ptr->m_list[floor_ptr->grid_array[ny][nx].m_idx];
187 if (tm_idx != floor_ptr->grid_array[ny][nx].m_idx) {
189 msg_format("%s%sが立ちふさがっている!", tm_idx ? "別の" : "", m_ptr->ml ? "モンスター" : "何か");
191 msg_format("There is %s in the way!", m_ptr->ml ? (tm_idx ? "another monster" : "a monster") : "someone");
193 } else if (!player_bold(player_ptr, ty, tx)) {
194 GAME_TEXT m_name[MAX_NLEN];
195 monster_desc(player_ptr, m_name, m_ptr, 0);
196 msg_format(_("素早く%sの懐に入り込んだ!", "You quickly jump in and attack %s!"), m_name);
199 if (!player_bold(player_ptr, ty, tx))
200 teleport_player_to(player_ptr, ty, tx, TELEPORT_NONMAGICAL);
202 tmp_mdeath = do_cmd_attack(player_ptr, ny, nx, HISSATSU_NYUSIN);
207 if (!moved && !player_bold(player_ptr, ty, tx))
208 teleport_player_to(player_ptr, ty, tx, TELEPORT_NONMAGICAL);
211 *mdeath = tmp_mdeath;
216 * @brief 盗賊と忍者における不意打ち
217 * @param player_ptr プレイヤーへの参照ポインタ
218 * @param pa_ptr 直接攻撃構造体への参照ポインタ
220 void process_surprise_attack(player_type *player_ptr, player_attack_type *pa_ptr)
222 monster_race *r_ptr = &r_info[pa_ptr->m_ptr->r_idx];
223 if (!has_melee_weapon(player_ptr, INVEN_MAIN_HAND + pa_ptr->hand) || player_ptr->is_icky_wield[pa_ptr->hand])
226 int tmp = player_ptr->lev * 6 + (player_ptr->skill_stl + 10) * 4;
227 if (player_ptr->monlite && (pa_ptr->mode != HISSATSU_NYUSIN))
229 if (has_aggravate(player_ptr))
231 if (r_ptr->level > (player_ptr->lev * player_ptr->lev / 20 + 10))
234 auto ninja_data = PlayerClass(player_ptr).get_specific_data<ninja_data_type>();
235 if (monster_csleep_remaining(pa_ptr->m_ptr) && pa_ptr->m_ptr->ml) {
236 /* Can't backstab creatures that we can't see, right? */
237 pa_ptr->backstab = true;
238 } else if ((ninja_data && ninja_data->s_stealth) && (randint0(tmp) > (r_ptr->level + 20)) &&
239 pa_ptr->m_ptr->ml && !(r_ptr->flagsr & RFR_RES_ALL)) {
240 pa_ptr->surprise_attack = true;
241 } else if (monster_fear_remaining(pa_ptr->m_ptr) && pa_ptr->m_ptr->ml) {
242 pa_ptr->stab_fleeing = true;
246 void print_surprise_attack(player_attack_type *pa_ptr)
248 if (pa_ptr->backstab)
249 msg_format(_("あなたは冷酷にも眠っている無力な%sを突き刺した!", "You cruelly stab the helpless, sleeping %s!"), pa_ptr->m_name);
250 else if (pa_ptr->surprise_attack)
251 msg_format(_("不意を突いて%sに強烈な一撃を喰らわせた!", "You make surprise attack, and hit %s with a powerful blow!"), pa_ptr->m_name);
252 else if (pa_ptr->stab_fleeing)
253 msg_format(_("逃げる%sを背中から突き刺した!", "You backstab the fleeing %s!"), pa_ptr->m_name);
254 else if (!pa_ptr->monk_attack)
255 msg_format(_("%sを攻撃した。", "You hit %s."), pa_ptr->m_name);
259 * @brief 盗賊と忍者における不意打ちのダメージ計算
260 * @param player_ptr プレイヤーへの参照ポインタ
261 * @param pa_ptr 直接攻撃構造体への参照ポインタ
263 void calc_surprise_attack_damage(player_type *player_ptr, player_attack_type *pa_ptr)
265 if (pa_ptr->backstab) {
266 pa_ptr->attack_damage *= (3 + (player_ptr->lev / 20));
270 if (pa_ptr->surprise_attack) {
271 pa_ptr->attack_damage = pa_ptr->attack_damage * (5 + (player_ptr->lev * 2 / 25)) / 2;
275 if (pa_ptr->stab_fleeing)
276 pa_ptr->attack_damage = (3 * pa_ptr->attack_damage) / 2;
281 * @param player_ptr プレイヤーへの参照ポインタ
284 bool hayagake(player_type *player_ptr)
286 PlayerEnergy energy(player_ptr);
287 if (player_ptr->action == ACTION_HAYAGAKE) {
288 set_action(player_ptr, ACTION_NONE);
289 energy.reset_player_turn();
293 grid_type *g_ptr = &player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x];
294 feature_type *f_ptr = &f_info[g_ptr->feat];
296 if (f_ptr->flags.has_not(FloorFeatureType::PROJECT) || (!player_ptr->levitation && f_ptr->flags.has(FloorFeatureType::DEEP))) {
297 msg_print(_("ここでは素早く動けない。", "You cannot run in here."));
299 set_action(player_ptr, ACTION_HAYAGAKE);
302 energy.reset_player_turn();
308 * @param set TRUEならば超隠密状態になる。
309 * @return ステータスに影響を及ぼす変化があった場合TRUEを返す。
311 bool set_superstealth(player_type *player_ptr, bool set)
315 auto ninja_data = PlayerClass(player_ptr).get_specific_data<ninja_data_type>();
316 if (!ninja_data || player_ptr->is_dead)
320 if (!ninja_data->s_stealth) {
321 if (player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x].info & CAVE_MNLT) {
322 msg_print(_("敵の目から薄い影の中に覆い隠された。", "You are mantled in weak shadow from ordinary eyes."));
323 player_ptr->monlite = player_ptr->old_monlite = true;
325 msg_print(_("敵の目から影の中に覆い隠された!", "You are mantled in shadow from ordinary eyes!"));
326 player_ptr->monlite = player_ptr->old_monlite = false;
330 ninja_data->s_stealth = true;
333 if (ninja_data->s_stealth) {
334 msg_print(_("再び敵の目にさらされるようになった。", "You are exposed to common sight once more."));
336 ninja_data->s_stealth = false;
342 player_ptr->redraw |= (PR_STATUS);
345 disturb(player_ptr, false, false);
351 * do_cmd_cast calls this function if the player's class is 'ninja'.
352 * @param player_ptr プレイヤーへの参照ポインタ
353 * @param spell 発動する特殊技能のID
354 * @return 処理を実行したらTRUE、キャンセルした場合FALSEを返す。
356 bool cast_ninja_spell(player_type *player_ptr, mind_ninja_type spell)
358 POSITION x = 0, y = 0;
360 PLAYER_LEVEL plev = player_ptr->lev;
361 auto ninja_data = PlayerClass(player_ptr).get_specific_data<ninja_data_type>();
363 case DARKNESS_CREATION:
364 (void)unlite_area(player_ptr, 0, 3);
368 wiz_lite(player_ptr, true);
370 detect_monsters_normal(player_ptr, DETECT_RAD_DEFAULT);
372 detect_traps(player_ptr, DETECT_RAD_DEFAULT, true);
373 detect_doors(player_ptr, DETECT_RAD_DEFAULT);
374 detect_stairs(player_ptr, DETECT_RAD_DEFAULT);
378 detect_objects_normal(player_ptr, DETECT_RAD_DEFAULT);
382 teleport_player(player_ptr, 10, TELEPORT_SPONTANEOUS);
385 if (ninja_data && !ninja_data->kawarimi) {
386 msg_print(_("敵の攻撃に対して敏感になった。", "You are now prepared to evade any attacks."));
387 ninja_data->kawarimi = true;
388 player_ptr->redraw |= (PR_STATUS);
393 teleport_player(player_ptr, player_ptr->lev * 5, TELEPORT_SPONTANEOUS);
396 if (!hit_and_away(player_ptr))
401 if (!get_aim_dir(player_ptr, &dir))
404 (void)stasis_monster(player_ptr, dir);
406 case ANCIENT_KNOWLEDGE:
407 return ident_spell(player_ptr, false);
409 set_tim_levitation(player_ptr, randint1(20) + 20, false);
412 fire_ball(player_ptr, AttributeType::FIRE, 0, 50 + plev, plev / 10 + 2);
413 teleport_player(player_ptr, 30, TELEPORT_SPONTANEOUS);
414 set_oppose_fire(player_ptr, (TIME_EFFECT)plev, false);
417 return rush_attack(player_ptr, nullptr);
418 case SYURIKEN_SPREADING: {
419 for (int i = 0; i < 8; i++) {
422 for (slot = 0; slot < INVEN_PACK; slot++) {
423 if (player_ptr->inventory_list[slot].tval == ItemKindType::SPIKE)
427 if (slot == INVEN_PACK) {
429 msg_print(_("くさびを持っていない。", "You have no Iron Spikes."));
431 msg_print(_("くさびがなくなった。", "You have no more Iron Spikes."));
436 (void)ThrowCommand(player_ptr).do_cmd_throw(1, false, slot);
437 PlayerEnergy(player_ptr).set_player_turn_energy(100);
443 (void)fetch_monster(player_ptr);
446 if (!get_aim_dir(player_ptr, &dir))
449 fire_ball(player_ptr, AttributeType::OLD_CONF, dir, plev * 3, 3);
453 if (!get_aim_dir(player_ptr, &dir)) {
459 (void)teleport_swap(player_ptr, dir);
462 create_rune_explosion(player_ptr, player_ptr->y, player_ptr->x);
465 (void)set_pass_wall(player_ptr, randint1(plev / 2) + plev / 2, false);
466 set_oppose_acid(player_ptr, (TIME_EFFECT)plev, false);
469 fire_ball(player_ptr, AttributeType::POIS, 0, 75 + plev * 2 / 3, plev / 5 + 2);
470 fire_ball(player_ptr, AttributeType::HYPODYNAMIA, 0, 75 + plev * 2 / 3, plev / 5 + 2);
471 fire_ball(player_ptr, AttributeType::CONFUSION, 0, 75 + plev * 2 / 3, plev / 5 + 2);
472 teleport_player(player_ptr, 30, TELEPORT_SPONTANEOUS);
474 case PURGATORY_FLAME: {
475 int num = damroll(3, 9);
476 for (int k = 0; k < num; k++) {
477 AttributeType typ = one_in_(2) ? AttributeType::FIRE : one_in_(3) ? AttributeType::NETHER : AttributeType::PLASMA;
480 scatter(player_ptr, &y, &x, player_ptr->y, player_ptr->x, 4, PROJECT_NONE);
481 if (!player_bold(player_ptr, y, x))
485 project(player_ptr, 0, 0, y, x, damroll(6 + plev / 8, 10), typ, (PROJECT_BEAM | PROJECT_THRU | PROJECT_GRID | PROJECT_KILL));
491 set_multishadow(player_ptr, 6 + randint1(6), false);
494 msg_print(_("なに?", "Zap?"));