OSDN Git Service

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