OSDN Git Service

Merge pull request #3532 from sikabane-works/release/3.0.0.87-alpha
[hengbandforosx/hengbandosx.git] / src / combat / attack-criticality.cpp
1 #include "combat/attack-criticality.h"
2 #include "combat/combat-options-type.h"
3 #include "inventory/inventory-slot-types.h"
4 #include "main/sound-of-music.h"
5 #include "monster-race/monster-race.h"
6 #include "monster-race/race-flags1.h"
7 #include "monster-race/race-flags7.h"
8 #include "object/tval-types.h"
9 #include "player-attack/player-attack.h"
10 #include "player-base/player-class.h"
11 #include "player-info/equipment-info.h"
12 #include "sv-definition/sv-weapon-types.h"
13 #include "system/item-entity.h"
14 #include "system/monster-entity.h"
15 #include "system/monster-race-info.h"
16 #include "system/player-type-definition.h"
17 #include "view/display-messages.h"
18
19 /*!
20  * @brief クリティカルダメージを適用する
21  *
22  * @param k クリティカルの強度を決定する値
23  * @param base_dam クリティカル適用前のダメージ
24  * @return クリティカルを適用したダメージと、クリティカル発生時に表示するメッセージと、クリティカル効果音のタプルを返す
25  */
26 std::tuple<int, concptr, sound_type> apply_critical_norm_damage(int k, int base_dam)
27 {
28     if (k < 400) {
29         return { 2 * base_dam + 5, _("手ごたえがあった!", "It was a good hit!"), SOUND_GOOD_HIT };
30     }
31     if (k < 700) {
32         return { 2 * base_dam + 10, _("かなりの手ごたえがあった!", "It was a great hit!"), SOUND_GREAT_HIT };
33     }
34     if (k < 900) {
35         return { 3 * base_dam + 15, _("会心の一撃だ!", "It was a superb hit!"), SOUND_SUPERB_HIT };
36     }
37     if (k < 1300) {
38         return { 3 * base_dam + 20, _("最高の会心の一撃だ!", "It was a *GREAT* hit!"), SOUND_STAR_GREAT_HIT };
39     }
40     return { ((7 * base_dam) / 2) + 25, _("比類なき最高の会心の一撃だ!", "It was a *SUPERB* hit!"), SOUND_STAR_SUPERB_HIT };
41 }
42
43 /*!
44  * @brief プレイヤーからモンスターへの打撃クリティカル判定 /
45  * Critical hits (by player) Factor in weapon weight, total plusses, player melee bonus
46  * @param weight 矢弾の重量
47  * @param plus 武器の命中修正
48  * @param dam 現在算出中のダメージ値
49  * @param meichuu 打撃の基本命中力
50  * @param mode オプションフラグ
51  * @return クリティカル修正が入ったダメージ値
52  */
53 int critical_norm(PlayerType *player_ptr, WEIGHT weight, int plus, int dam, int16_t meichuu, combat_options mode, bool impact)
54 {
55     /* Extract "blow" power */
56     int i = (weight + (meichuu * 3 + plus * 5) + player_ptr->skill_thn);
57
58     /* Chance */
59     auto pow = PlayerClass(player_ptr).equals(PlayerClassType::NINJA) ? 4444 : 5000;
60     if (impact) {
61         pow /= 2;
62     }
63
64     bool is_special_option = randint1(pow) <= i;
65     is_special_option |= mode == HISSATSU_MAJIN;
66     is_special_option |= mode == HISSATSU_3DAN;
67     if (!is_special_option) {
68         return dam;
69     }
70
71     int k = weight + randint1(650);
72     if (impact || (mode == HISSATSU_MAJIN) || (mode == HISSATSU_3DAN)) {
73         k += randint1(650);
74     }
75
76     auto [critical_dam, msg, battle_sound] = apply_critical_norm_damage(k, dam);
77     sound(battle_sound);
78     msg_print(msg);
79     return critical_dam;
80 }
81
82 /*!
83  * @brief 忍者ヒットで急所を突く
84  * @param player_ptr プレイヤーへの参照ポインタ
85  * @param pa_ptr 直接攻撃構造体への参照ポインタ
86  * @details 闇討ち&追討ちを実施した後に致命傷チェックを行う
87  * チェックを通ったら、ユニークならば2倍ダメージ、それ以外は一撃死
88  * @todo 3つの処理をdetailsに書くよりは関数自体を分割すべきだが、一旦後回しにする。他の項目と一緒に処理する
89  */
90 static void ninja_critical(PlayerType *player_ptr, player_attack_type *pa_ptr)
91 {
92     auto *r_ptr = &monraces_info[pa_ptr->m_ptr->r_idx];
93     int maxhp = pa_ptr->m_ptr->maxhp;
94     if (one_in_(pa_ptr->backstab ? 13 : (pa_ptr->stab_fleeing || pa_ptr->surprise_attack) ? 15
95                                                                                           : 27)) {
96         pa_ptr->attack_damage *= 5;
97         pa_ptr->drain_result *= 2;
98         msg_format(_("刃が%sに深々と突き刺さった!", "You critically injured %s!"), pa_ptr->m_name);
99         return;
100     }
101
102     bool is_weaken = pa_ptr->m_ptr->hp < maxhp / 2;
103     bool is_unique = (r_ptr->kind_flags.has(MonsterKindType::UNIQUE)) || ((r_ptr->flags7 & RF7_UNIQUE2) != 0);
104     bool is_critical = (is_weaken && one_in_((player_ptr->num_blow[0] + player_ptr->num_blow[1] + 1) * 10)) || ((one_in_(666) || ((pa_ptr->backstab || pa_ptr->surprise_attack) && one_in_(11))) && !is_unique);
105     if (!is_critical) {
106         return;
107     }
108
109     if (is_unique || !is_weaken) {
110         pa_ptr->attack_damage = std::max(pa_ptr->attack_damage * 5, pa_ptr->m_ptr->hp / 2);
111         pa_ptr->drain_result *= 2;
112         msg_format(_("%sに致命傷を負わせた!", "You fatally injured %s!"), pa_ptr->m_name);
113     } else {
114         pa_ptr->attack_damage = pa_ptr->m_ptr->hp + 1;
115         msg_format(_("刃が%sの急所を貫いた!", "You hit %s on a fatal spot!"), pa_ptr->m_name);
116     }
117 }
118
119 /*!
120  * @brief 急所を突く
121  * @param player_ptr プレイヤーへの参照ポインタ
122  * @param pa_ptr 直接攻撃構造体への参照ポインタ
123  */
124 void critical_attack(PlayerType *player_ptr, player_attack_type *pa_ptr)
125 {
126     auto *o_ptr = &player_ptr->inventory_list[enum2i(INVEN_MAIN_HAND) + pa_ptr->hand];
127     auto *r_ptr = &monraces_info[pa_ptr->m_ptr->r_idx];
128     if ((o_ptr->bi_key == BaseitemKey(ItemKindType::SWORD, SV_POISON_NEEDLE)) || (pa_ptr->mode == HISSATSU_KYUSHO)) {
129         if ((randint1(randint1(r_ptr->level / 7) + 5) == 1) && r_ptr->kind_flags.has_not(MonsterKindType::UNIQUE) && !(r_ptr->flags7 & RF7_UNIQUE2)) {
130             pa_ptr->attack_damage = pa_ptr->m_ptr->hp + 1;
131             msg_format(_("%sの急所を突き刺した!", "You hit %s on a fatal spot!"), pa_ptr->m_name);
132         } else {
133             pa_ptr->attack_damage = 1;
134         }
135
136         return;
137     }
138
139     if (!PlayerClass(player_ptr).equals(PlayerClassType::NINJA)) {
140         return;
141     }
142
143     const auto has_weapon = has_melee_weapon(player_ptr, enum2i(INVEN_MAIN_HAND) + pa_ptr->hand);
144     const auto is_ninja_hit = has_weapon && !player_ptr->is_icky_wield[pa_ptr->hand] && ((player_ptr->cur_lite <= 0) || one_in_(7));
145     if (is_ninja_hit) {
146         ninja_critical(player_ptr, pa_ptr);
147     }
148 }