OSDN Git Service

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