OSDN Git Service

[Refactor] #40514 player_type の resist_chaos, resist_dark 変数を廃止. / Abolished the...
[hengband/hengband.git] / src / player / player-status-resist.c
1 #include "player/player-status-resist.h"
2 #include "artifact/fixed-art-types.h"
3 #include "grid/grid.h"
4 #include "inventory/inventory-slot-types.h"
5 #include "monster-race/monster-race.h"
6 #include "monster-race/race-flags2.h"
7 #include "monster-race/race-flags7.h"
8 #include "mutation/mutation-flag-types.h"
9 #include "object-enchant/object-ego.h"
10 #include "object-enchant/tr-types.h"
11 #include "object-enchant/trc-types.h"
12 #include "object-hook/hook-checker.h"
13 #include "object-hook/hook-weapon.h"
14 #include "object/object-flags.h"
15 #include "player/mimic-info-table.h"
16 #include "player/player-class.h"
17 #include "player/player-race-types.h"
18 #include "player/player-race.h"
19 #include "player/player-skill.h"
20 #include "player/player-status-flags.h"
21 #include "player/player-status.h"
22 #include "player/special-defense-types.h"
23 #include "realm/realm-hex-numbers.h"
24 #include "realm/realm-song-numbers.h"
25 #include "realm/realm-types.h"
26 #include "spell-realm/spells-hex.h"
27 #include "status/element-resistance.h"
28 #include "sv-definition/sv-weapon-types.h"
29 #include "system/floor-type-definition.h"
30 #include "system/monster-type-definition.h"
31 #include "system/object-type-definition.h"
32 #include "util/bit-flags-calculator.h"
33 #include "util/quarks.h"
34 #include "util/string-processor.h"
35
36 /*!
37  * @brief 耐性倍率計算の用途に応じた分岐処理
38  */
39 PERCENTAGE randrate(int dice, int fix, rate_calc_type_mode mode)
40 {
41     switch (mode) {
42     case CALC_RAND:
43         return randint1(dice) * 100 + fix * 100;
44         break;
45     case CALC_AVERAGE:
46         return (dice + 1) * 50 + fix * 100;
47         break;
48     case CALC_MIN:
49         return (fix + 1) * 100;
50         break;
51     case CALC_MAX:
52         return (dice + fix) * 100;
53         break;
54     default:
55         return (fix + 1) * 100;
56         break;
57     }
58 }
59
60 /*!
61  * @brief 酸属性攻撃に対するダメージ倍率計算
62  */
63 PERCENTAGE calc_acid_damage_rate(player_type *creature_ptr)
64 {
65     PERCENTAGE per = 100;
66
67     if (has_immune_acid(creature_ptr)) {
68         return 0;
69     }
70
71     BIT_FLAGS flgs = has_vuln_acid(creature_ptr);
72     for (int i = 0; i < FLAG_CAUSE_MAX; i++) {
73         if (flgs & (0x01 << i)) {
74             if (i == FLAG_CAUSE_MUTATION) {
75                 per *= 2;
76             } else {
77                 per += per / 3;
78             }
79         }
80     }
81
82     if (has_resist_acid(creature_ptr))
83         per = (per + 2) / 3;
84     if (is_oppose_acid(creature_ptr))
85         per = (per + 2) / 3;
86
87     return per;
88 }
89
90 /*!
91  * @brief 電撃属性攻撃に対するダメージ倍率計算
92  */
93 PERCENTAGE calc_elec_damage_rate(player_type *creature_ptr)
94 {
95     PERCENTAGE per = 100;
96
97     if (has_immune_elec(creature_ptr)) {
98         return 0;
99     }
100
101     BIT_FLAGS flgs = has_vuln_elec(creature_ptr);
102     for (int i = 0; i < FLAG_CAUSE_MAX; i++) {
103         if (flgs & (0x01 << i)) {
104             if (i == FLAG_CAUSE_MUTATION) {
105                 per *= 2;
106             } else {
107                 per += per / 3;
108             }
109         }
110     }
111
112     if (has_resist_elec(creature_ptr))
113         per = (per + 2) / 3;
114     if (is_oppose_elec(creature_ptr))
115         per = (per + 2) / 3;
116
117     return per;
118 }
119
120 /*!
121  * @brief 火炎属性攻撃に対するダメージ倍率計算
122  */
123 PERCENTAGE calc_fire_damage_rate(player_type *creature_ptr)
124 {
125     PERCENTAGE per = 100;
126     BIT_FLAGS flgs = has_vuln_fire(creature_ptr);
127      for (int i = 0; i < FLAG_CAUSE_MAX; i++) {
128         if (flgs & (0x01 << i)) {
129             if (i == FLAG_CAUSE_MUTATION) {
130                 per *= 2;
131             } else {
132                 per += per / 3;
133             }
134         }
135     }
136
137     /* Resist the damage */
138     if (has_resist_fire(creature_ptr))
139         per = (per + 2) / 3;
140     if (is_oppose_fire(creature_ptr))
141         per = (per + 2) / 3;
142
143     return per;
144 }
145
146 /*!
147  * @brief 冷気属性攻撃に対するダメージ倍率計算
148  */
149 PERCENTAGE calc_cold_damage_rate(player_type *creature_ptr)
150 {
151     PERCENTAGE per = 100;
152     BIT_FLAGS flgs = has_vuln_cold(creature_ptr);
153     for (int i = 0; i < FLAG_CAUSE_MAX; i++) {
154         if (flgs & (0x01 << i)) {
155             if (i == FLAG_CAUSE_MUTATION) {
156                 per *= 2;
157             } else {
158                 per += per / 3;
159             }
160         }
161     }
162
163     if (has_resist_cold(creature_ptr))
164         per = (per + 2) / 3;
165     if (is_oppose_cold(creature_ptr))
166         per = (per + 2) / 3;
167
168     return per;
169 }
170
171 /*!
172  * @brief 毒属性攻撃に対するダメージ倍率計算
173  */
174 PERCENTAGE calc_pois_damage_rate(player_type *creature_ptr)
175 {
176     PERCENTAGE per = 100;
177     if (has_resist_pois(creature_ptr))
178         per = (per + 2) / 3;
179     if (is_oppose_pois(creature_ptr))
180         per = (per + 2) / 3;
181
182     return per;
183 }
184
185 /*!
186  * @brief 放射性廃棄物攻撃に対するダメージ倍率計算
187  */
188 PERCENTAGE calc_nuke_damage_rate(player_type *creature_ptr)
189 {
190
191     PERCENTAGE per = 100;
192     if (has_resist_pois(creature_ptr))
193         per = (2 * per + 2) / 5;
194     if (is_oppose_pois(creature_ptr))
195         per = (2 * per + 2) / 5;
196
197     return per;
198 }
199
200 /*!
201  * @brief 死の光線に対するダメージ倍率計算
202  */
203 PERCENTAGE calc_deathray_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
204 {
205     (void)mode; // unused
206     if (creature_ptr->mimic_form) {
207         if (mimic_info[creature_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING) {
208             return 0;
209         }
210     }
211
212     switch (creature_ptr->prace) {
213     case RACE_GOLEM:
214     case RACE_SKELETON:
215     case RACE_ZOMBIE:
216     case RACE_VAMPIRE:
217     case RACE_BALROG:
218     case RACE_SPECTRE:
219         return 0;
220         break;
221     }
222
223     return 100;
224 }
225
226 /*!
227  * @brief 閃光属性攻撃に対するダメージ倍率計算
228  */
229 PERCENTAGE calc_lite_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
230 {
231     PERCENTAGE per = 100;
232     if (is_specific_player_race(creature_ptr, RACE_VAMPIRE) || (creature_ptr->mimic_form == MIMIC_VAMPIRE)) {
233         per *= 2;
234     } else if (is_specific_player_race(creature_ptr, RACE_S_FAIRY)) {
235         per = per * 4 / 3;
236     }
237
238     if (has_resist_lite(creature_ptr)) {
239         per *= 400;
240         per /= randrate(4, 7, mode);
241     }
242
243     if (creature_ptr->wraith_form)
244         per *= 2;
245
246     return per;
247 }
248
249 /*!
250  * @brief 暗黒属性攻撃に対するダメージ倍率計算
251  */
252 PERCENTAGE calc_dark_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
253 {
254     PERCENTAGE per = 100;
255
256     if (is_specific_player_race(creature_ptr, RACE_VAMPIRE) || (creature_ptr->mimic_form == MIMIC_VAMPIRE) || creature_ptr->wraith_form) {
257         return 0;
258     }
259
260     if (has_resist_dark(creature_ptr)) {
261         per *= 400;
262         per /= randrate(4, 7, mode);
263     }
264
265     return per;
266 }
267
268 /*!
269  * @brief 破片属性攻撃に対するダメージ倍率計算
270  */
271 PERCENTAGE calc_shards_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
272 {
273     PERCENTAGE per = 100;
274
275     if (creature_ptr->resist_shard) {
276         per *= 600;
277         per /= randrate(4, 7, mode);
278     }
279
280     return per;
281 }
282
283 /*!
284  * @brief 轟音属性攻撃に対するダメージ倍率計算
285  */
286 PERCENTAGE calc_sound_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
287 {
288     PERCENTAGE per = 100;
289
290     if (has_resist_sound(creature_ptr)) {
291         per *= 500;
292         per /= randrate(4, 7, mode);
293     }
294
295     return per;
296 }
297
298 /*!
299  * @brief 混乱属性攻撃に対するダメージ倍率計算
300  */
301 PERCENTAGE calc_conf_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
302 {
303     PERCENTAGE per = 100;
304
305     if (has_resist_conf(creature_ptr)) {
306         per *= 500;
307         per /= randrate(4, 7, mode);
308     }
309
310     return per;
311 }
312
313 /*!
314  * @brief 混沌属性攻撃に対するダメージ倍率計算
315  */
316 PERCENTAGE calc_chaos_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
317 {
318     PERCENTAGE per = 100;
319
320     if (has_resist_chaos(creature_ptr)) {
321         per *= 600;
322         per /= randrate(4, 7, mode);
323     }
324
325     return per;
326 }
327
328 /*!
329  * @brief 劣化属性攻撃に対するダメージ倍率計算
330  */
331 PERCENTAGE calc_disenchant_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
332 {
333     PERCENTAGE per = 100;
334
335     if (creature_ptr->resist_disen) {
336         per *= 600;
337         per /= randrate(4, 7, mode);
338     }
339
340     return per;
341 }
342
343 /*!
344  * @brief 因果混乱属性攻撃に対するダメージ倍率計算
345  */
346 PERCENTAGE calc_nexus_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
347 {
348     PERCENTAGE per = 100;
349
350     if (creature_ptr->resist_disen) {
351         per *= 600;
352         per /= randrate(4, 7, mode);
353     }
354
355     return per;
356 }
357
358 /*!
359  * @brief ロケット属性攻撃に対するダメージ倍率計算
360  */
361 PERCENTAGE calc_rocket_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
362 {
363     (void)mode; // unused
364     PERCENTAGE per = 100;
365
366     if (creature_ptr->resist_shard) {
367         per /= 2;
368     }
369
370     return per;
371 }
372
373 /*!
374  * @brief 地獄属性攻撃に対するダメージ倍率計算
375  */
376 PERCENTAGE calc_nether_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
377 {
378     PERCENTAGE per = 100;
379
380     if (creature_ptr->resist_neth) {
381         if (!is_specific_player_race(creature_ptr, RACE_SPECTRE))
382             per *= 6;
383         per *= 100;
384         per /= randrate(4, 7, mode);
385     }
386
387     return per;
388 }
389
390 /*!
391  * @brief 時間逆転攻撃に対するダメージ倍率計算
392  */
393 PERCENTAGE calc_time_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
394 {
395     (void)mode; // unused
396     PERCENTAGE per = 100;
397
398     if (creature_ptr->resist_time) {
399         per *= 400;
400         per /= randrate(4, 7, mode);
401     }
402
403     return per;
404 }
405
406 /*!
407  * @brief 聖なる火炎攻撃に対するダメージ倍率計算
408  */
409 PERCENTAGE calc_holy_fire_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
410 {
411     (void)mode; // unused
412     PERCENTAGE per = 100;
413     if (creature_ptr->align > 10)
414         per /= 2;
415     else if (creature_ptr->align < -10)
416         per *= 2;
417     return per;
418 }
419
420 /*!
421  * @brief 地獄の火炎攻撃に対するダメージ倍率計算
422  */
423 PERCENTAGE calc_hell_fire_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
424 {
425     (void)mode; // unused
426     PERCENTAGE per = 100;
427     if (creature_ptr->align > 10)
428         per *= 2;
429     return per;
430 }
431
432 /*!
433  * @brief 重力攻撃に対するダメージ倍率計算
434  */
435 PERCENTAGE calc_gravity_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
436 {
437     (void)mode; // unused
438     PERCENTAGE per = 100;
439     if (creature_ptr->levitation) {
440         per = (per * 2) / 3;
441     }
442     return per;
443 }