OSDN Git Service

[Refactor] #40514 calc_disenchant_damage_rate() 実装. / Implement calc_disenchant_damag...
[hengband/hengband.git] / src / player / player-status-resist.c
1 #include "player/player-status-resist.h"
2 #include "art-definition/art-sword-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/player-class.h"
16 #include "player/player-race-types.h"
17 #include "player/player-race.h"
18 #include "player/player-skill.h"
19 #include "player/player-status-flags.h"
20 #include "player/player-status.h"
21 #include "player/special-defense-types.h"
22 #include "realm/realm-hex-numbers.h"
23 #include "realm/realm-song-numbers.h"
24 #include "realm/realm-types.h"
25 #include "spell-realm/spells-hex.h"
26 #include "status/element-resistance.h"
27 #include "sv-definition/sv-weapon-types.h"
28 #include "system/floor-type-definition.h"
29 #include "system/monster-type-definition.h"
30 #include "system/object-type-definition.h"
31 #include "util/bit-flags-calculator.h"
32 #include "util/quarks.h"
33 #include "util/string-processor.h"
34
35 PERCENTAGE randrate(int dice, int fix, rate_calc_type_mode mode)
36 {
37     switch (mode) {
38     case CALC_RAND:
39         return randint1(dice) * 100 + fix * 100;
40         break;
41     case CALC_AVERAGE:
42         return (dice + 1) * 50 + fix * 100;
43         break;
44     case CALC_MIN:
45         return (fix + 1) * 100;
46         break;
47     case CALC_MAX:
48         return (dice + fix) * 100;
49         break;
50     default:
51         return (fix + 1) * 100;
52         break;
53     }
54 }
55
56 PERCENTAGE calc_acid_damage_rate(player_type *creature_ptr)
57 {
58     PERCENTAGE per = 100;
59     int i;
60
61     if (is_immune_acid(creature_ptr)) {
62         return 0;
63     }
64
65     BIT_FLAGS flgs = is_vuln_acid(creature_ptr);
66     for (i = 0; i < FLAG_CAUSE_MAX; i++) {
67         if (flgs & (0x01 << i)) {
68             if (i == FLAG_CAUSE_MUTATION) {
69                 per *= 2;
70             } else {
71                 per += per / 3;
72             }
73         }
74     }
75
76     if (creature_ptr->resist_acid)
77         per = (per + 2) / 3;
78     if (is_oppose_acid(creature_ptr))
79         per = (per + 2) / 3;
80
81     return per;
82 }
83
84 PERCENTAGE calc_elec_damage_rate(player_type *creature_ptr)
85 {
86     PERCENTAGE per = 100;
87     int i;
88
89     if (is_immune_elec(creature_ptr)) {
90         return 0;
91     }
92
93     BIT_FLAGS flgs = is_vuln_elec(creature_ptr);
94     for (i = 0; i < FLAG_CAUSE_MAX; i++) {
95         if (flgs & (0x01 << i)) {
96             if (i == FLAG_CAUSE_MUTATION) {
97                 per *= 2;
98             } else {
99                 per += per / 3;
100             }
101         }
102     }
103
104     if (creature_ptr->resist_elec)
105         per = (per + 2) / 3;
106     if (is_oppose_elec(creature_ptr))
107         per = (per + 2) / 3;
108
109     return per;
110 }
111
112 PERCENTAGE calc_fire_damage_rate(player_type *creature_ptr)
113 {
114     PERCENTAGE per = 100;
115     int i;
116     BIT_FLAGS flgs = is_vuln_fire(creature_ptr);
117     for (i = 0; i < FLAG_CAUSE_MAX; i++) {
118         if (flgs & (0x01 << i)) {
119             if (i == FLAG_CAUSE_MUTATION) {
120                 per *= 2;
121             } else {
122                 per += per / 3;
123             }
124         }
125     }
126
127     /* Resist the damage */
128     if (creature_ptr->resist_fire)
129         per = (per + 2) / 3;
130     if (is_oppose_fire(creature_ptr))
131         per = (per + 2) / 3;
132
133     return per;
134 }
135
136 PERCENTAGE calc_cold_damage_rate(player_type *creature_ptr)
137 {
138     PERCENTAGE per = 100;
139     int i;
140     BIT_FLAGS flgs = is_vuln_cold(creature_ptr);
141     for (i = 0; i < FLAG_CAUSE_MAX; i++) {
142         if (flgs & (0x01 << i)) {
143             if (i == FLAG_CAUSE_MUTATION) {
144                 per *= 2;
145             } else {
146                 per += per / 3;
147             }
148         }
149     }
150
151     if (creature_ptr->resist_cold)
152         per = (per + 2) / 3;
153     if (is_oppose_cold(creature_ptr))
154         per = (per + 2) / 3;
155
156     return per;
157 }
158
159 PERCENTAGE calc_pois_damage_rate(player_type *creature_ptr)
160 {
161     PERCENTAGE per = 100;
162     if (creature_ptr->resist_pois)
163         per = (per + 2) / 3;
164     if (is_oppose_pois(creature_ptr))
165         per = (per + 2) / 3;
166
167     return per;
168 }
169
170 PERCENTAGE calc_nuke_damage_rate(player_type *creature_ptr)
171 {
172     PERCENTAGE per = 100;
173     if (creature_ptr->resist_pois)
174         per = (per + 2) / 3;
175     if (is_oppose_pois(creature_ptr))
176         per = (per + 2) / 3;
177
178     return per;
179 }
180
181 PERCENTAGE calc_lite_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
182 {
183     PERCENTAGE per = 100;
184     if (is_specific_player_race(creature_ptr, RACE_VAMPIRE) || (creature_ptr->mimic_form == MIMIC_VAMPIRE)) {
185         per *= 2;
186     } else if (is_specific_player_race(creature_ptr, RACE_S_FAIRY)) {
187         per = per * 4 / 3;
188     }
189
190     if (creature_ptr->resist_lite) {
191         per *= 400;
192         per /= randrate(4, 7, mode);
193     }
194
195     if (creature_ptr->wraith_form)
196         per *= 2;
197
198     return per;
199 }
200
201 PERCENTAGE calc_dark_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
202 {
203     PERCENTAGE per = 100;
204
205     if (is_specific_player_race(creature_ptr, RACE_VAMPIRE) || (creature_ptr->mimic_form == MIMIC_VAMPIRE) || creature_ptr->wraith_form) {
206         return 0;
207     }
208
209     if (creature_ptr->resist_dark) {
210         per *= 400;
211         per /= randrate(4, 7, mode);
212     }
213
214     return per;
215 }
216
217 PERCENTAGE calc_shards_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
218 {
219     PERCENTAGE per = 100;
220
221     if (creature_ptr->resist_shard) {
222         per *= 600;
223         per /= randrate(4, 7, mode);
224     }
225
226     return per;
227 }
228
229 PERCENTAGE calc_sound_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
230 {
231     PERCENTAGE per = 100;
232
233     if (creature_ptr->resist_sound) {
234         per *= 500;
235         per /= randrate(4, 7, mode);
236     }
237
238     return per;
239 }
240
241 PERCENTAGE calc_conf_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
242 {
243     PERCENTAGE per = 100;
244
245     if (creature_ptr->resist_conf) {
246         per *= 500;
247         per /= randrate(4, 7, mode);
248     }
249
250     return per;
251 }
252
253 PERCENTAGE calc_chaos_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
254 {
255     PERCENTAGE per = 100;
256
257     if (creature_ptr->resist_chaos) {
258         per *= 600;
259         per /= randrate(4, 7, mode);
260     }
261
262     return per;
263 }
264
265 PERCENTAGE calc_disenchant_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
266 {
267     PERCENTAGE per = 100;
268
269     if (creature_ptr->resist_disen) {
270         per *= 600;
271         per /= randrate(4, 7, mode);
272     }
273
274     return per;
275 }
276
277 PERCENTAGE calc_nether_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
278 {
279     PERCENTAGE per = 100;
280
281     if (creature_ptr->resist_neth) {
282         if (!is_specific_player_race(creature_ptr, RACE_SPECTRE))
283             per *= 6;
284         per *= 100;
285         per /= randrate(4, 7, mode);
286     }
287
288     return per;
289 }
290
291 PERCENTAGE calc_holy_fire_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
292 {
293     (mode); // unused
294     PERCENTAGE per = 100;
295     if (creature_ptr->align > 10)
296         per /= 2;
297     else if (creature_ptr->align < -10)
298         per *= 2;
299     return per;
300 }
301
302 PERCENTAGE calc_hell_fire_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
303 {
304     (mode); // unused
305     PERCENTAGE per = 100;
306     if (creature_ptr->align > 10)
307         per *= 2;
308     return per;
309 }