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 "object/tval-types.h"
7 #include "player-attack/player-attack.h"
8 #include "player-base/player-class.h"
9 #include "player-info/equipment-info.h"
10 #include "sv-definition/sv-weapon-types.h"
11 #include "system/item-entity.h"
12 #include "system/monster-entity.h"
13 #include "system/monster-race-info.h"
14 #include "system/player-type-definition.h"
15 #include "view/display-messages.h"
18 * @brief クリティカルダメージを適用する
20 * @param k クリティカルの強度を決定する値
21 * @param base_dam クリティカル適用前のダメージ
22 * @param mult 期待値計算時のdam倍率
23 * @return クリティカルを適用したダメージと、クリティカル発生時に表示するメッセージと、クリティカル効果音のタプルを返す
25 std::tuple<int, concptr, sound_type> apply_critical_norm_damage(int k, int base_dam, int mult)
28 return { 2 * base_dam + 5 * mult, _("手ごたえがあった!", "It was a good hit!"), SOUND_GOOD_HIT };
31 return { 2 * base_dam + 10 * mult, _("かなりの手ごたえがあった!", "It was a great hit!"), SOUND_GREAT_HIT };
34 return { 3 * base_dam + 15 * mult, _("会心の一撃だ!", "It was a superb hit!"), SOUND_SUPERB_HIT };
37 return { 3 * base_dam + 20 * mult, _("最高の会心の一撃だ!", "It was a *GREAT* hit!"), SOUND_STAR_GREAT_HIT };
39 return { ((7 * base_dam) / 2) + 25 * mult, _("比類なき最高の会心の一撃だ!", "It was a *SUPERB* hit!"), SOUND_STAR_SUPERB_HIT };
43 * @brief プレイヤーからモンスターへの打撃クリティカル判定 /
44 * Critical hits (by player) Factor in weapon weight, total plusses, player melee bonus
47 * @param dam 現在算出中のダメージ値
48 * @param meichuu 打撃の基本命中力
49 * @param mode オプションフラグ
50 * @return クリティカル修正が入ったダメージ値
52 int critical_norm(PlayerType *player_ptr, WEIGHT weight, int plus, int dam, int16_t meichuu, combat_options mode, bool impact)
54 /* Extract "blow" power */
55 int i = (weight + (meichuu * 3 + plus * 5) + player_ptr->skill_thn);
58 auto pow = PlayerClass(player_ptr).equals(PlayerClassType::NINJA) ? 4444 : 5000;
63 bool is_special_option = randint1(pow) <= i;
64 is_special_option |= mode == HISSATSU_MAJIN;
65 is_special_option |= mode == HISSATSU_3DAN;
66 if (!is_special_option) {
70 int k = weight + randint1(650);
71 if (impact || (mode == HISSATSU_MAJIN) || (mode == HISSATSU_3DAN)) {
75 auto [critical_dam, msg, battle_sound] = apply_critical_norm_damage(k, dam);
83 * @param player_ptr プレイヤーへの参照ポインタ
84 * @param pa_ptr 直接攻撃構造体への参照ポインタ
85 * @details 闇討ち&追討ちを実施した後に致命傷チェックを行う
86 * チェックを通ったら、ユニークならば2倍ダメージ、それ以外は一撃死
87 * @todo 3つの処理をdetailsに書くよりは関数自体を分割すべきだが、一旦後回しにする。他の項目と一緒に処理する
89 static void ninja_critical(PlayerType *player_ptr, player_attack_type *pa_ptr)
91 auto *r_ptr = &pa_ptr->m_ptr->get_monrace();
92 int maxhp = pa_ptr->m_ptr->maxhp;
93 if (one_in_(pa_ptr->backstab ? 13 : (pa_ptr->stab_fleeing || pa_ptr->surprise_attack) ? 15
95 pa_ptr->attack_damage *= 5;
96 pa_ptr->drain_result *= 2;
97 msg_format(_("刃が%sに深々と突き刺さった!", "You critically injured %s!"), pa_ptr->m_name);
101 const auto no_instantly_death = r_ptr->resistance_flags.has(MonsterResistanceType::NO_INSTANTLY_DEATH);
102 bool is_weaken = pa_ptr->m_ptr->hp < maxhp / 2;
103 bool is_unique = r_ptr->kind_flags.has(MonsterKindType::UNIQUE) || no_instantly_death;
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);
109 if (is_unique || !is_weaken) {
110 if (no_instantly_death) {
111 r_ptr->r_resistance_flags.set(MonsterResistanceType::NO_INSTANTLY_DEATH);
113 pa_ptr->attack_damage = std::max(pa_ptr->attack_damage * 5, pa_ptr->m_ptr->hp / 2);
114 pa_ptr->drain_result *= 2;
115 msg_format(_("%sに致命傷を負わせた!", "You fatally injured %s!"), pa_ptr->m_name);
117 pa_ptr->attack_damage = pa_ptr->m_ptr->hp + 1;
118 msg_format(_("刃が%sの急所を貫いた!", "You hit %s on a fatal spot!"), pa_ptr->m_name);
124 * @param player_ptr プレイヤーへの参照ポインタ
125 * @param pa_ptr 直接攻撃構造体への参照ポインタ
127 void critical_attack(PlayerType *player_ptr, player_attack_type *pa_ptr)
129 auto *o_ptr = &player_ptr->inventory_list[enum2i(INVEN_MAIN_HAND) + pa_ptr->hand];
130 auto *r_ptr = &pa_ptr->m_ptr->get_monrace();
131 const auto no_instantly_death = r_ptr->resistance_flags.has(MonsterResistanceType::NO_INSTANTLY_DEATH);
132 if ((o_ptr->bi_key == BaseitemKey(ItemKindType::SWORD, SV_POISON_NEEDLE)) || (pa_ptr->mode == HISSATSU_KYUSHO)) {
133 if ((randint1(randint1(r_ptr->level / 7) + 5) == 1) && r_ptr->kind_flags.has_not(MonsterKindType::UNIQUE) && !no_instantly_death) {
134 pa_ptr->attack_damage = pa_ptr->m_ptr->hp + 1;
135 msg_format(_("%sの急所を突き刺した!", "You hit %s on a fatal spot!"), pa_ptr->m_name);
137 if (no_instantly_death) {
138 r_ptr->r_resistance_flags.set(MonsterResistanceType::NO_INSTANTLY_DEATH);
140 pa_ptr->attack_damage = 1;
146 if (!PlayerClass(player_ptr).equals(PlayerClassType::NINJA)) {
150 const auto has_weapon = has_melee_weapon(player_ptr, enum2i(INVEN_MAIN_HAND) + pa_ptr->hand);
151 const auto is_ninja_hit = has_weapon && !player_ptr->is_icky_wield[pa_ptr->hand] && ((player_ptr->cur_lite <= 0) || one_in_(7));
153 ninja_critical(player_ptr, pa_ptr);