OSDN Git Service

5d6dfaf9ba1df7dd0055b9ce5a2de4d099c57074
[hengbandforosx/hengbandosx.git] / src / status / element-resistance.cpp
1 #include "status/element-resistance.h"
2 #include "core/disturbance.h"
3 #include "core/player-redraw-types.h"
4 #include "core/stuff-handler.h"
5 #include "game-option/disturbance-options.h"
6 #include "player/player-race.h"
7 #include "player/special-defense-types.h"
8 #include "realm/realm-song-numbers.h"
9 #include "spell-realm/spells-song.h"
10 #include "system/player-type-definition.h"
11 #include "view/display-messages.h"
12
13 /*!
14  * @brief 一時的酸耐性の継続時間をセットする / Set "oppose_acid", notice observable changes
15  * @param v 継続時間
16  * @param do_dec 現在の継続時間より長い値のみ上書きする
17  * @return ステータスに影響を及ぼす変化があった場合TRUEを返す。
18  */
19 bool set_oppose_acid(player_type *creature_ptr, TIME_EFFECT v, bool do_dec)
20 {
21     bool notice = FALSE;
22     v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
23     if (creature_ptr->is_dead)
24         return FALSE;
25
26     if (v) {
27         if (creature_ptr->oppose_acid && !do_dec) {
28             if (creature_ptr->oppose_acid > v)
29                 return FALSE;
30         } else if (!is_oppose_acid(creature_ptr)) {
31             msg_print(_("酸への耐性がついた気がする!", "You feel resistant to acid!"));
32             notice = TRUE;
33         }
34     } else {
35         if (creature_ptr->oppose_acid && !music_singing(creature_ptr, MUSIC_RESIST) && !(creature_ptr->special_defense & KATA_MUSOU)) {
36             msg_print(_("酸への耐性が薄れた気がする。", "You feel less resistant to acid."));
37             notice = TRUE;
38         }
39     }
40
41     creature_ptr->oppose_acid = v;
42
43     if (!notice)
44         return FALSE;
45     creature_ptr->redraw |= (PR_STATUS);
46
47     if (disturb_state)
48         disturb(creature_ptr, FALSE, FALSE);
49     handle_stuff(creature_ptr);
50     return TRUE;
51 }
52
53 /*!
54  * @brief 一時的電撃耐性の継続時間をセットする / Set "oppose_elec", notice observable changes
55  * @param v 継続時間
56  * @param do_dec 現在の継続時間より長い値のみ上書きする
57  * @return ステータスに影響を及ぼす変化があった場合TRUEを返す。
58  */
59 bool set_oppose_elec(player_type *creature_ptr, TIME_EFFECT v, bool do_dec)
60 {
61     bool notice = FALSE;
62     v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
63
64     if (creature_ptr->is_dead)
65         return FALSE;
66
67     if (v) {
68         if (creature_ptr->oppose_elec && !do_dec) {
69             if (creature_ptr->oppose_elec > v)
70                 return FALSE;
71         } else if (!is_oppose_elec(creature_ptr)) {
72             msg_print(_("電撃への耐性がついた気がする!", "You feel resistant to electricity!"));
73             notice = TRUE;
74         }
75     } else {
76         if (creature_ptr->oppose_elec && !music_singing(creature_ptr, MUSIC_RESIST) && !(creature_ptr->special_defense & KATA_MUSOU)) {
77             msg_print(_("電撃への耐性が薄れた気がする。", "You feel less resistant to electricity."));
78             notice = TRUE;
79         }
80     }
81
82     creature_ptr->oppose_elec = v;
83
84     if (!notice)
85         return FALSE;
86     creature_ptr->redraw |= (PR_STATUS);
87
88     if (disturb_state)
89         disturb(creature_ptr, FALSE, FALSE);
90     handle_stuff(creature_ptr);
91     return TRUE;
92 }
93
94 /*!
95  * @brief 一時的火炎耐性の継続時間をセットする / Set "oppose_fire", notice observable changes
96  * @param v 継続時間
97  * @param do_dec 現在の継続時間より長い値のみ上書きする
98  * @return ステータスに影響を及ぼす変化があった場合TRUEを返す。
99  */
100 bool set_oppose_fire(player_type *creature_ptr, TIME_EFFECT v, bool do_dec)
101 {
102     bool notice = FALSE;
103     v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
104     if (creature_ptr->is_dead)
105         return FALSE;
106
107     if ((is_specific_player_race(creature_ptr, RACE_BALROG) && (creature_ptr->lev > 44)) || (creature_ptr->mimic_form == MIMIC_DEMON))
108         v = 1;
109     if (v) {
110         if (creature_ptr->oppose_fire && !do_dec) {
111             if (creature_ptr->oppose_fire > v)
112                 return FALSE;
113         } else if (!is_oppose_fire(creature_ptr)) {
114             msg_print(_("火への耐性がついた気がする!", "You feel resistant to fire!"));
115             notice = TRUE;
116         }
117     } else {
118         if (creature_ptr->oppose_fire && !music_singing(creature_ptr, MUSIC_RESIST) && !(creature_ptr->special_defense & KATA_MUSOU)) {
119             msg_print(_("火への耐性が薄れた気がする。", "You feel less resistant to fire."));
120             notice = TRUE;
121         }
122     }
123
124     creature_ptr->oppose_fire = v;
125
126     if (!notice)
127         return FALSE;
128     creature_ptr->redraw |= (PR_STATUS);
129
130     if (disturb_state)
131         disturb(creature_ptr, FALSE, FALSE);
132     handle_stuff(creature_ptr);
133     return TRUE;
134 }
135
136 /*!
137  * @brief 一時的冷気耐性の継続時間をセットする / Set "oppose_cold", notice observable changes
138  * @param v 継続時間
139  * @param do_dec 現在の継続時間より長い値のみ上書きする
140  * @return ステータスに影響を及ぼす変化があった場合TRUEを返す。
141  */
142 bool set_oppose_cold(player_type *creature_ptr, TIME_EFFECT v, bool do_dec)
143 {
144     bool notice = FALSE;
145     v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
146     if (creature_ptr->is_dead)
147         return FALSE;
148
149     if (v) {
150         if (creature_ptr->oppose_cold && !do_dec) {
151             if (creature_ptr->oppose_cold > v)
152                 return FALSE;
153         } else if (!is_oppose_cold(creature_ptr)) {
154             msg_print(_("冷気への耐性がついた気がする!", "You feel resistant to cold!"));
155             notice = TRUE;
156         }
157     } else {
158         if (creature_ptr->oppose_cold && !music_singing(creature_ptr, MUSIC_RESIST) && !(creature_ptr->special_defense & KATA_MUSOU)) {
159             msg_print(_("冷気への耐性が薄れた気がする。", "You feel less resistant to cold."));
160             notice = TRUE;
161         }
162     }
163
164     creature_ptr->oppose_cold = v;
165
166     if (!notice)
167         return FALSE;
168     creature_ptr->redraw |= (PR_STATUS);
169
170     if (disturb_state)
171         disturb(creature_ptr, FALSE, FALSE);
172     handle_stuff(creature_ptr);
173     return TRUE;
174 }
175
176 /*!
177  * @brief 一時的毒耐性の継続時間をセットする / Set "oppose_pois", notice observable changes
178  * @param v 継続時間
179  * @param do_dec 現在の継続時間より長い値のみ上書きする
180  * @return ステータスに影響を及ぼす変化があった場合TRUEを返す。
181  */
182 bool set_oppose_pois(player_type *creature_ptr, TIME_EFFECT v, bool do_dec)
183 {
184     bool notice = FALSE;
185     v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
186     if ((creature_ptr->pclass == CLASS_NINJA) && (creature_ptr->lev > 44))
187         v = 1;
188     if (creature_ptr->is_dead)
189         return FALSE;
190
191     if (v) {
192         if (creature_ptr->oppose_pois && !do_dec) {
193             if (creature_ptr->oppose_pois > v)
194                 return FALSE;
195         } else if (!is_oppose_pois(creature_ptr)) {
196             msg_print(_("毒への耐性がついた気がする!", "You feel resistant to poison!"));
197             notice = TRUE;
198         }
199     } else {
200         if (creature_ptr->oppose_pois && !music_singing(creature_ptr, MUSIC_RESIST) && !(creature_ptr->special_defense & KATA_MUSOU)) {
201             msg_print(_("毒への耐性が薄れた気がする。", "You feel less resistant to poison."));
202             notice = TRUE;
203         }
204     }
205
206     creature_ptr->oppose_pois = v;
207     if (!notice)
208         return FALSE;
209     creature_ptr->redraw |= (PR_STATUS);
210
211     if (disturb_state)
212         disturb(creature_ptr, FALSE, FALSE);
213     handle_stuff(creature_ptr);
214     return TRUE;
215 }
216
217 bool is_oppose_acid(player_type *creature_ptr)
218 {
219     return creature_ptr->oppose_acid || music_singing(creature_ptr, MUSIC_RESIST) || (creature_ptr->special_defense & KATA_MUSOU);
220 }
221
222 bool is_oppose_elec(player_type *creature_ptr)
223 {
224     return creature_ptr->oppose_elec || music_singing(creature_ptr, MUSIC_RESIST) || (creature_ptr->special_defense & KATA_MUSOU);
225 }
226
227 bool is_oppose_fire(player_type *creature_ptr)
228 {
229     return creature_ptr->oppose_fire || music_singing(creature_ptr, MUSIC_RESIST)
230         || (creature_ptr->special_defense & KATA_MUSOU || (creature_ptr->mimic_form == MIMIC_DEMON)
231             || (is_specific_player_race(creature_ptr, RACE_BALROG) && creature_ptr->lev > 44));
232 }
233
234 bool is_oppose_cold(player_type *creature_ptr)
235 {
236     return creature_ptr->oppose_cold || music_singing(creature_ptr, MUSIC_RESIST) || (creature_ptr->special_defense & KATA_MUSOU);
237 }
238
239 bool is_oppose_pois(player_type *creature_ptr)
240 {
241     return creature_ptr->oppose_pois || music_singing(creature_ptr, MUSIC_RESIST)
242         || (creature_ptr->special_defense & KATA_MUSOU || (creature_ptr->pclass == CLASS_NINJA && creature_ptr->lev > 44));
243 }