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 "system/player-type-definition.h"
33 #include "util/bit-flags-calculator.h"
34 #include "util/quarks.h"
35 #include "util/string-processor.h"
38 * @brief 耐性倍率計算の用途に応じた分岐処理
40 PERCENTAGE randrate(int dice, int fix, rate_calc_type_mode mode)
44 return randint1(dice) * 100 + fix * 100;
47 return (dice + 1) * 50 + fix * 100;
50 return (fix + 1) * 100;
53 return (dice + fix) * 100;
56 return (fix + 1) * 100;
62 * @brief 酸属性攻撃に対するダメージ倍率計算
64 PERCENTAGE calc_acid_damage_rate(player_type *creature_ptr)
68 if (has_immune_acid(creature_ptr)) {
72 BIT_FLAGS flgs = has_vuln_acid(creature_ptr);
74 for (BIT_FLAGS check_flag = 0x01U; check_flag < FLAG_CAUSE_MAX; check_flag <<= 1) {
75 if (any_bits(flgs, check_flag)) {
76 if (check_flag == FLAG_CAUSE_MUTATION) {
84 if (has_resist_acid(creature_ptr))
86 if (is_oppose_acid(creature_ptr))
93 * @brief 電撃属性攻撃に対するダメージ倍率計算
95 PERCENTAGE calc_elec_damage_rate(player_type *creature_ptr)
99 if (has_immune_elec(creature_ptr)) {
103 BIT_FLAGS flgs = has_vuln_elec(creature_ptr);
104 for (BIT_FLAGS check_flag = 0x01U; check_flag < FLAG_CAUSE_MAX; check_flag <<= 1) {
105 if (any_bits(flgs, check_flag)) {
106 if (check_flag == FLAG_CAUSE_MUTATION) {
114 if (has_resist_elec(creature_ptr))
116 if (is_oppose_elec(creature_ptr))
123 * @brief 火炎属性攻撃に対するダメージ倍率計算
125 PERCENTAGE calc_fire_damage_rate(player_type *creature_ptr)
127 PERCENTAGE per = 100;
128 BIT_FLAGS flgs = has_vuln_fire(creature_ptr);
129 for (BIT_FLAGS check_flag = 0x01U; check_flag < FLAG_CAUSE_MAX; check_flag <<= 1) {
130 if (any_bits(flgs, check_flag)) {
131 if (check_flag == FLAG_CAUSE_MUTATION) {
139 /* Resist the damage */
140 if (has_resist_fire(creature_ptr))
142 if (is_oppose_fire(creature_ptr))
149 * @brief 冷気属性攻撃に対するダメージ倍率計算
151 PERCENTAGE calc_cold_damage_rate(player_type *creature_ptr)
153 PERCENTAGE per = 100;
154 BIT_FLAGS flgs = has_vuln_cold(creature_ptr);
155 for (BIT_FLAGS check_flag = 0x01U; check_flag < FLAG_CAUSE_MAX; check_flag <<= 1) {
156 if (any_bits(flgs, check_flag)) {
157 if (check_flag == FLAG_CAUSE_MUTATION) {
165 if (has_resist_cold(creature_ptr))
167 if (is_oppose_cold(creature_ptr))
174 * @brief 毒属性攻撃に対するダメージ倍率計算
176 PERCENTAGE calc_pois_damage_rate(player_type *creature_ptr)
178 PERCENTAGE per = 100;
179 if (has_resist_pois(creature_ptr))
181 if (is_oppose_pois(creature_ptr))
188 * @brief 放射性廃棄物攻撃に対するダメージ倍率計算
190 PERCENTAGE calc_nuke_damage_rate(player_type *creature_ptr)
193 PERCENTAGE per = 100;
194 if (has_resist_pois(creature_ptr))
195 per = (2 * per + 2) / 5;
196 if (is_oppose_pois(creature_ptr))
197 per = (2 * per + 2) / 5;
203 * @brief 死の光線に対するダメージ倍率計算
205 PERCENTAGE calc_deathray_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
207 (void)mode; // unused
208 if (creature_ptr->mimic_form) {
209 if (mimic_info[creature_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING) {
214 switch (creature_ptr->prace) {
232 * @brief 閃光属性攻撃に対するダメージ倍率計算
234 PERCENTAGE calc_lite_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
236 PERCENTAGE per = 100;
238 if (player_race_has_flag(creature_ptr, TR_VUL_LITE)) {
239 switch (player_race_life(creature_ptr)) {
240 case PlayerRaceLife::UNDEAD:
249 if (has_resist_lite(creature_ptr)) {
251 per /= randrate(4, 7, mode);
254 if (creature_ptr->wraith_form)
261 * @brief 暗黒属性攻撃に対するダメージ倍率計算
263 PERCENTAGE calc_dark_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
265 PERCENTAGE per = 100;
267 if (has_immune_dark(creature_ptr))
270 if (has_resist_dark(creature_ptr)) {
272 per /= randrate(4, 7, mode);
279 * @brief 破片属性攻撃に対するダメージ倍率計算
281 PERCENTAGE calc_shards_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
283 PERCENTAGE per = 100;
285 if (has_resist_shard(creature_ptr)) {
287 per /= randrate(4, 7, mode);
294 * @brief 轟音属性攻撃に対するダメージ倍率計算
296 PERCENTAGE calc_sound_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
298 PERCENTAGE per = 100;
300 if (has_resist_sound(creature_ptr)) {
302 per /= randrate(4, 7, mode);
309 * @brief 混乱属性攻撃に対するダメージ倍率計算
311 PERCENTAGE calc_conf_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
313 PERCENTAGE per = 100;
315 if (has_resist_conf(creature_ptr)) {
317 per /= randrate(4, 7, mode);
324 * @brief 混沌属性攻撃に対するダメージ倍率計算
326 PERCENTAGE calc_chaos_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
328 PERCENTAGE per = 100;
330 if (has_resist_chaos(creature_ptr)) {
332 per /= randrate(4, 7, mode);
339 * @brief 劣化属性攻撃に対するダメージ倍率計算
341 PERCENTAGE calc_disenchant_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
343 PERCENTAGE per = 100;
345 if (has_resist_disen(creature_ptr)) {
347 per /= randrate(4, 7, mode);
354 * @brief 因果混乱属性攻撃に対するダメージ倍率計算
356 PERCENTAGE calc_nexus_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
358 PERCENTAGE per = 100;
360 if (has_resist_disen(creature_ptr)) {
362 per /= randrate(4, 7, mode);
369 * @brief ロケット属性攻撃に対するダメージ倍率計算
371 PERCENTAGE calc_rocket_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
373 (void)mode; // unused
374 PERCENTAGE per = 100;
376 if (has_resist_shard(creature_ptr)) {
384 * @brief 地獄属性攻撃に対するダメージ倍率計算
386 PERCENTAGE calc_nether_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
388 PERCENTAGE per = 100;
390 if (has_resist_neth(creature_ptr)) {
391 if (!is_specific_player_race(creature_ptr, RACE_SPECTRE))
394 per /= randrate(4, 7, mode);
401 * @brief 時間逆転攻撃に対するダメージ倍率計算
403 PERCENTAGE calc_time_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
405 (void)mode; // unused
406 PERCENTAGE per = 100;
408 if (has_resist_time(creature_ptr)) {
410 per /= randrate(4, 7, mode);
417 * @brief 水流攻撃に対するダメージ倍率計算
419 PERCENTAGE calc_water_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
421 (void)mode; // unused
422 PERCENTAGE per = 100;
424 if (has_resist_water(creature_ptr)) {
426 per /= randrate(4, 7, mode);
433 * @brief 聖なる火炎攻撃に対するダメージ倍率計算
435 PERCENTAGE calc_holy_fire_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
437 (void)mode; // unused
438 PERCENTAGE per = 100;
439 if (creature_ptr->alignment > 10)
441 else if (creature_ptr->alignment < -10)
447 * @brief 地獄の火炎攻撃に対するダメージ倍率計算
449 PERCENTAGE calc_hell_fire_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
451 (void)mode; // unused
452 PERCENTAGE per = 100;
453 if (creature_ptr->alignment > 10)
459 * @brief 重力攻撃に対するダメージ倍率計算
461 PERCENTAGE calc_gravity_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
463 (void)mode; // unused
464 PERCENTAGE per = 100;
465 if (creature_ptr->levitation) {
472 * @brief 虚無攻撃に対するダメージ倍率計算
474 PERCENTAGE calc_void_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
476 (void)mode; // unused
477 PERCENTAGE per = 100;
478 if (creature_ptr->tim_pass_wall) {
480 } else if (creature_ptr->anti_tele) {
482 per /= randrate(4, 7, mode);
483 } else if (creature_ptr->levitation) {
490 * @brief 深淵攻撃に対するダメージ倍率計算
492 PERCENTAGE calc_abyss_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
494 (void)mode; // unused
495 PERCENTAGE per = 100;
497 if (has_resist_dark(creature_ptr)) {
499 per /= randrate(4, 7, mode);
500 } else if (!creature_ptr->levitation && creature_ptr->anti_tele) {