OSDN Git Service

c8517f237f25615b7d99bddfdaf1984db13343ad
[hengband/hengband.git] / src / mind / monk-attack.c
1 /*!
2  * @brief 素手で攻撃することに補正のある職業 (修行僧、狂戦士、練気術師)の打撃処理
3  * @date 2020/05/23
4  * @author Hourier
5  * @details 練気術師は騎乗していない時
6  */
7
8 #include "mind/monk-attack.h"
9 #include "cmd-action/cmd-attack.h"
10 #include "combat/attack-criticality.h"
11 #include "core/speed-table.h"
12 #include "core/stuff-handler.h"
13 #include "floor/floor.h"
14 #include "game-option/cheat-options.h"
15 #include "io/targeting.h"
16 #include "main/sound-definitions-table.h"
17 #include "main/sound-of-music.h"
18 #include "mind/mind-force-trainer.h"
19 #include "monster-race/race-flags1.h"
20 #include "monster-race/race-flags3.h"
21 #include "monster/monster-status.h"
22 #include "view/display-messages.h"
23 #include "world/world.h"
24
25 /*!
26  * @brief 朦朧への抵抗値を計算する
27  * @param pa_ptr 直接攻撃構造体への参照ポインタ
28  * @return 朦朧への抵抗値
29  */
30 static int calc_stun_resistance(player_attack_type *pa_ptr)
31 {
32     monster_race *r_ptr = &r_info[pa_ptr->m_ptr->r_idx];
33     int resist_stun = 0;
34     if (r_ptr->flags1 & RF1_UNIQUE)
35         resist_stun += 88;
36
37     if (r_ptr->flags3 & RF3_NO_STUN)
38         resist_stun += 66;
39
40     if (r_ptr->flags3 & RF3_NO_CONF)
41         resist_stun += 33;
42
43     if (r_ptr->flags3 & RF3_NO_SLEEP)
44         resist_stun += 33;
45
46     if ((r_ptr->flags3 & RF3_UNDEAD) || (r_ptr->flags3 & RF3_NONLIVING))
47         resist_stun += 66;
48
49     return resist_stun;
50 }
51
52 /*!
53  * @brief 技のランダム選択回数を決定する
54  * @param attacker_ptr プレーヤーへの参照ポインタ
55  * @return 技のランダム選択回数
56  * @details ランダム選択は一番強い技が最終的に選択されるので、回数が多いほど有利
57  */
58 static int calc_max_blow_selection_times(player_type *attacker_ptr)
59 {
60     if (attacker_ptr->special_defense & KAMAE_BYAKKO)
61         return (attacker_ptr->lev < 3 ? 1 : attacker_ptr->lev / 3);
62
63     if (attacker_ptr->special_defense & KAMAE_SUZAKU)
64         return 1;
65
66     if (attacker_ptr->special_defense & KAMAE_GENBU)
67         return 1;
68
69     return attacker_ptr->lev < 7 ? 1 : attacker_ptr->lev / 7;
70 }
71
72 /*!
73  * @brief プレーヤーのレベルと技の難度を加味しつつ、確率で一番強い技を選ぶ
74  * @param attacker_ptr プレーヤーへの参照ポインタ
75  * @return 技のランダム選択回数
76  * @return 技の行使に必要な最低レベル
77  */
78 static int select_blow(player_type *attacker_ptr, player_attack_type *pa_ptr, int max_blow_selection_times)
79 {
80     int min_level = 1;
81     const martial_arts *old_ptr = &ma_blows[0];
82     for (int times = 0; times < max_blow_selection_times; times++) {
83         do {
84             pa_ptr->ma_ptr = &ma_blows[randint0(MAX_MA)];
85             if ((attacker_ptr->pclass == CLASS_FORCETRAINER) && (pa_ptr->ma_ptr->min_level > 1))
86                 min_level = pa_ptr->ma_ptr->min_level + 3;
87             else
88                 min_level = pa_ptr->ma_ptr->min_level;
89         } while ((min_level > attacker_ptr->lev) || (randint1(attacker_ptr->lev) < pa_ptr->ma_ptr->chance));
90
91         if ((pa_ptr->ma_ptr->min_level <= old_ptr->min_level) || attacker_ptr->stun || attacker_ptr->confused) {
92             pa_ptr->ma_ptr = old_ptr;
93             continue;
94         }
95
96         old_ptr = pa_ptr->ma_ptr;
97         if (current_world_ptr->wizard && cheat_xtra)
98             msg_print(_("攻撃を再選択しました。", "Attack re-selected."));
99     }
100
101     if (attacker_ptr->pclass == CLASS_FORCETRAINER)
102         min_level = MAX(1, pa_ptr->ma_ptr->min_level - 3);
103     else
104         min_level = pa_ptr->ma_ptr->min_level;
105
106     return min_level;
107 }
108
109 static int process_monk_additional_effect(player_attack_type *pa_ptr, int *stun_effect)
110 {
111     int special_effect = 0;
112     monster_race *r_ptr = &r_info[pa_ptr->m_ptr->r_idx];
113     if (pa_ptr->ma_ptr->effect == MA_KNEE) {
114         if (r_ptr->flags1 & RF1_MALE) {
115             msg_format(_("%sに金的膝蹴りをくらわした!", "You hit %s in the groin with your knee!"), pa_ptr->m_name);
116             sound(SOUND_PAIN);
117             special_effect = MA_KNEE;
118         } else
119             msg_format(pa_ptr->ma_ptr->desc, pa_ptr->m_name);
120     }
121
122     else if (pa_ptr->ma_ptr->effect == MA_SLOW) {
123         if (!((r_ptr->flags1 & RF1_NEVER_MOVE) || angband_strchr("~#{}.UjmeEv$,DdsbBFIJQSXclnw!=?", r_ptr->d_char))) {
124             msg_format(_("%sの足首に関節蹴りをくらわした!", "You kick %s in the ankle."), pa_ptr->m_name);
125             special_effect = MA_SLOW;
126         } else
127             msg_format(pa_ptr->ma_ptr->desc, pa_ptr->m_name);
128     } else {
129         if (pa_ptr->ma_ptr->effect) {
130             *stun_effect = (pa_ptr->ma_ptr->effect / 2) + randint1(pa_ptr->ma_ptr->effect / 2);
131         }
132
133         msg_format(pa_ptr->ma_ptr->desc, pa_ptr->m_name);
134     }
135
136     return special_effect;
137 }
138
139 /*!
140  * @brief 攻撃の重さ (修行僧と練気術師における武器重量)を決定する
141  * @param attacker_ptr プレーヤーへの参照ポインタ
142  * @return 重さ
143  */
144 static WEIGHT calc_monk_attack_weight(player_type *attacker_ptr)
145 {
146     WEIGHT weight = 8;
147     if (attacker_ptr->special_defense & KAMAE_SUZAKU)
148         weight = 4;
149
150     if ((attacker_ptr->pclass == CLASS_FORCETRAINER) && (get_current_ki(attacker_ptr) != 0)) {
151         weight += (get_current_ki(attacker_ptr) / 30);
152         if (weight > 20)
153             weight = 20;
154     }
155
156     return weight;
157 }
158
159 /*!
160  * @brief 急所攻撃による追加効果を与える
161  * @param attacker_ptr プレーヤーへの参照ポインタ
162  * @param pa_ptr 直接攻撃構造体への参照ポインタ
163  * @param stun_effect 朦朧の残りターン
164  * @param resist_stun 朦朧への抵抗値
165  * @param special_effect 技を繰り出した時の追加効果
166  * @return なし
167  */
168 static void process_attack_vital_spot(player_type *attacker_ptr, player_attack_type *pa_ptr, int *stun_effect, int *resist_stun, const int special_effect)
169 {
170     monster_race *r_ptr = &r_info[pa_ptr->m_ptr->r_idx];
171     if ((special_effect == MA_KNEE) && ((pa_ptr->attack_damage + attacker_ptr->to_d[pa_ptr->hand]) < pa_ptr->m_ptr->hp)) {
172         msg_format(_("%^sは苦痛にうめいている!", "%^s moans in agony!"), pa_ptr->m_name);
173         *stun_effect = 7 + randint1(13);
174         *resist_stun /= 3;
175         return;
176     }
177
178     if ((special_effect == MA_SLOW) && ((pa_ptr->attack_damage + attacker_ptr->to_d[pa_ptr->hand]) < pa_ptr->m_ptr->hp)) {
179         if (!(r_ptr->flags1 & RF1_UNIQUE) && (randint1(attacker_ptr->lev) > r_ptr->level) && pa_ptr->m_ptr->mspeed > 60) {
180             msg_format(_("%^sは足をひきずり始めた。", "%^s starts limping slower."), pa_ptr->m_name);
181             pa_ptr->m_ptr->mspeed -= 10;
182         }
183     }
184 }
185
186 /*!
187  * @brief 朦朧効果を受けたモンスターのステータス表示
188  * @param attacker_ptr プレーヤーの参照ポインタ
189  * @param pa_ptr 直接攻撃構造体への参照ポインタ
190  * @param g_ptr グリッドへの参照ポインタ
191  * @param stun_effect 朦朧の残りターン
192  * @param resist_stun 朦朧への抵抗値
193  * @return なし
194  */
195 static void print_stun_effect(player_type *attacker_ptr, player_attack_type *pa_ptr, const int stun_effect, const int resist_stun)
196 {
197     monster_race *r_ptr = &r_info[pa_ptr->m_ptr->r_idx];
198     if (stun_effect && ((pa_ptr->attack_damage + attacker_ptr->to_d[pa_ptr->hand]) < pa_ptr->m_ptr->hp)) {
199         if (attacker_ptr->lev > randint1(r_ptr->level + resist_stun + 10)) {
200             if (set_monster_stunned(attacker_ptr, pa_ptr->g_ptr->m_idx, stun_effect + monster_stunned_remaining(pa_ptr->m_ptr))) {
201                 msg_format(_("%^sはフラフラになった。", "%^s is stunned."), pa_ptr->m_name);
202             } else {
203                 msg_format(_("%^sはさらにフラフラになった。", "%^s is more stunned."), pa_ptr->m_name);
204             }
205         }
206     }
207 }
208
209 /*!
210  * @brief 強力な素手攻撃ができる職業 (修行僧、狂戦士、練気術師)の素手攻撃処理メインルーチン
211  * @param attacker_ptr プレーヤーの参照ポインタ
212  * @param pa_ptr 直接攻撃構造体への参照ポインタ
213  * @param g_ptr グリッドへの参照ポインタ
214  * @return なし
215  */
216 void process_monk_attack(player_type *attacker_ptr, player_attack_type *pa_ptr)
217 {
218     int resist_stun = calc_stun_resistance(pa_ptr);
219     int max_blow_selection_times = calc_max_blow_selection_times(attacker_ptr);
220     int min_level = select_blow(attacker_ptr, pa_ptr, max_blow_selection_times);
221
222     pa_ptr->attack_damage = damroll(pa_ptr->ma_ptr->dd + attacker_ptr->to_dd[pa_ptr->hand], pa_ptr->ma_ptr->ds + attacker_ptr->to_ds[pa_ptr->hand]);
223     if (attacker_ptr->special_attack & ATTACK_SUIKEN)
224         pa_ptr->attack_damage *= 2;
225
226     int stun_effect = 0;
227     int special_effect = process_monk_additional_effect(pa_ptr, &stun_effect);
228     WEIGHT weight = calc_monk_attack_weight(attacker_ptr);
229     pa_ptr->attack_damage = critical_norm(attacker_ptr, attacker_ptr->lev * weight, min_level, pa_ptr->attack_damage, attacker_ptr->to_h[0], 0);
230     process_attack_vital_spot(attacker_ptr, pa_ptr, &stun_effect, &resist_stun, special_effect);
231     print_stun_effect(attacker_ptr, pa_ptr, stun_effect, resist_stun);
232 }
233
234 bool double_attack(player_type *creature_ptr)
235 {
236     DIRECTION dir;
237     if (!get_rep_dir(creature_ptr, &dir, FALSE))
238         return FALSE;
239     POSITION y = creature_ptr->y + ddy[dir];
240     POSITION x = creature_ptr->x + ddx[dir];
241     if (!creature_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
242         msg_print(_("その方向にはモンスターはいません。", "You don't see any monster in this direction"));
243         msg_print(NULL);
244         return TRUE;
245     }
246
247     if (one_in_(3))
248         msg_print(_("あーたたたたたたたたたたたたたたたたたたたたたた!!!", "Ahhhtatatatatatatatatatatatatatataatatatatattaaaaa!!!!"));
249     else if (one_in_(2))
250         msg_print(_("無駄無駄無駄無駄無駄無駄無駄無駄無駄無駄無駄無駄!!!", "Mudamudamudamudamudamudamudamudamudamudamudamudamuda!!!!"));
251     else
252         msg_print(_("オラオラオラオラオラオラオラオラオラオラオラオラ!!!", "Oraoraoraoraoraoraoraoraoraoraoraoraoraoraoraoraora!!!!"));
253
254     do_cmd_attack(creature_ptr, y, x, 0);
255     if (creature_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
256         handle_stuff(creature_ptr);
257         do_cmd_attack(creature_ptr, y, x, 0);
258     }
259
260     creature_ptr->energy_need += ENERGY_NEED();
261     return TRUE;
262 }