OSDN Git Service

Merge pull request #3532 from sikabane-works/release/3.0.0.87-alpha
[hengbandforosx/hengbandosx.git] / src / artifact / random-art-activation.cpp
1 /*!
2  * @file random-art-activation.cpp
3  * @brief ランダムアーティファクトの発動実装定義
4  */
5
6 #include "artifact/random-art-activation.h"
7 #include "artifact/random-art-bias-types.h"
8 #include "artifact/random-art-effects.h"
9 #include "object-enchant/object-boost.h"
10 #include "object-enchant/tr-types.h"
11 #include "system/item-entity.h"
12 #include "util/bit-flags-calculator.h"
13 #include "util/enum-converter.h"
14
15 static RandomArtActType invest_activation_elec(void)
16 {
17     if (!one_in_(3)) {
18         return RandomArtActType::BO_ELEC_1;
19     }
20
21     if (!one_in_(5)) {
22         return RandomArtActType::BA_ELEC_2;
23     }
24
25     return RandomArtActType::BA_ELEC_3;
26 }
27
28 static RandomArtActType invest_activation_fire(void)
29 {
30     if (!one_in_(3)) {
31         return RandomArtActType::BO_FIRE_1;
32     }
33
34     if (!one_in_(5)) {
35         return RandomArtActType::BA_FIRE_1;
36     }
37
38     return RandomArtActType::BA_FIRE_2;
39 }
40
41 static RandomArtActType invest_activation_cold(void)
42 {
43     if (!one_in_(3)) {
44         return RandomArtActType::BO_COLD_1;
45     }
46
47     if (!one_in_(3)) {
48         return RandomArtActType::BA_COLD_1;
49     }
50
51     if (!one_in_(3)) {
52         return RandomArtActType::BA_COLD_2;
53     }
54
55     return RandomArtActType::BA_COLD_3;
56 }
57
58 static RandomArtActType invest_activation_chaos(void)
59 {
60     return one_in_(6) ? RandomArtActType::SUMMON_DEMON : RandomArtActType::CALL_CHAOS;
61 }
62
63 static RandomArtActType invest_activation_priest(void)
64 {
65     if (one_in_(13)) {
66         return RandomArtActType::CHARM_UNDEAD;
67     }
68
69     if (one_in_(12)) {
70         return RandomArtActType::BANISH_EVIL;
71     }
72
73     if (one_in_(11)) {
74         return RandomArtActType::DISP_EVIL;
75     }
76
77     if (one_in_(10)) {
78         return RandomArtActType::PROT_EVIL;
79     }
80
81     if (one_in_(9)) {
82         return RandomArtActType::CURE_1000;
83     }
84
85     if (one_in_(8)) {
86         return RandomArtActType::CURE_700;
87     }
88
89     if (one_in_(7)) {
90         return RandomArtActType::REST_ALL;
91     }
92
93     if (one_in_(6)) {
94         return RandomArtActType::REST_EXP;
95     }
96
97     return RandomArtActType::CURE_MW;
98 }
99
100 static RandomArtActType invest_activation_necromancy(void)
101 {
102     if (one_in_(66)) {
103         return RandomArtActType::WRAITH;
104     }
105
106     if (one_in_(13)) {
107         return RandomArtActType::DISP_GOOD;
108     }
109
110     if (one_in_(9)) {
111         return RandomArtActType::MASS_GENO;
112     }
113
114     if (one_in_(8)) {
115         return RandomArtActType::GENOCIDE;
116     }
117
118     if (one_in_(13)) {
119         return RandomArtActType::SUMMON_UNDEAD;
120     }
121
122     if (one_in_(9)) {
123         return RandomArtActType::DRAIN_2;
124     }
125
126     if (one_in_(6)) {
127         return RandomArtActType::CHARM_UNDEAD;
128     }
129
130     return RandomArtActType::DRAIN_1;
131 }
132
133 static RandomArtActType invest_activation_law(void)
134 {
135     if (one_in_(8)) {
136         return RandomArtActType::BANISH_EVIL;
137     }
138
139     if (one_in_(4)) {
140         return RandomArtActType::DISP_EVIL;
141     }
142
143     return RandomArtActType::PROT_EVIL;
144 }
145
146 static RandomArtActType invest_activation_rogue(void)
147 {
148     if (one_in_(50)) {
149         return RandomArtActType::SPEED;
150     }
151
152     if (one_in_(4)) {
153         return RandomArtActType::SLEEP;
154     }
155
156     if (one_in_(3)) {
157         return RandomArtActType::DETECT_ALL;
158     }
159
160     if (one_in_(8)) {
161         return RandomArtActType::ID_FULL;
162     }
163
164     return RandomArtActType::ID_PLAIN;
165 }
166
167 static RandomArtActType invest_activation_mage(void)
168 {
169     if (one_in_(20)) {
170         return RandomArtActType::SUMMON_ELEMENTAL;
171     }
172
173     if (one_in_(10)) {
174         return RandomArtActType::SUMMON_PHANTOM;
175     }
176
177     if (one_in_(5)) {
178         return RandomArtActType::RUNE_EXPLO;
179     }
180
181     return RandomArtActType::ESP;
182 }
183
184 static RandomArtActType invest_activation_warrior(void)
185 {
186     return one_in_(100) ? RandomArtActType::INVULN : RandomArtActType::BERSERK;
187 }
188
189 static RandomArtActType invest_activation_ranger(void)
190 {
191     if (one_in_(20)) {
192         return RandomArtActType::CHARM_ANIMALS;
193     }
194
195     if (one_in_(7)) {
196         return RandomArtActType::SUMMON_ANIMAL;
197     }
198
199     if (one_in_(6)) {
200         return RandomArtActType::CHARM_ANIMAL;
201     }
202
203     if (one_in_(4)) {
204         return RandomArtActType::RESIST_ALL;
205     }
206
207     if (one_in_(3)) {
208         return RandomArtActType::SATIATE;
209     }
210
211     return RandomArtActType::CURE_POISON;
212 }
213
214 /*!
215  * @brief ランダムアーティファクト生成中、対象のオブジェクトにバイアスに依存した発動を与える。/ Add one activaton of randam artifact depend on bias.
216  * @details バイアスが無い場合、一部のバイアスの確率によっては one_ability() に処理が移行する。
217  * @param o_ptr 対象のオブジェクト構造体ポインタ
218  */
219 void give_activation_power(ItemEntity *o_ptr)
220 {
221     RandomArtActType type = RandomArtActType::NONE;
222     int chance = 0;
223     switch (o_ptr->artifact_bias) {
224     case BIAS_ELEC:
225         type = invest_activation_elec();
226         chance = 101;
227         break;
228     case BIAS_POIS:
229         type = RandomArtActType::BA_POIS_1;
230         chance = 101;
231         break;
232     case BIAS_FIRE:
233         type = invest_activation_fire();
234         chance = 101;
235         break;
236     case BIAS_COLD:
237         type = invest_activation_cold();
238         chance = 101;
239         break;
240     case BIAS_CHAOS:
241         type = invest_activation_chaos();
242         chance = 50;
243         break;
244     case BIAS_PRIESTLY:
245         type = invest_activation_priest();
246         chance = 101;
247         break;
248     case BIAS_NECROMANTIC:
249         type = invest_activation_necromancy();
250         chance = 101;
251         break;
252     case BIAS_LAW:
253         type = invest_activation_law();
254         chance = 101;
255         break;
256     case BIAS_ROGUE:
257         type = invest_activation_rogue();
258         chance = 101;
259         break;
260     case BIAS_MAGE:
261         type = invest_activation_mage();
262         chance = 66;
263         break;
264     case BIAS_WARRIOR:
265         type = invest_activation_warrior();
266         chance = 80;
267         break;
268     case BIAS_RANGER:
269         type = invest_activation_ranger();
270         chance = 101;
271         break;
272     }
273
274     if ((type == RandomArtActType::NONE) || (randint1(100) >= chance)) {
275         one_activation(o_ptr);
276         return;
277     }
278
279     o_ptr->activation_id = type;
280     o_ptr->art_flags.set(TR_ACTIVATE);
281     o_ptr->timeout = 0;
282 }