OSDN Git Service

[Refactor] #38844 Continued removing inclusion of monster-race.h in angband.h
[hengband/hengband.git] / src / combat / attack-criticality.c
1 #include "combat/combat-options-type.h"
2 #include "combat/attack-criticality.h"
3 #include "monster-race/monster-race.h"
4 #include "monster-race/race-flags1.h"
5 #include "monster-race/race-flags7.h"
6 #include "sv-definition/sv-weapon-types.h"
7 #include "view/display-messages.h"
8
9 /*!
10 * @brief プレイヤーからモンスターへの打撃クリティカル判定 /
11 * Critical hits (by player) Factor in weapon weight, total plusses, player melee bonus
12 * @param weight 矢弾の重量
13 * @param plus 武器の命中修正
14 * @param dam 現在算出中のダメージ値
15 * @param meichuu 打撃の基本命中力
16 * @param mode オプションフラグ
17 * @return クリティカル修正が入ったダメージ値
18 */
19 HIT_POINT critical_norm(player_type *attacker_ptr, WEIGHT weight, int plus, HIT_POINT dam, s16b meichuu, combat_options mode)
20 {
21     /* Extract "blow" power */
22     int i = (weight + (meichuu * 3 + plus * 5) + attacker_ptr->skill_thn);
23
24     /* Chance */
25     bool is_special_option = randint1((attacker_ptr->pclass == CLASS_NINJA) ? 4444 : 5000) <= i;
26     is_special_option |= mode == HISSATSU_MAJIN;
27     is_special_option |= mode == HISSATSU_3DAN;
28     if (!is_special_option)
29         return dam;
30
31     int k = weight + randint1(650);
32     if ((mode == HISSATSU_MAJIN) || (mode == HISSATSU_3DAN))
33         k += randint1(650);
34
35     if (k < 400) {
36         msg_print(_("手ごたえがあった!", "It was a good hit!"));
37
38         dam = 2 * dam + 5;
39         return dam;
40     }
41
42     if (k < 700) {
43         msg_print(_("かなりの手ごたえがあった!", "It was a great hit!"));
44         dam = 2 * dam + 10;
45         return dam;
46     }
47
48     if (k < 900) {
49         msg_print(_("会心の一撃だ!", "It was a superb hit!"));
50         dam = 3 * dam + 15;
51         return dam;
52     }
53
54     if (k < 1300) {
55         msg_print(_("最高の会心の一撃だ!", "It was a *GREAT* hit!"));
56         dam = 3 * dam + 20;
57         return dam;
58     }
59
60     msg_print(_("比類なき最高の会心の一撃だ!", "It was a *SUPERB* hit!"));
61     dam = ((7 * dam) / 2) + 25;
62     return dam;
63 }
64
65 /*!
66  * @brief モンスター打撃のクリティカルランクを返す /
67  * Critical blow. All hits that do 95% of total possible damage,
68  * @param dice モンスター打撃のダイス数
69  * @param sides モンスター打撃の最大ダイス目
70  * @param dam プレイヤーに与えたダメージ
71  * @details
72  * and which also do at least 20 damage, or, sometimes, N damage.
73  * This is used only to determine "cuts" and "stuns".
74  */
75 int calc_monster_critical(DICE_NUMBER dice, DICE_SID sides, HIT_POINT dam)
76 {
77     int total = dice * sides;
78     if (dam < total * 19 / 20)
79         return 0;
80
81     if ((dam < 20) && (randint0(100) >= dam))
82         return 0;
83
84     int max = 0;
85     if ((dam >= total) && (dam >= 40))
86         max++;
87
88     if (dam >= 20)
89         while (randint0(100) < 2)
90             max++;
91
92     if (dam > 45)
93         return (6 + max);
94
95     if (dam > 33)
96         return (5 + max);
97
98     if (dam > 25)
99         return (4 + max);
100
101     if (dam > 18)
102         return (3 + max);
103
104     if (dam > 11)
105         return (2 + max);
106
107     return (1 + max);
108 }
109
110 /*!
111  * @brief 忍者ヒットで急所を突く
112  * @param attacker_ptr プレーヤーへの参照ポインタ
113  * @param pa_ptr 直接攻撃構造体への参照ポインタ
114  * @return なし
115  */
116 static void ninja_critical(player_type *attacker_ptr, player_attack_type *pa_ptr)
117 {
118     monster_race *r_ptr = &r_info[pa_ptr->m_ptr->r_idx];
119     int maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
120     if (one_in_(pa_ptr->backstab ? 13 : (pa_ptr->stab_fleeing || pa_ptr->surprise_attack) ? 15 : 27)) {
121         pa_ptr->attack_damage *= 5;
122         pa_ptr->drain_result *= 2;
123         msg_format(_("刃が%sに深々と突き刺さった!", "You critically injured %s!"), pa_ptr->m_name);
124         return;
125     }
126
127     bool is_critical = ((pa_ptr->m_ptr->hp < maxhp / 2) && one_in_((attacker_ptr->num_blow[0] + attacker_ptr->num_blow[1] + 1) * 10))
128         || ((one_in_(666) || ((pa_ptr->backstab || pa_ptr->surprise_attack) && one_in_(11))) && ((r_ptr->flags1 & RF1_UNIQUE) == 0)
129             && ((r_ptr->flags7 & RF7_UNIQUE2) == 0));
130     if (!is_critical)
131         return;
132
133     if ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE2) || (pa_ptr->m_ptr->hp >= maxhp / 2)) {
134         pa_ptr->attack_damage = MAX(pa_ptr->attack_damage * 5, pa_ptr->m_ptr->hp / 2);
135         pa_ptr->drain_result *= 2;
136         msg_format(_("%sに致命傷を負わせた!", "You fatally injured %s!"), pa_ptr->m_name);
137     } else {
138         pa_ptr->attack_damage = pa_ptr->m_ptr->hp + 1;
139         msg_format(_("刃が%sの急所を貫いた!", "You hit %s on a fatal spot!"), pa_ptr->m_name);
140     }
141 }
142
143 /*!
144  * @brief 急所を突く
145  * @param attacker_ptr プレーヤーへの参照ポインタ
146  * @param pa_ptr 直接攻撃構造体への参照ポインタ
147  * @return なし
148  */
149 void critical_attack(player_type *attacker_ptr, player_attack_type *pa_ptr)
150 {
151     object_type *o_ptr = &attacker_ptr->inventory_list[INVEN_RARM + pa_ptr->hand];
152     monster_race *r_ptr = &r_info[pa_ptr->m_ptr->r_idx];
153     if (((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_POISON_NEEDLE)) || (pa_ptr->mode == HISSATSU_KYUSHO)) {
154         if ((randint1(randint1(r_ptr->level / 7) + 5) == 1) && !(r_ptr->flags1 & RF1_UNIQUE) && !(r_ptr->flags7 & RF7_UNIQUE2)) {
155             pa_ptr->attack_damage = pa_ptr->m_ptr->hp + 1;
156             msg_format(_("%sの急所を突き刺した!", "You hit %s on a fatal spot!"), pa_ptr->m_name);
157         } else
158             pa_ptr->attack_damage = 1;
159
160         return;
161     }
162
163     bool is_ninja_hit = (attacker_ptr->pclass == CLASS_NINJA) && has_melee_weapon(attacker_ptr, INVEN_RARM + pa_ptr->hand)
164         && !attacker_ptr->icky_wield[pa_ptr->hand] && ((attacker_ptr->cur_lite <= 0) || one_in_(7));
165     if (is_ninja_hit)
166         ninja_critical(attacker_ptr, pa_ptr);
167 }