OSDN Git Service

[Refactor] #40521 Separated inventory-slot-types.h from player-status.h
[hengbandforosx/hengbandosx.git] / src / monster-attack / monster-attack-player.c
1 /*!
2  * @brief モンスターからプレーヤーへの直接攻撃処理
3  * @date 2020/05/23
4  * @author Hourier
5  */
6
7 #include "monster-attack/monster-attack-player.h"
8 #include "cmd-action/cmd-attack.h"
9 #include "cmd-action/cmd-pet.h"
10 #include "combat/attack-accuracy.h"
11 #include "combat/attack-criticality.h"
12 #include "combat/aura-counterattack.h"
13 #include "combat/combat-options-type.h"
14 #include "combat/hallucination-attacks-table.h"
15 #include "dungeon/dungeon.h"
16 #include "effect/effect-characteristics.h"
17 #include "inventory/inventory-slot-types.h"
18 #include "main/sound-definitions-table.h"
19 #include "main/sound-of-music.h"
20 #include "mind/mind-ninja.h"
21 #include "mind/mind-samurai.h"
22 #include "monster-attack/monster-attack-describer.h"
23 #include "monster-attack/monster-attack-effect.h"
24 #include "monster-attack/monster-attack-switcher.h"
25 #include "monster-attack/monster-attack-util.h"
26 #include "monster-race/monster-race.h"
27 #include "monster-race/race-flags1.h"
28 #include "monster-race/race-flags3.h"
29 #include "monster/monster-description-types.h"
30 #include "monster/monster-describer.h"
31 #include "monster/monster-status.h"
32 #include "monster/monster-info.h"
33 #include "monster/smart-learn-types.h"
34 #include "object-hook/hook-armor.h"
35 #include "object/item-tester-hooker.h"
36 #include "pet/pet-fall-off.h"
37 #include "player/player-damage.h"
38 #include "status/action-setter.h"
39 #include "player/player-move.h"
40 #include "player/player-skill.h"
41 #include "player/special-defense-types.h"
42 #include "realm/realm-hex-numbers.h"
43 #include "spell-realm/spells-crusade.h"
44 #include "spell-kind/spells-teleport.h"
45 #include "spell-realm/spells-hex.h"
46 #include "spell/process-effect.h"
47 #include "spell/spell-types.h"
48 #include "status/bad-status-setter.h"
49 #include "view/display-messages.h"
50
51 static bool check_no_blow(player_type *target_ptr, monap_type *monap_ptr)
52 {
53     monster_race *r_ptr = &r_info[monap_ptr->m_ptr->r_idx];
54     if (r_ptr->flags1 & (RF1_NEVER_BLOW))
55         return FALSE;
56
57     if (d_info[target_ptr->dungeon_idx].flags1 & DF1_NO_MELEE)
58         return FALSE;
59
60     if (!is_hostile(monap_ptr->m_ptr))
61         return FALSE;
62
63     return TRUE;
64 }
65
66 /*!
67  * @brief プレーヤー死亡等でモンスターからプレーヤーへの直接攻撃処理を途中で打ち切るかどうかを判定する
68  * @param target_ptr プレーヤーへの参照ポインタ
69  * @param monap_ptr モンスターからプレーヤーへの直接攻撃構造体への参照ポインタ
70  * @return 攻撃続行ならばTRUE、打ち切りになったらFALSE
71  */
72 static bool check_monster_attack_terminated(player_type *target_ptr, monap_type *monap_ptr)
73 {
74     if (!monster_is_valid(monap_ptr->m_ptr))
75         return FALSE;
76
77     if (monap_ptr->method == RBM_NONE)
78         return FALSE;
79
80     monster_race *r_ptr = &r_info[monap_ptr->m_ptr->r_idx];
81     if (is_pet(monap_ptr->m_ptr) && (r_ptr->flags1 & RF1_UNIQUE) && (monap_ptr->method == RBM_EXPLODE)) {
82         monap_ptr->method = RBM_HIT;
83         monap_ptr->d_dice /= 10;
84     }
85
86     if (!target_ptr->playing || target_ptr->is_dead || (distance(target_ptr->y, target_ptr->x, monap_ptr->m_ptr->fy, monap_ptr->m_ptr->fx) > 1)
87         || target_ptr->leaving)
88         return FALSE;
89
90     return TRUE;
91 }
92
93 /*!
94  * @brief 対邪悪結界が効いている状態で邪悪なモンスターから直接攻撃を受けた時の処理
95  * @param target_ptr プレーヤーへの参照ポインタ
96  * @param monap_ptr モンスターからプレーヤーへの直接攻撃構造体への参照ポインタ
97  * @return briefに書いた条件+確率が満たされたらTRUE、それ以外はFALSE
98  */
99 static bool effect_protecion_from_evil(player_type *target_ptr, monap_type *monap_ptr)
100 {
101     monster_race *r_ptr = &r_info[monap_ptr->m_ptr->r_idx];
102     if ((target_ptr->protevil <= 0) || ((r_ptr->flags3 & RF3_EVIL) == 0) || (target_ptr->lev < monap_ptr->rlev) || ((randint0(100) + target_ptr->lev) <= 50))
103         return FALSE;
104
105     if (is_original_ap_and_seen(target_ptr, monap_ptr->m_ptr))
106         r_ptr->r_flags3 |= RF3_EVIL;
107
108 #ifdef JP
109     if (monap_ptr->abbreviate)
110         msg_format("撃退した。");
111     else
112         msg_format("%^sは撃退された。", monap_ptr->m_name);
113
114     monap_ptr->abbreviate = 1; /* 2回目以降は省略 */
115 #else
116     msg_format("%^s is repelled.", monap_ptr->m_name);
117 #endif
118
119     return TRUE;
120 }
121
122 static void describe_silly_attacks(monap_type *monap_ptr)
123 {
124     if (monap_ptr->act == NULL)
125         return;
126
127     if (monap_ptr->do_silly_attack) {
128 #ifdef JP
129         monap_ptr->abbreviate = -1;
130 #endif
131         monap_ptr->act = silly_attacks[randint0(MAX_SILLY_ATTACK)];
132     }
133
134 #ifdef JP
135     if (monap_ptr->abbreviate == 0)
136         msg_format("%^sに%s", monap_ptr->m_name, monap_ptr->act);
137     else if (monap_ptr->abbreviate == 1)
138         msg_format("%s", monap_ptr->act);
139     else /* if (monap_ptr->abbreviate == -1) */
140         msg_format("%^s%s", monap_ptr->m_name, monap_ptr->act);
141
142     monap_ptr->abbreviate = 1; /*2回目以降は省略 */
143 #else
144     msg_format("%^s %s%s", monap_ptr->m_name, monap_ptr->act, monap_ptr->do_silly_attack ? " you." : "");
145 #endif
146 }
147
148 /*!
149  * @brief 切り傷と朦朧が同時に発生した時、片方を無効にする
150  * @param monap_ptr モンスターからプレーヤーへの直接攻撃構造体への参照ポインタ
151  * @return なし
152  */
153 static void select_cut_stun(monap_type *monap_ptr)
154 {
155     if ((monap_ptr->do_cut == 0) || (monap_ptr->do_stun == 0))
156         return;
157
158     if (randint0(100) < 50)
159         monap_ptr->do_cut = 0;
160     else
161         monap_ptr->do_stun = 0;
162 }
163
164 static void calc_player_cut(player_type *target_ptr, monap_type *monap_ptr)
165 {
166     if (monap_ptr->do_cut == 0)
167         return;
168
169     int cut_plus = 0;
170     int criticality = calc_monster_critical(monap_ptr->d_dice, monap_ptr->d_side, monap_ptr->damage);
171     switch (criticality) {
172     case 0:
173         cut_plus = 0;
174         break;
175     case 1:
176         cut_plus = randint1(5);
177         break;
178     case 2:
179         cut_plus = randint1(5) + 5;
180         break;
181     case 3:
182         cut_plus = randint1(20) + 20;
183         break;
184     case 4:
185         cut_plus = randint1(50) + 50;
186         break;
187     case 5:
188         cut_plus = randint1(100) + 100;
189         break;
190     case 6:
191         cut_plus = 300;
192         break;
193     default:
194         cut_plus = 500;
195         break;
196     }
197
198     if (cut_plus > 0)
199         (void)set_cut(target_ptr, target_ptr->cut + cut_plus);
200 }
201
202 static void calc_player_stun(player_type *target_ptr, monap_type *monap_ptr)
203 {
204     if (monap_ptr->do_stun == 0)
205         return;
206
207     int stun_plus = 0;
208     int criticality = calc_monster_critical(monap_ptr->d_dice, monap_ptr->d_side, monap_ptr->damage);
209     switch (criticality) {
210     case 0:
211         stun_plus = 0;
212         break;
213     case 1:
214         stun_plus = randint1(5);
215         break;
216     case 2:
217         stun_plus = randint1(5) + 10;
218         break;
219     case 3:
220         stun_plus = randint1(10) + 20;
221         break;
222     case 4:
223         stun_plus = randint1(15) + 30;
224         break;
225     case 5:
226         stun_plus = randint1(20) + 40;
227         break;
228     case 6:
229         stun_plus = 80;
230         break;
231     default:
232         stun_plus = 150;
233         break;
234     }
235
236     if (stun_plus > 0)
237         (void)set_stun(target_ptr, target_ptr->stun + stun_plus);
238 }
239
240 static void monster_explode(player_type *target_ptr, monap_type *monap_ptr)
241 {
242     if (!monap_ptr->explode)
243         return;
244
245     sound(SOUND_EXPLODE);
246     if (mon_take_hit(target_ptr, monap_ptr->m_idx, monap_ptr->m_ptr->hp + 1, &monap_ptr->fear, NULL)) {
247         monap_ptr->blinked = FALSE;
248         monap_ptr->alive = FALSE;
249     }
250 }
251
252 static void describe_attack_evasion(player_type *target_ptr, monap_type *monap_ptr)
253 {
254     if (!monap_ptr->m_ptr->ml)
255         return;
256
257     disturb(target_ptr, TRUE, TRUE);
258 #ifdef JP
259     if (monap_ptr->abbreviate)
260         msg_format("%sかわした。", (target_ptr->special_attack & ATTACK_SUIKEN) ? "奇妙な動きで" : "");
261     else
262         msg_format("%s%^sの攻撃をかわした。", (target_ptr->special_attack & ATTACK_SUIKEN) ? "奇妙な動きで" : "", monap_ptr->m_name);
263
264     monap_ptr->abbreviate = 1; /* 2回目以降は省略 */
265 #else
266     msg_format("%^s misses you.", monap_ptr->m_name);
267 #endif
268 }
269
270 static void gain_armor_exp(player_type *target_ptr, monap_type *monap_ptr)
271 {
272     if (!object_is_armour(target_ptr, &target_ptr->inventory_list[INVEN_RARM]) && !object_is_armour(target_ptr, &target_ptr->inventory_list[INVEN_LARM]))
273         return;
274
275     int cur = target_ptr->skill_exp[GINOU_SHIELD];
276     int max = s_info[target_ptr->pclass].s_max[GINOU_SHIELD];
277     if (cur >= max)
278         return;
279
280     monster_race *r_ptr = &r_info[monap_ptr->m_ptr->r_idx];
281     DEPTH targetlevel = r_ptr->level;
282     int inc = 0;
283     if ((cur / 100) < targetlevel) {
284         if ((cur / 100 + 15) < targetlevel)
285             inc += 1 + (targetlevel - (cur / 100 + 15));
286         else
287             inc += 1;
288     }
289
290     target_ptr->skill_exp[GINOU_SHIELD] = MIN(max, cur + inc);
291     target_ptr->update |= (PU_BONUS);
292 }
293
294 /*!
295  * @brief モンスターから直接攻撃を1回受けた時の処理
296  * @return 対邪悪結界により攻撃が当たらなかったらFALSE、それ以外はTRUE
297  * @param target_ptr プレーヤーへの参照ポインタ
298  * @param monap_ptr モンスターからプレーヤーへの直接攻撃構造体への参照ポインタ
299  * @details 最大4 回/モンスター/ターン、このルーチンを通る
300  */
301 static bool process_monster_attack_hit(player_type *target_ptr, monap_type *monap_ptr)
302 {
303     disturb(target_ptr, TRUE, TRUE);
304     if (effect_protecion_from_evil(target_ptr, monap_ptr))
305         return FALSE;
306
307     monap_ptr->do_cut = 0;
308     monap_ptr->do_stun = 0;
309     describe_monster_attack_method(monap_ptr);
310     describe_silly_attacks(monap_ptr);
311     monap_ptr->obvious = TRUE;
312     monap_ptr->damage = damroll(monap_ptr->d_dice, monap_ptr->d_side);
313     if (monap_ptr->explode)
314         monap_ptr->damage = 0;
315
316     switch_monster_blow_to_player(target_ptr, monap_ptr);
317     select_cut_stun(monap_ptr);
318     calc_player_cut(target_ptr, monap_ptr);
319     calc_player_stun(target_ptr, monap_ptr);
320     monster_explode(target_ptr, monap_ptr);
321     process_aura_counterattack(target_ptr, monap_ptr);
322     return TRUE;
323 }
324
325 /*!
326  * @brief 一部の打撃種別の場合のみ、避けた旨のメッセージ表示と盾技能スキル向上を行う
327  * @param target_ptr プレーヤーへの参照ポインタ
328  * @param monap_ptr モンスターからプレーヤーへの直接攻撃構造体への参照ポインタ
329  * @return なし
330  */
331 static void process_monster_attack_evasion(player_type *target_ptr, monap_type *monap_ptr)
332 {
333     switch (monap_ptr->method) {
334     case RBM_HIT:
335     case RBM_TOUCH:
336     case RBM_PUNCH:
337     case RBM_KICK:
338     case RBM_CLAW:
339     case RBM_BITE:
340     case RBM_STING:
341     case RBM_SLASH:
342     case RBM_BUTT:
343     case RBM_CRUSH:
344     case RBM_ENGULF:
345     case RBM_CHARGE:
346         describe_attack_evasion(target_ptr, monap_ptr);
347         gain_armor_exp(target_ptr, monap_ptr);
348         monap_ptr->damage = 0;
349         return;
350     default:
351         return;
352     }
353 }
354
355 static void increase_blow_type_seen(player_type *target_ptr, monap_type *monap_ptr)
356 {
357     if (!is_original_ap_and_seen(target_ptr, monap_ptr->m_ptr) || monap_ptr->do_silly_attack)
358         return;
359
360     monster_race *r_ptr = &r_info[monap_ptr->m_ptr->r_idx];
361     if (!monap_ptr->obvious && (monap_ptr->damage == 0) && (r_ptr->r_blows[monap_ptr->ap_cnt] <= 10))
362         return;
363
364     if (r_ptr->r_blows[monap_ptr->ap_cnt] < MAX_UCHAR)
365         r_ptr->r_blows[monap_ptr->ap_cnt]++;
366 }
367
368 static bool process_monster_blows(player_type *target_ptr, monap_type *monap_ptr)
369 {
370     monster_race *r_ptr = &r_info[monap_ptr->m_ptr->r_idx];
371     for (monap_ptr->ap_cnt = 0; monap_ptr->ap_cnt < 4; monap_ptr->ap_cnt++) {
372         monap_ptr->obvious = FALSE;
373         HIT_POINT power = 0;
374         monap_ptr->damage = 0;
375         monap_ptr->act = NULL;
376         monap_ptr->effect = r_ptr->blow[monap_ptr->ap_cnt].effect;
377         monap_ptr->method = r_ptr->blow[monap_ptr->ap_cnt].method;
378         monap_ptr->d_dice = r_ptr->blow[monap_ptr->ap_cnt].d_dice;
379         monap_ptr->d_side = r_ptr->blow[monap_ptr->ap_cnt].d_side;
380
381         if (!check_monster_attack_terminated(target_ptr, monap_ptr))
382             break;
383
384         if (monap_ptr->method == RBM_SHOOT)
385             continue;
386
387         power = mbe_info[monap_ptr->effect].power;
388         monap_ptr->ac = target_ptr->ac + target_ptr->to_a;
389         if ((monap_ptr->effect == RBE_NONE)
390             || check_hit_from_monster_to_player(target_ptr, power, monap_ptr->rlev, monster_stunned_remaining(monap_ptr->m_ptr)))
391             if (!process_monster_attack_hit(target_ptr, monap_ptr))
392                 continue;
393             else
394                 process_monster_attack_evasion(target_ptr, monap_ptr);
395
396         increase_blow_type_seen(target_ptr, monap_ptr);
397         check_fall_off_horse(target_ptr, monap_ptr);
398         if (target_ptr->special_defense & NINJA_KAWARIMI) {
399             if (kawarimi(target_ptr, FALSE))
400                 return TRUE;
401         }
402     }
403
404     return FALSE;
405 }
406
407 /*!
408  * @brief 呪術「目には目を」の効果処理
409  * @param target_ptr プレーヤーへの参照ポインタ
410  * @param monap_ptr モンスターからプレーヤーへの直接攻撃構造体への参照ポインタ
411  * @return なし
412  */
413 static void eyes_on_eyes(player_type *target_ptr, monap_type *monap_ptr)
414 {
415     if (((target_ptr->tim_eyeeye == 0) && !hex_spelling(target_ptr, HEX_EYE_FOR_EYE)) || (monap_ptr->get_damage == 0) || target_ptr->is_dead)
416         return;
417
418 #ifdef JP
419     msg_format("攻撃が%s自身を傷つけた!", monap_ptr->m_name);
420 #else
421     GAME_TEXT m_name_self[80];
422     monster_desc(target_ptr, m_name_self, monap_ptr->m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE | MD_OBJECTIVE);
423     msg_format("The attack of %s has wounded %s!", monap_ptr->m_name, m_name_self);
424 #endif
425     project(target_ptr, 0, 0, monap_ptr->m_ptr->fy, monap_ptr->m_ptr->fx, monap_ptr->get_damage, GF_MISSILE, PROJECT_KILL, -1);
426     if (target_ptr->tim_eyeeye)
427         set_tim_eyeeye(target_ptr, target_ptr->tim_eyeeye - 5, TRUE);
428 }
429
430 static void thief_teleport(player_type *target_ptr, monap_type *monap_ptr)
431 {
432     if (!monap_ptr->blinked || !monap_ptr->alive || target_ptr->is_dead)
433         return;
434
435     if (teleport_barrier(target_ptr, monap_ptr->m_idx)) {
436         msg_print(_("泥棒は笑って逃げ...ようとしたがバリアに防がれた。", "The thief flees laughing...? But a magic barrier obstructs it."));
437     } else {
438         msg_print(_("泥棒は笑って逃げた!", "The thief flees laughing!"));
439         teleport_away(target_ptr, monap_ptr->m_idx, MAX_SIGHT * 2 + 5, TELEPORT_SPONTANEOUS);
440     }
441 }
442
443 static void postprocess_monster_blows(player_type *target_ptr, monap_type *monap_ptr)
444 {
445     revenge_store(target_ptr, monap_ptr->get_damage);
446     eyes_on_eyes(target_ptr, monap_ptr);
447     musou_counterattack(target_ptr, monap_ptr);
448     thief_teleport(target_ptr, monap_ptr);
449     monster_race *r_ptr = &r_info[monap_ptr->m_ptr->r_idx];
450     if (target_ptr->is_dead && (r_ptr->r_deaths < MAX_SHORT) && !target_ptr->current_floor_ptr->inside_arena)
451         r_ptr->r_deaths++;
452
453     if (monap_ptr->m_ptr->ml && monap_ptr->fear && monap_ptr->alive && !target_ptr->is_dead) {
454         sound(SOUND_FLEE);
455         msg_format(_("%^sは恐怖で逃げ出した!", "%^s flees in terror!"), monap_ptr->m_name);
456     }
457
458     if (target_ptr->special_defense & KATA_IAI)
459         set_action(target_ptr, ACTION_NONE);
460 }
461
462 /*!
463  * @brief モンスターからプレイヤーへの打撃処理 / Attack the player via physical attacks.
464  * @param m_idx 打撃を行うモンスターのID
465  * @return 実際に攻撃処理を行った場合TRUEを返す
466  */
467 bool make_attack_normal(player_type *target_ptr, MONSTER_IDX m_idx)
468 {
469     monap_type tmp_monap;
470     monap_type *monap_ptr = initialize_monap_type(target_ptr, &tmp_monap, m_idx);
471     check_no_blow(target_ptr, monap_ptr);
472
473     monster_race *r_ptr = &r_info[monap_ptr->m_ptr->r_idx];
474     monap_ptr->rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
475     monster_desc(target_ptr, monap_ptr->m_name, monap_ptr->m_ptr, 0);
476     monster_desc(target_ptr, monap_ptr->ddesc, monap_ptr->m_ptr, MD_WRONGDOER_NAME);
477     if (target_ptr->special_defense & KATA_IAI) {
478         msg_format(_("相手が襲いかかる前に素早く武器を振るった。", "You took sen, drew and cut in one motion before %s moved."), monap_ptr->m_name);
479         if (do_cmd_attack(target_ptr, monap_ptr->m_ptr->fy, monap_ptr->m_ptr->fx, HISSATSU_IAI))
480             return TRUE;
481     }
482
483     if ((target_ptr->special_defense & NINJA_KAWARIMI) && (randint0(55) < (target_ptr->lev * 3 / 5 + 20))) {
484         if (kawarimi(target_ptr, TRUE))
485             return TRUE;
486     }
487
488     monap_ptr->blinked = FALSE;
489     if (process_monster_blows(target_ptr, monap_ptr))
490         return TRUE;
491
492     postprocess_monster_blows(target_ptr, monap_ptr);
493     return TRUE;
494 }