1 #include "player/player-status-resist.h"
2 #include "artifact/fixed-art-types.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"
37 * @brief 耐性倍率計算の用途に応じた分岐処理
39 PERCENTAGE randrate(int dice, int fix, rate_calc_type_mode mode)
43 return randint1(dice) * 100 + fix * 100;
46 return (dice + 1) * 50 + fix * 100;
49 return (fix + 1) * 100;
52 return (dice + fix) * 100;
55 return (fix + 1) * 100;
61 * @brief 酸属性攻撃に対するダメージ倍率計算
63 PERCENTAGE calc_acid_damage_rate(player_type *creature_ptr)
67 if (has_immune_acid(creature_ptr)) {
71 BIT_FLAGS flgs = has_vuln_acid(creature_ptr);
73 for (BIT_FLAGS check_flag = 0x01U; check_flag < FLAG_CAUSE_MAX; check_flag <<= 1) {
74 if (any_bits(flgs, check_flag)) {
75 if (check_flag == FLAG_CAUSE_MUTATION) {
83 if (has_resist_acid(creature_ptr))
85 if (is_oppose_acid(creature_ptr))
92 * @brief 電撃属性攻撃に対するダメージ倍率計算
94 PERCENTAGE calc_elec_damage_rate(player_type *creature_ptr)
98 if (has_immune_elec(creature_ptr)) {
102 BIT_FLAGS flgs = has_vuln_elec(creature_ptr);
103 for (BIT_FLAGS check_flag = 0x01U; check_flag < FLAG_CAUSE_MAX; check_flag <<= 1) {
104 if (any_bits(flgs, check_flag)) {
105 if (check_flag == FLAG_CAUSE_MUTATION) {
113 if (has_resist_elec(creature_ptr))
115 if (is_oppose_elec(creature_ptr))
122 * @brief 火炎属性攻撃に対するダメージ倍率計算
124 PERCENTAGE calc_fire_damage_rate(player_type *creature_ptr)
126 PERCENTAGE per = 100;
127 BIT_FLAGS flgs = has_vuln_fire(creature_ptr);
128 for (BIT_FLAGS check_flag = 0x01U; check_flag < FLAG_CAUSE_MAX; check_flag <<= 1) {
129 if (any_bits(flgs, check_flag)) {
130 if (check_flag == FLAG_CAUSE_MUTATION) {
138 /* Resist the damage */
139 if (has_resist_fire(creature_ptr))
141 if (is_oppose_fire(creature_ptr))
148 * @brief 冷気属性攻撃に対するダメージ倍率計算
150 PERCENTAGE calc_cold_damage_rate(player_type *creature_ptr)
152 PERCENTAGE per = 100;
153 BIT_FLAGS flgs = has_vuln_cold(creature_ptr);
154 for (BIT_FLAGS check_flag = 0x01U; check_flag < FLAG_CAUSE_MAX; check_flag <<= 1) {
155 if (any_bits(flgs, check_flag)) {
156 if (check_flag == FLAG_CAUSE_MUTATION) {
164 if (has_resist_cold(creature_ptr))
166 if (is_oppose_cold(creature_ptr))
173 * @brief 毒属性攻撃に対するダメージ倍率計算
175 PERCENTAGE calc_pois_damage_rate(player_type *creature_ptr)
177 PERCENTAGE per = 100;
178 if (has_resist_pois(creature_ptr))
180 if (is_oppose_pois(creature_ptr))
187 * @brief 放射性廃棄物攻撃に対するダメージ倍率計算
189 PERCENTAGE calc_nuke_damage_rate(player_type *creature_ptr)
192 PERCENTAGE per = 100;
193 if (has_resist_pois(creature_ptr))
194 per = (2 * per + 2) / 5;
195 if (is_oppose_pois(creature_ptr))
196 per = (2 * per + 2) / 5;
202 * @brief 死の光線に対するダメージ倍率計算
204 PERCENTAGE calc_deathray_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
206 (void)mode; // unused
207 if (creature_ptr->mimic_form) {
208 if (mimic_info[creature_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING) {
213 switch (creature_ptr->prace) {
231 * @brief 閃光属性攻撃に対するダメージ倍率計算
233 PERCENTAGE calc_lite_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
235 PERCENTAGE per = 100;
237 if (player_race_has_flag(creature_ptr, TR_VUL_LITE)) {
238 switch (player_race_life(creature_ptr)) {
239 case PlayerRaceLife::UNDEAD:
248 if (has_resist_lite(creature_ptr)) {
250 per /= randrate(4, 7, mode);
253 if (creature_ptr->wraith_form)
260 * @brief 暗黒属性攻撃に対するダメージ倍率計算
262 PERCENTAGE calc_dark_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
264 PERCENTAGE per = 100;
266 if (has_immune_dark(creature_ptr))
269 if (has_resist_dark(creature_ptr)) {
271 per /= randrate(4, 7, mode);
278 * @brief 破片属性攻撃に対するダメージ倍率計算
280 PERCENTAGE calc_shards_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
282 PERCENTAGE per = 100;
284 if (has_resist_shard(creature_ptr)) {
286 per /= randrate(4, 7, mode);
293 * @brief 轟音属性攻撃に対するダメージ倍率計算
295 PERCENTAGE calc_sound_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
297 PERCENTAGE per = 100;
299 if (has_resist_sound(creature_ptr)) {
301 per /= randrate(4, 7, mode);
308 * @brief 混乱属性攻撃に対するダメージ倍率計算
310 PERCENTAGE calc_conf_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
312 PERCENTAGE per = 100;
314 if (has_resist_conf(creature_ptr)) {
316 per /= randrate(4, 7, mode);
323 * @brief 混沌属性攻撃に対するダメージ倍率計算
325 PERCENTAGE calc_chaos_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
327 PERCENTAGE per = 100;
329 if (has_resist_chaos(creature_ptr)) {
331 per /= randrate(4, 7, mode);
338 * @brief 劣化属性攻撃に対するダメージ倍率計算
340 PERCENTAGE calc_disenchant_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
342 PERCENTAGE per = 100;
344 if (has_resist_disen(creature_ptr)) {
346 per /= randrate(4, 7, mode);
353 * @brief 因果混乱属性攻撃に対するダメージ倍率計算
355 PERCENTAGE calc_nexus_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
357 PERCENTAGE per = 100;
359 if (has_resist_disen(creature_ptr)) {
361 per /= randrate(4, 7, mode);
368 * @brief ロケット属性攻撃に対するダメージ倍率計算
370 PERCENTAGE calc_rocket_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
372 (void)mode; // unused
373 PERCENTAGE per = 100;
375 if (has_resist_shard(creature_ptr)) {
383 * @brief 地獄属性攻撃に対するダメージ倍率計算
385 PERCENTAGE calc_nether_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
387 PERCENTAGE per = 100;
389 if (has_resist_neth(creature_ptr)) {
390 if (!is_specific_player_race(creature_ptr, RACE_SPECTRE))
393 per /= randrate(4, 7, mode);
400 * @brief 時間逆転攻撃に対するダメージ倍率計算
402 PERCENTAGE calc_time_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
404 (void)mode; // unused
405 PERCENTAGE per = 100;
407 if (has_resist_time(creature_ptr)) {
409 per /= randrate(4, 7, mode);
416 * @brief 水流攻撃に対するダメージ倍率計算
418 PERCENTAGE calc_water_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
420 (void)mode; // unused
421 PERCENTAGE per = 100;
423 if (has_resist_water(creature_ptr)) {
425 per /= randrate(4, 7, mode);
432 * @brief 聖なる火炎攻撃に対するダメージ倍率計算
434 PERCENTAGE calc_holy_fire_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
436 (void)mode; // unused
437 PERCENTAGE per = 100;
438 if (creature_ptr->align > 10)
440 else if (creature_ptr->align < -10)
446 * @brief 地獄の火炎攻撃に対するダメージ倍率計算
448 PERCENTAGE calc_hell_fire_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
450 (void)mode; // unused
451 PERCENTAGE per = 100;
452 if (creature_ptr->align > 10)
458 * @brief 重力攻撃に対するダメージ倍率計算
460 PERCENTAGE calc_gravity_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
462 (void)mode; // unused
463 PERCENTAGE per = 100;
464 if (creature_ptr->levitation) {
471 * @brief 虚無攻撃に対するダメージ倍率計算
473 PERCENTAGE calc_void_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
475 (void)mode; // unused
476 PERCENTAGE per = 100;
477 if (creature_ptr->tim_pass_wall) {
479 } else if (creature_ptr->anti_tele) {
481 per /= randrate(4, 7, mode);
482 } else if (creature_ptr->levitation) {
489 * @brief 深淵攻撃に対するダメージ倍率計算
491 PERCENTAGE calc_abyss_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
493 (void)mode; // unused
494 PERCENTAGE per = 100;
496 if (has_resist_dark(creature_ptr)) {
498 per /= randrate(4, 7, mode);
499 } else if (!creature_ptr->levitation && creature_ptr->anti_tele) {