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)
76 bool MonsterAttackPlayer::check_no_blow()
78 auto *r_ptr = &r_info[this->m_ptr->r_idx];
79 if (r_ptr->behavior_flags.has(MonsterBehaviorType::NEVER_BLOW)) {
83 if (d_info[this->player_ptr->dungeon_idx].flags.has(DungeonFeatureType::NO_MELEE)) {
87 return is_hostile(this->m_ptr);
91 * @brief プレイヤー死亡等でモンスターからプレイヤーへの直接攻撃処理を途中で打ち切るかどうかを判定する
92 * @return 攻撃続行ならばTRUE、打ち切りになったらFALSE
94 bool MonsterAttackPlayer::check_monster_continuous_attack()
96 if (!monster_is_valid(this->m_ptr) || (this->method == RaceBlowMethodType::NONE)) {
100 auto *r_ptr = &r_info[this->m_ptr->r_idx];
101 if (is_pet(this->m_ptr) && (r_ptr->flags1 & RF1_UNIQUE) && (this->method == RaceBlowMethodType::EXPLODE)) {
102 this->method = RaceBlowMethodType::HIT;
106 auto is_neighbor = distance(this->player_ptr->y, this->player_ptr->x, this->m_ptr->fy, this->m_ptr->fx) <= 1;
107 return this->player_ptr->playing && !this->player_ptr->is_dead && is_neighbor && !this->player_ptr->leaving;
111 * @brief 対邪悪結界が効いている状態で邪悪なモンスターから直接攻撃を受けた時の処理
112 * @return briefに書いた条件+確率が満たされたらTRUE、それ以外はFALSE
114 bool MonsterAttackPlayer::effect_protecion_from_evil()
116 auto *r_ptr = &r_info[this->m_ptr->r_idx];
117 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)) {
121 if (is_original_ap_and_seen(this->player_ptr, this->m_ptr)) {
122 r_ptr->r_flags3 |= RF3_EVIL;
126 this->abbreviate ? msg_format("撃退した。") : msg_format("%^sは撃退された。", this->m_name);
127 this->abbreviate = 1; /* 2回目以降は省略 */
129 msg_format("%^s is repelled.", this->m_name);
135 void MonsterAttackPlayer::describe_silly_attacks()
137 if (this->act == nullptr) {
141 if (this->do_silly_attack) {
143 this->abbreviate = -1;
145 this->act = silly_attacks[randint0(MAX_SILLY_ATTACK)];
149 if (this->abbreviate == 0) {
150 msg_format("%^sに%s", this->m_name, this->act);
151 } else if (this->abbreviate == 1) {
152 msg_format("%s", this->act);
154 /* if (this->abbreviate == -1) */
155 msg_format("%^s%s", this->m_name, this->act);
158 this->abbreviate = 1; /*2回目以降は省略 */
160 msg_format("%^s %s%s", this->m_name, this->act, this->do_silly_attack ? " you." : "");
165 * @brief 切り傷と朦朧が同時に発生した時、片方を無効にする
167 void MonsterAttackPlayer::select_cut_stun()
169 if ((this->do_cut == 0) || (this->do_stun == 0)) {
173 if (randint0(100) < 50) {
180 void MonsterAttackPlayer::calc_player_cut()
182 if (this->do_cut == 0) {
186 auto cut_plus = PlayerCut::get_accumulation(this->d_dice * this->d_side, this->damage);
188 (void)BadStatusSetter(this->player_ptr).mod_cut(cut_plus);
194 * @param raw PlayerTypeに格納されている生値
196 * @details AD&Dの記法に則り、19以上の値を取らなくしているので、格納方法が面倒
198 int MonsterAttackPlayer::stat_value(const int raw)
204 return (raw - 18) / 10 + 18;
209 * @param this->player_ptr プレイヤーへの参照ポインタ
210 * @param monap_ptr モンスター打撃への参照ポインタ
212 * 痛恨の一撃ならば朦朧蓄積ランクを1上げる.
213 * 2%の確率で朦朧蓄積ランクを1上げる.
214 * 肉体のパラメータが合計80を超える水準に強化されていたら朦朧蓄積ランクを1下げる.
216 void MonsterAttackPlayer::process_player_stun()
218 if (this->do_stun == 0) {
222 auto total = this->d_dice * this->d_side;
223 auto accumulation_rank = PlayerStun::get_accumulation_rank(total, this->damage);
224 if (accumulation_rank == 0) {
228 if ((total < this->damage) && (accumulation_rank <= 6)) {
236 auto str = this->stat_value(this->player_ptr->stat_cur[A_STR]);
237 auto dex = this->stat_value(this->player_ptr->stat_cur[A_DEX]);
238 auto con = this->stat_value(this->player_ptr->stat_cur[A_CON]);
239 auto is_powerful_body = str + dex + con > 80;
240 if (is_powerful_body) {
244 auto stun_plus = PlayerStun::get_accumulation(accumulation_rank);
246 (void)BadStatusSetter(this->player_ptr).mod_stun(stun_plus);
250 void MonsterAttackPlayer::monster_explode()
252 if (!this->explode) {
256 sound(SOUND_EXPLODE);
257 MonsterDamageProcessor mdp(this->player_ptr, this->m_idx, this->m_ptr->hp + 1, &this->fear, AttributeType::NONE);
258 if (mdp.mon_take_hit(nullptr)) {
259 this->blinked = false;
264 void MonsterAttackPlayer::describe_attack_evasion()
266 if (!this->m_ptr->ml) {
270 disturb(this->player_ptr, true, true);
272 auto is_suiken = any_bits(this->player_ptr->special_attack, ATTACK_SUIKEN);
273 if (this->abbreviate) {
274 msg_format("%sかわした。", is_suiken ? "奇妙な動きで" : "");
276 msg_format("%s%^sの攻撃をかわした。", is_suiken ? "奇妙な動きで" : "", this->m_name);
279 this->abbreviate = 1; /* 2回目以降は省略 */
281 msg_format("%^s misses you.", this->m_name);
285 void MonsterAttackPlayer::gain_armor_exp()
287 const auto o_ptr_mh = &this->player_ptr->inventory_list[INVEN_MAIN_HAND];
288 const auto o_ptr_sh = &this->player_ptr->inventory_list[INVEN_SUB_HAND];
289 if (!o_ptr_mh->is_armour() && !o_ptr_sh->is_armour()) {
293 auto cur = this->player_ptr->skill_exp[PlayerSkillKindType::SHIELD];
294 auto max = s_info[enum2i(this->player_ptr->pclass)].s_max[PlayerSkillKindType::SHIELD];
299 auto *r_ptr = &r_info[this->m_ptr->r_idx];
300 auto target_level = r_ptr->level;
302 if ((cur / 100) < target_level) {
303 auto addition = (cur / 100 + 15) < target_level ? (target_level - (cur / 100 + 15)) : 0;
304 increment += 1 + addition;
307 this->player_ptr->skill_exp[PlayerSkillKindType::SHIELD] = std::min<short>(max, cur + increment);
308 this->player_ptr->update |= (PU_BONUS);
312 * @brief モンスターから直接攻撃を1回受けた時の処理
313 * @return 対邪悪結界により攻撃が当たらなかったらFALSE、それ以外はTRUE
314 * @param this->player_ptr プレイヤーへの参照ポインタ
315 * @param monap_ptr モンスターからプレイヤーへの直接攻撃構造体への参照ポインタ
316 * @details 最大4 回/モンスター/ターン、このルーチンを通る
318 bool MonsterAttackPlayer::process_monster_attack_hit()
320 disturb(this->player_ptr, true, true);
321 if (this->effect_protecion_from_evil()) {
327 describe_monster_attack_method(this);
328 this->describe_silly_attacks();
329 this->obvious = true;
330 this->damage = damroll(this->d_dice, this->d_side);
335 switch_monster_blow_to_player(this->player_ptr, this);
336 this->select_cut_stun();
337 this->calc_player_cut();
338 this->process_player_stun();
339 this->monster_explode();
340 process_aura_counterattack(this->player_ptr, this);
345 * @brief 一部の打撃種別の場合のみ、避けた旨のメッセージ表示と盾技能スキル向上を行う
346 * @param this->player_ptr プレイヤーへの参照ポインタ
347 * @param monap_ptr モンスターからプレイヤーへの直接攻撃構造体への参照ポインタ
349 void MonsterAttackPlayer::process_monster_attack_evasion()
351 switch (this->method) {
352 case RaceBlowMethodType::HIT:
353 case RaceBlowMethodType::TOUCH:
354 case RaceBlowMethodType::PUNCH:
355 case RaceBlowMethodType::KICK:
356 case RaceBlowMethodType::CLAW:
357 case RaceBlowMethodType::BITE:
358 case RaceBlowMethodType::STING:
359 case RaceBlowMethodType::SLASH:
360 case RaceBlowMethodType::BUTT:
361 case RaceBlowMethodType::CRUSH:
362 case RaceBlowMethodType::ENGULF:
363 case RaceBlowMethodType::CHARGE:
364 this->describe_attack_evasion();
365 this->gain_armor_exp();
374 * @brief モンスターの打撃情報を蓄積させる
375 * @param ap_cnt モンスターの打撃 N回目
376 * @details どの敵が何をしてきたか正しく認識できていなければ情報を蓄積しない.
377 * 非自明な類の打撃については、そのダメージが 0 ならば基本的に知識が増えない.
378 * 但し、既に一定以上の知識があれば常に知識が増える(何をされたのか察知できる).
380 void MonsterAttackPlayer::increase_blow_type_seen(const int ap_cnt)
382 if (!is_original_ap_and_seen(this->player_ptr, this->m_ptr) || this->do_silly_attack) {
386 auto *r_ptr = &r_info[this->m_ptr->r_idx];
387 if (!this->obvious && (this->damage == 0) && (r_ptr->r_blows[ap_cnt] <= 10)) {
391 if (r_ptr->r_blows[ap_cnt] < MAX_UCHAR) {
392 r_ptr->r_blows[ap_cnt]++;
397 * @brief モンスターからプレイヤーへの打撃処理本体
398 * @return 打撃に反応してプレイヤーがその場から離脱したかどうか
400 bool MonsterAttackPlayer::process_monster_blows()
402 auto *r_ptr = &r_info[this->m_ptr->r_idx];
403 for (auto ap_cnt = 0; ap_cnt < MAX_NUM_BLOWS; ap_cnt++) {
404 this->obvious = false;
407 this->effect = r_ptr->blow[ap_cnt].effect;
408 this->method = r_ptr->blow[ap_cnt].method;
409 this->d_dice = r_ptr->blow[ap_cnt].d_dice;
410 this->d_side = r_ptr->blow[ap_cnt].d_side;
412 if (!this->check_monster_continuous_attack()) {
416 // effect が RaceBlowEffectType::NONE (無効値)になることはあり得ないはずだが、万一そう
418 // r_info.txt の "B:" トークンに effect 以降を書き忘れた場合が該当する。
419 if (this->effect == RaceBlowEffectType::NONE) {
420 plog("unexpected: MonsterAttackPlayer::effect == RaceBlowEffectType::NONE");
424 if (this->method == RaceBlowMethodType::SHOOT) {
428 // フレーバーの打撃は必中扱い。それ以外は通常の命中判定を行う。
429 this->ac = this->player_ptr->ac + this->player_ptr->to_a;
431 if (this->effect == RaceBlowEffectType::FLAVOR) {
434 const int power = mbe_info[enum2i(this->effect)].power;
435 hit = check_hit_from_monster_to_player(this->player_ptr, power, this->rlev, monster_stunned_remaining(this->m_ptr));
439 // 命中した。命中処理と思い出処理を行う。
440 // 打撃そのものは対邪悪結界で撃退した可能性がある。
441 const bool protect = !this->process_monster_attack_hit();
442 this->increase_blow_type_seen(ap_cnt);
444 // 撃退成功時はそのまま次の打撃へ移行。
448 // 撃退失敗時は落馬処理、変わり身のテレポート処理を行う。
449 check_fall_off_horse(this->player_ptr, this);
451 // 変わり身のテレポートが成功したら攻撃を打ち切り、プレイヤーが離脱した旨を返す。
452 if (kawarimi(this->player_ptr, false)) {
456 // 命中しなかった。回避時の処理、思い出処理を行う。
457 this->process_monster_attack_evasion();
458 this->increase_blow_type_seen(ap_cnt);
462 // 通常はプレイヤーはその場にとどまる。
466 void MonsterAttackPlayer::postprocess_monster_blows()
468 SpellHex spell_hex(this->player_ptr, this);
469 spell_hex.store_vengeful_damage(this->get_damage);
470 spell_hex.eyes_on_eyes();
471 musou_counterattack(this->player_ptr, this);
472 spell_hex.thief_teleport();
473 auto *r_ptr = &r_info[this->m_ptr->r_idx];
474 if (this->player_ptr->is_dead && (r_ptr->r_deaths < MAX_SHORT) && !this->player_ptr->current_floor_ptr->inside_arena) {
478 if (this->m_ptr->ml && this->fear && this->alive && !this->player_ptr->is_dead) {
480 msg_format(_("%^sは恐怖で逃げ出した!", "%^s flees in terror!"), this->m_name);
483 PlayerClass(this->player_ptr).break_samurai_stance({ SamuraiStanceType::IAI });
487 * @brief モンスターからプレイヤーへの打撃処理 / Attack the player via physical attacks.
489 void MonsterAttackPlayer::make_attack_normal()
491 if (!this->check_no_blow()) {
495 auto *r_ptr = &r_info[this->m_ptr->r_idx];
496 this->rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
497 monster_desc(this->player_ptr, this->m_name, this->m_ptr, 0);
498 monster_desc(this->player_ptr, this->ddesc, this->m_ptr, MD_WRONGDOER_NAME);
499 if (PlayerClass(this->player_ptr).samurai_stance_is(SamuraiStanceType::IAI)) {
500 msg_format(_("相手が襲いかかる前に素早く武器を振るった。", "You took sen, drew and cut in one motion before %s moved."), this->m_name);
501 if (do_cmd_attack(this->player_ptr, this->m_ptr->fy, this->m_ptr->fx, HISSATSU_IAI)) {
506 auto can_activate_kawarimi = randint0(55) < (this->player_ptr->lev * 3 / 5 + 20);
507 if (can_activate_kawarimi && kawarimi(this->player_ptr, true)) {
511 this->blinked = false;
512 if (this->process_monster_blows()) {
516 this->postprocess_monster_blows();