OSDN Git Service

Merge pull request #1344 from sikabane-works/feature/refactor-player_race_type
[hengbandforosx/hengbandosx.git] / src / specific-object / death-scythe.cpp
1 /*!
2  * @brief 死の大鎌に特有の処理
3  * @date 2020/05/23
4  * @author Hourier
5  * @details 現時点ではダメージ反射のみ。行数に注意して関数を追加しても良い.
6  */
7
8 #include "specific-object/death-scythe.h"
9 #include "combat/attack-criticality.h"
10 #include "core/player-redraw-types.h"
11 #include "core/stuff-handler.h"
12 #include "inventory/inventory-slot-types.h"
13 #include "main/sound-definitions-table.h"
14 #include "main/sound-of-music.h"
15 #include "object-enchant/tr-types.h"
16 #include "object/object-flags.h"
17 #include "player-attack/player-attack-util.h"
18 #include "player/player-damage.h"
19 #include "player/player-race.h"
20 #include "status/element-resistance.h"
21 #include "system/object-type-definition.h"
22 #include "system/player-type-definition.h"
23 #include "util/bit-flags-calculator.h"
24 #include "view/display-messages.h"
25 #include "player/player-status-flags.h"
26
27 /*!
28  * @brief 死の大鎌ダメージが跳ね返ってきた時の、種族ごとのダメージ倍率を返す
29  * @param attacker_ptr プレーヤーへの参照ポインタ
30  * @return 倍率 (実際は1/10になる)
31  */
32 static int calc_death_scythe_reflection_magnification_mimic_none(player_type *attacker_ptr)
33 {
34     switch (attacker_ptr->prace) {
35     case player_race_type::YEEK:
36     case player_race_type::KLACKON:
37     case player_race_type::HUMAN:
38     case player_race_type::AMBERITE:
39     case player_race_type::DUNADAN:
40     case player_race_type::BARBARIAN:
41     case player_race_type::BEASTMAN:
42         return 25;
43     case player_race_type::HALF_ORC:
44     case player_race_type::HALF_TROLL:
45     case player_race_type::HALF_OGRE:
46     case player_race_type::HALF_GIANT:
47     case player_race_type::HALF_TITAN:
48     case player_race_type::CYCLOPS:
49     case player_race_type::IMP:
50     case player_race_type::SKELETON:
51     case player_race_type::ZOMBIE:
52     case player_race_type::VAMPIRE:
53     case player_race_type::SPECTRE:
54     case player_race_type::BALROG:
55     case player_race_type::DRACONIAN:
56         return 30;
57     default:
58         return 10;
59     }
60 }
61
62 /*!
63  * @brief 死の大鎌ダメージが跳ね返ってきた時の、変身中の種族も考慮したダメージ倍率を返す
64  * @param attacker_ptr プレーヤーへの参照ポインタ
65  * @return 倍率 (実際は1/10になる)
66  */
67 static int calc_death_scythe_reflection_magnification(player_type *attacker_ptr)
68 {
69     switch (attacker_ptr->mimic_form) {
70     case MIMIC_NONE:
71         return calc_death_scythe_reflection_magnification_mimic_none(attacker_ptr);
72     case MIMIC_DEMON:
73     case MIMIC_DEMON_LORD:
74     case MIMIC_VAMPIRE:
75         return 30;
76     default:
77         return 10;
78     }
79 }
80
81 /*!
82  * @brief 耐性等に応じて死の大鎌による反射ダメージ倍率を補正する
83  * @param attacker_ptr プレーヤーへの参照ポインタ
84  * @param magnification ダメージ倍率
85  * @param death_scythe_flags 死の大鎌に関するオブジェクトフラグ配列
86  */
87 static void compensate_death_scythe_reflection_magnification(player_type *attacker_ptr, int *magnification, BIT_FLAGS *death_scythe_flags)
88 {
89     if ((attacker_ptr->alignment < 0) && (*magnification < 20))
90         *magnification = 20;
91
92     if (!(has_resist_acid(attacker_ptr) || is_oppose_acid(attacker_ptr) || has_immune_acid(attacker_ptr)) && (*magnification < 25))
93         *magnification = 25;
94
95     if (!(has_resist_elec(attacker_ptr) || is_oppose_elec(attacker_ptr) || has_immune_elec(attacker_ptr)) && (*magnification < 25))
96         *magnification = 25;
97
98     if (!(has_resist_fire(attacker_ptr) || is_oppose_fire(attacker_ptr) || has_immune_fire(attacker_ptr)) && (*magnification < 25))
99         *magnification = 25;
100
101     if (!(has_resist_cold(attacker_ptr) || is_oppose_cold(attacker_ptr) || has_immune_cold(attacker_ptr)) && (*magnification < 25))
102         *magnification = 25;
103
104     if (!(has_resist_pois(attacker_ptr) || is_oppose_pois(attacker_ptr)) && (*magnification < 25))
105         *magnification = 25;
106
107     if ((attacker_ptr->pclass != CLASS_SAMURAI) && (has_flag(death_scythe_flags, TR_FORCE_WEAPON)) && (attacker_ptr->csp > (attacker_ptr->msp / 30))) {
108         attacker_ptr->csp -= (1 + (attacker_ptr->msp / 30));
109         attacker_ptr->redraw |= (PR_MANA);
110         *magnification = *magnification * 3 / 2 + 20;
111     }
112 }
113
114 /*!
115  * @brief 死の大鎌による反射ダメージ倍率を更に上げる
116  * @param pa_ptr 直接攻撃構造体への参照ポインタ
117  */
118 static void death_scythe_reflection_critial_hit(player_attack_type *pa_ptr)
119 {
120     if (!one_in_(6))
121         return;
122
123     int more_magnification = 2;
124     msg_format(_("グッサリ切り裂かれた!", "Your weapon cuts deep into yourself!"));
125     while (one_in_(4))
126         more_magnification++;
127
128     pa_ptr->attack_damage *= (HIT_POINT)more_magnification;
129 }
130
131 /*!
132  * @brief 死の大鎌によるダメージ反射のメインルーチン
133  * @param attacker_ptr プレーヤーへの参照ポインタ
134  * @param pa_ptr 直接攻撃構造体への参照ポインタ
135  */
136 void process_death_scythe_reflection(player_type *attacker_ptr, player_attack_type *pa_ptr)
137 {
138     BIT_FLAGS death_scythe_flags[TR_FLAG_SIZE];
139     sound(SOUND_HIT);
140     msg_format(_("ミス! %sにかわされた。", "You miss %s."), pa_ptr->m_name);
141     msg_print(_("振り回した大鎌が自分自身に返ってきた!", "Your scythe returns to you!"));
142
143     object_type *o_ptr = &attacker_ptr->inventory_list[INVEN_MAIN_HAND + pa_ptr->hand];
144     object_flags(attacker_ptr, o_ptr, death_scythe_flags);
145     pa_ptr->attack_damage = damroll(o_ptr->dd + attacker_ptr->to_dd[pa_ptr->hand], o_ptr->ds + attacker_ptr->to_ds[pa_ptr->hand]);
146     int magnification = calc_death_scythe_reflection_magnification(attacker_ptr);
147     compensate_death_scythe_reflection_magnification(attacker_ptr, &magnification, death_scythe_flags);
148     pa_ptr->attack_damage *= (HIT_POINT)magnification;
149     pa_ptr->attack_damage /= 10;
150     pa_ptr->attack_damage = critical_norm(attacker_ptr, o_ptr->weight, o_ptr->to_h, pa_ptr->attack_damage, attacker_ptr->to_h[pa_ptr->hand], pa_ptr->mode);
151     death_scythe_reflection_critial_hit(pa_ptr);
152     pa_ptr->attack_damage += (attacker_ptr->to_d[pa_ptr->hand] + o_ptr->to_d);
153     if (pa_ptr->attack_damage < 0)
154         pa_ptr->attack_damage = 0;
155
156     take_hit(attacker_ptr, DAMAGE_FORCE, pa_ptr->attack_damage, _("死の大鎌", "Death scythe"));
157     handle_stuff(attacker_ptr);
158 }