OSDN Git Service

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