2 * @brief モンスターからプレイヤーへの直接攻撃処理
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 "core/disturbance.h"
16 #include "core/player-update-types.h"
17 #include "dungeon/dungeon-flag-types.h"
18 #include "dungeon/dungeon.h"
19 #include "floor/geometry.h"
20 #include "inventory/inventory-slot-types.h"
21 #include "main/sound-definitions-table.h"
22 #include "main/sound-of-music.h"
23 #include "mind/mind-ninja.h"
24 #include "mind/mind-samurai.h"
25 #include "monster-attack/monster-attack-describer.h"
26 #include "monster-attack/monster-attack-effect.h"
27 #include "monster-attack/monster-attack-switcher.h"
28 #include "monster-attack/monster-attack-types.h"
29 #include "monster-race/monster-race.h"
30 #include "monster-race/race-flags1.h"
31 #include "monster-race/race-flags3.h"
32 #include "monster/monster-damage.h"
33 #include "monster/monster-describer.h"
34 #include "monster/monster-description-types.h"
35 #include "monster/monster-info.h"
36 #include "monster/monster-status.h"
37 #include "monster/smart-learn-types.h"
38 #include "object-hook/hook-armor.h"
39 #include "object/item-tester-hooker.h"
40 #include "pet/pet-fall-off.h"
41 #include "player-base/player-class.h"
42 #include "player-info/samurai-data-type.h"
43 #include "player/attack-defense-types.h"
44 #include "player/player-damage.h"
45 #include "player/player-skill.h"
46 #include "player/special-defense-types.h"
47 #include "spell-realm/spells-hex.h"
48 #include "status/action-setter.h"
49 #include "status/bad-status-setter.h"
50 #include "system/angband.h"
51 #include "system/floor-type-definition.h"
52 #include "system/monster-race-definition.h"
53 #include "system/monster-type-definition.h"
54 #include "system/object-type-definition.h"
55 #include "system/player-type-definition.h"
56 #include "timed-effect/player-cut.h"
57 #include "timed-effect/player-stun.h"
58 #include "util/bit-flags-calculator.h"
59 #include "view/display-messages.h"
63 * @param player_ptr プレイヤーへの参照ポインタ
64 * @param m_idx 打撃を行うモンスターのID
66 MonsterAttackPlayer::MonsterAttackPlayer(PlayerType *player_ptr, short m_idx)
68 , m_ptr(&player_ptr->current_floor_ptr->m_list[m_idx])
69 , method(RaceBlowMethodType::NONE)
70 , effect(RaceBlowEffectType::NONE)
71 , do_silly_attack(one_in_(2) && player_ptr->hallucinated)
72 , player_ptr(player_ptr)
77 * @brief モンスターからプレイヤーへの打撃処理 / Attack the player via physical attacks.
79 void MonsterAttackPlayer::make_attack_normal()
81 if (!this->check_no_blow()) {
85 auto *r_ptr = &r_info[this->m_ptr->r_idx];
86 this->rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
87 monster_desc(this->player_ptr, this->m_name, this->m_ptr, 0);
88 monster_desc(this->player_ptr, this->ddesc, this->m_ptr, MD_WRONGDOER_NAME);
89 if (PlayerClass(this->player_ptr).samurai_stance_is(SamuraiStanceType::IAI)) {
90 msg_format(_("相手が襲いかかる前に素早く武器を振るった。", "You took sen, drew and cut in one motion before %s moved."), this->m_name);
91 if (do_cmd_attack(this->player_ptr, this->m_ptr->fy, this->m_ptr->fx, HISSATSU_IAI)) {
96 auto can_activate_kawarimi = randint0(55) < (this->player_ptr->lev * 3 / 5 + 20);
97 if (can_activate_kawarimi && kawarimi(this->player_ptr, true)) {
101 this->blinked = false;
102 if (this->process_monster_blows()) {
106 this->postprocess_monster_blows();
111 * @param raw PlayerTypeに格納されている生値
113 * @details AD&Dの記法に則り、19以上の値を取らなくしているので、格納方法が面倒
115 int MonsterAttackPlayer::stat_value(const int raw)
121 return (raw - 18) / 10 + 18;
124 bool MonsterAttackPlayer::check_no_blow()
126 auto *r_ptr = &r_info[this->m_ptr->r_idx];
127 if (r_ptr->behavior_flags.has(MonsterBehaviorType::NEVER_BLOW)) {
131 if (d_info[this->player_ptr->dungeon_idx].flags.has(DungeonFeatureType::NO_MELEE)) {
135 return is_hostile(this->m_ptr);
139 * @brief モンスターからプレイヤーへの打撃処理本体
140 * @return 打撃に反応してプレイヤーがその場から離脱したかどうか
142 bool MonsterAttackPlayer::process_monster_blows()
144 auto *r_ptr = &r_info[this->m_ptr->r_idx];
145 for (auto ap_cnt = 0; ap_cnt < MAX_NUM_BLOWS; ap_cnt++) {
146 this->obvious = false;
149 this->effect = r_ptr->blow[ap_cnt].effect;
150 this->method = r_ptr->blow[ap_cnt].method;
151 this->d_dice = r_ptr->blow[ap_cnt].d_dice;
152 this->d_side = r_ptr->blow[ap_cnt].d_side;
154 if (!this->check_monster_continuous_attack()) {
158 // effect が RaceBlowEffectType::NONE (無効値)になることはあり得ないはずだが、万一そう
160 // r_info.txt の "B:" トークンに effect 以降を書き忘れた場合が該当する。
161 if (this->effect == RaceBlowEffectType::NONE) {
162 plog("unexpected: MonsterAttackPlayer::effect == RaceBlowEffectType::NONE");
166 if (this->method == RaceBlowMethodType::SHOOT) {
170 // フレーバーの打撃は必中扱い。それ以外は通常の命中判定を行う。
171 this->ac = this->player_ptr->ac + this->player_ptr->to_a;
173 if (this->effect == RaceBlowEffectType::FLAVOR) {
176 const int power = mbe_info[enum2i(this->effect)].power;
177 hit = check_hit_from_monster_to_player(this->player_ptr, power, this->rlev, monster_stunned_remaining(this->m_ptr));
181 // 命中した。命中処理と思い出処理を行う。
182 // 打撃そのものは対邪悪結界で撃退した可能性がある。
183 const bool protect = !this->process_monster_attack_hit();
184 this->increase_blow_type_seen(ap_cnt);
186 // 撃退成功時はそのまま次の打撃へ移行。
190 // 撃退失敗時は落馬処理、変わり身のテレポート処理を行う。
191 check_fall_off_horse(this->player_ptr, this);
193 // 変わり身のテレポートが成功したら攻撃を打ち切り、プレイヤーが離脱した旨を返す。
194 if (kawarimi(this->player_ptr, false)) {
198 // 命中しなかった。回避時の処理、思い出処理を行う。
199 this->process_monster_attack_evasion();
200 this->increase_blow_type_seen(ap_cnt);
204 // 通常はプレイヤーはその場にとどまる。
209 * @brief プレイヤー死亡等でモンスターからプレイヤーへの直接攻撃処理を途中で打ち切るかどうかを判定する
210 * @return 攻撃続行ならばTRUE、打ち切りになったらFALSE
212 bool MonsterAttackPlayer::check_monster_continuous_attack()
214 if (!monster_is_valid(this->m_ptr) || (this->method == RaceBlowMethodType::NONE)) {
218 auto *r_ptr = &r_info[this->m_ptr->r_idx];
219 if (is_pet(this->m_ptr) && (r_ptr->flags1 & RF1_UNIQUE) && (this->method == RaceBlowMethodType::EXPLODE)) {
220 this->method = RaceBlowMethodType::HIT;
224 auto is_neighbor = distance(this->player_ptr->y, this->player_ptr->x, this->m_ptr->fy, this->m_ptr->fx) <= 1;
225 return this->player_ptr->playing && !this->player_ptr->is_dead && is_neighbor && !this->player_ptr->leaving;
229 * @brief モンスターから直接攻撃を1回受けた時の処理
230 * @return 対邪悪結界により攻撃が当たらなかったらFALSE、それ以外はTRUE
231 * @param this->player_ptr プレイヤーへの参照ポインタ
232 * @param monap_ptr モンスターからプレイヤーへの直接攻撃構造体への参照ポインタ
233 * @details 最大4 回/モンスター/ターン、このルーチンを通る
235 bool MonsterAttackPlayer::process_monster_attack_hit()
237 disturb(this->player_ptr, true, true);
238 if (this->effect_protecion_from_evil()) {
244 describe_monster_attack_method(this);
245 this->describe_silly_attacks();
246 this->obvious = true;
247 this->damage = damroll(this->d_dice, this->d_side);
252 switch_monster_blow_to_player(this->player_ptr, this);
253 this->select_cut_stun();
254 this->calc_player_cut();
255 this->process_player_stun();
256 this->monster_explode();
257 process_aura_counterattack(this->player_ptr, this);
262 * @brief 対邪悪結界が効いている状態で邪悪なモンスターから直接攻撃を受けた時の処理
263 * @return briefに書いた条件+確率が満たされたらTRUE、それ以外はFALSE
265 bool MonsterAttackPlayer::effect_protecion_from_evil()
267 auto *r_ptr = &r_info[this->m_ptr->r_idx];
268 if ((this->player_ptr->protevil <= 0) || none_bits(r_ptr->flags3, RF3_EVIL) || (this->player_ptr->lev < this->rlev) || ((randint0(100) + this->player_ptr->lev) <= 50)) {
272 if (is_original_ap_and_seen(this->player_ptr, this->m_ptr)) {
273 r_ptr->r_flags3 |= RF3_EVIL;
277 this->abbreviate ? msg_format("撃退した。") : msg_format("%^sは撃退された。", this->m_name);
278 this->abbreviate = 1; /* 2回目以降は省略 */
280 msg_format("%^s is repelled.", this->m_name);
286 void MonsterAttackPlayer::describe_silly_attacks()
288 if (this->act == nullptr) {
292 if (this->do_silly_attack) {
294 this->abbreviate = -1;
296 this->act = silly_attacks[randint0(MAX_SILLY_ATTACK)];
300 if (this->abbreviate == 0) {
301 msg_format("%^sに%s", this->m_name, this->act);
302 } else if (this->abbreviate == 1) {
303 msg_format("%s", this->act);
305 /* if (this->abbreviate == -1) */
306 msg_format("%^s%s", this->m_name, this->act);
309 this->abbreviate = 1; /*2回目以降は省略 */
311 msg_format("%^s %s%s", this->m_name, this->act, this->do_silly_attack ? " you." : "");
316 * @brief 切り傷と朦朧が同時に発生した時、片方を無効にする
318 void MonsterAttackPlayer::select_cut_stun()
320 if ((this->do_cut == 0) || (this->do_stun == 0)) {
324 if (randint0(100) < 50) {
331 void MonsterAttackPlayer::calc_player_cut()
333 if (this->do_cut == 0) {
337 auto cut_plus = PlayerCut::get_accumulation(this->d_dice * this->d_side, this->damage);
339 (void)BadStatusSetter(this->player_ptr).mod_cut(cut_plus);
345 * @param this->player_ptr プレイヤーへの参照ポインタ
346 * @param monap_ptr モンスター打撃への参照ポインタ
348 * 痛恨の一撃ならば朦朧蓄積ランクを1上げる.
349 * 2%の確率で朦朧蓄積ランクを1上げる.
350 * 肉体のパラメータが合計80を超える水準に強化されていたら朦朧蓄積ランクを1下げる.
352 void MonsterAttackPlayer::process_player_stun()
354 if (this->do_stun == 0) {
358 auto total = this->d_dice * this->d_side;
359 auto accumulation_rank = PlayerStun::get_accumulation_rank(total, this->damage);
360 if (accumulation_rank == 0) {
364 if ((total < this->damage) && (accumulation_rank <= 6)) {
372 auto str = this->stat_value(this->player_ptr->stat_cur[A_STR]);
373 auto dex = this->stat_value(this->player_ptr->stat_cur[A_DEX]);
374 auto con = this->stat_value(this->player_ptr->stat_cur[A_CON]);
375 auto is_powerful_body = str + dex + con > 80;
376 if (is_powerful_body) {
380 auto stun_plus = PlayerStun::get_accumulation(accumulation_rank);
382 (void)BadStatusSetter(this->player_ptr).mod_stun(stun_plus);
386 void MonsterAttackPlayer::monster_explode()
388 if (!this->explode) {
392 sound(SOUND_EXPLODE);
393 MonsterDamageProcessor mdp(this->player_ptr, this->m_idx, this->m_ptr->hp + 1, &this->fear, AttributeType::NONE);
394 if (mdp.mon_take_hit(nullptr)) {
395 this->blinked = false;
401 * @brief 一部の打撃種別の場合のみ、避けた旨のメッセージ表示と盾技能スキル向上を行う
402 * @param this->player_ptr プレイヤーへの参照ポインタ
403 * @param monap_ptr モンスターからプレイヤーへの直接攻撃構造体への参照ポインタ
405 void MonsterAttackPlayer::process_monster_attack_evasion()
407 switch (this->method) {
408 case RaceBlowMethodType::HIT:
409 case RaceBlowMethodType::TOUCH:
410 case RaceBlowMethodType::PUNCH:
411 case RaceBlowMethodType::KICK:
412 case RaceBlowMethodType::CLAW:
413 case RaceBlowMethodType::BITE:
414 case RaceBlowMethodType::STING:
415 case RaceBlowMethodType::SLASH:
416 case RaceBlowMethodType::BUTT:
417 case RaceBlowMethodType::CRUSH:
418 case RaceBlowMethodType::ENGULF:
419 case RaceBlowMethodType::CHARGE:
420 this->describe_attack_evasion();
421 this->gain_armor_exp();
429 void MonsterAttackPlayer::describe_attack_evasion()
431 if (!this->m_ptr->ml) {
435 disturb(this->player_ptr, true, true);
437 auto is_suiken = any_bits(this->player_ptr->special_attack, ATTACK_SUIKEN);
438 if (this->abbreviate) {
439 msg_format("%sかわした。", is_suiken ? "奇妙な動きで" : "");
441 msg_format("%s%^sの攻撃をかわした。", is_suiken ? "奇妙な動きで" : "", this->m_name);
444 this->abbreviate = 1; /* 2回目以降は省略 */
446 msg_format("%^s misses you.", this->m_name);
450 void MonsterAttackPlayer::gain_armor_exp()
452 const auto o_ptr_mh = &this->player_ptr->inventory_list[INVEN_MAIN_HAND];
453 const auto o_ptr_sh = &this->player_ptr->inventory_list[INVEN_SUB_HAND];
454 if (!o_ptr_mh->is_armour() && !o_ptr_sh->is_armour()) {
458 auto cur = this->player_ptr->skill_exp[PlayerSkillKindType::SHIELD];
459 auto max = s_info[enum2i(this->player_ptr->pclass)].s_max[PlayerSkillKindType::SHIELD];
464 auto *r_ptr = &r_info[this->m_ptr->r_idx];
465 auto target_level = r_ptr->level;
467 if ((cur / 100) < target_level) {
468 auto addition = (cur / 100 + 15) < target_level ? (target_level - (cur / 100 + 15)) : 0;
469 increment += 1 + addition;
472 this->player_ptr->skill_exp[PlayerSkillKindType::SHIELD] = std::min<short>(max, cur + increment);
473 this->player_ptr->update |= (PU_BONUS);
477 * @brief モンスターの打撃情報を蓄積させる
478 * @param ap_cnt モンスターの打撃 N回目
479 * @details どの敵が何をしてきたか正しく認識できていなければ情報を蓄積しない.
480 * 非自明な類の打撃については、そのダメージが 0 ならば基本的に知識が増えない.
481 * 但し、既に一定以上の知識があれば常に知識が増える(何をされたのか察知できる).
483 void MonsterAttackPlayer::increase_blow_type_seen(const int ap_cnt)
485 if (!is_original_ap_and_seen(this->player_ptr, this->m_ptr) || this->do_silly_attack) {
489 auto *r_ptr = &r_info[this->m_ptr->r_idx];
490 if (!this->obvious && (this->damage == 0) && (r_ptr->r_blows[ap_cnt] <= 10)) {
494 if (r_ptr->r_blows[ap_cnt] < MAX_UCHAR) {
495 r_ptr->r_blows[ap_cnt]++;
499 void MonsterAttackPlayer::postprocess_monster_blows()
501 SpellHex spell_hex(this->player_ptr, this);
502 spell_hex.store_vengeful_damage(this->get_damage);
503 spell_hex.eyes_on_eyes();
504 musou_counterattack(this->player_ptr, this);
505 spell_hex.thief_teleport();
506 auto *r_ptr = &r_info[this->m_ptr->r_idx];
507 if (this->player_ptr->is_dead && (r_ptr->r_deaths < MAX_SHORT) && !this->player_ptr->current_floor_ptr->inside_arena) {
511 if (this->m_ptr->ml && this->fear && this->alive && !this->player_ptr->is_dead) {
513 msg_format(_("%^sは恐怖で逃げ出した!", "%^s flees in terror!"), this->m_name);
516 PlayerClass(this->player_ptr).break_samurai_stance({ SamuraiStanceType::IAI });