3 * @brief ベースアイテムを強化する処理
8 #include "object-enchant/apply-magic.h"
9 #include "artifact/fixed-art-types.h"
10 #include "artifact/fixed-art-generator.h"
11 #include "dungeon/dungeon.h"
12 #include "mutation/mutation-flag-types.h"
13 #include "object-enchant/apply-magic-accessory.h"
14 #include "object-enchant/apply-magic-armor.h"
15 #include "object-enchant/apply-magic-others.h"
16 #include "object-enchant/apply-magic-weapon.h"
17 #include "object-enchant/item-apply-magic.h"
18 #include "object-enchant/object-boost.h"
19 #include "object-enchant/object-curse.h"
20 #include "object-enchant/object-ego.h"
21 #include "object-enchant/special-object-flags.h"
22 #include "object-enchant/tr-types.h"
23 #include "object-enchant/trc-types.h"
24 #include "object-enchant/trg-types.h"
25 #include "object-hook/hook-checker.h"
26 #include "object-hook/hook-enchant.h"
27 #include "object/object-kind.h"
28 #include "player/player-status-flags.h"
29 #include "sv-definition/sv-armor-types.h"
30 #include "sv-definition/sv-protector-types.h"
31 #include "sv-definition/sv-weapon-types.h"
32 #include "system/artifact-type-definition.h"
33 #include "system/floor-type-definition.h"
34 #include "util/bit-flags-calculator.h"
35 #include "world/world.h"
38 * @brief 0 および負数に対応した randint1()
41 * n == 0 のとき、常に 0 を返す。
42 * n > 0 のとき、[1, n] の乱数を返す。
43 * n < 0 のとき、[n,-1] の乱数を返す。
45 static int randint1_signed(const int n)
50 return n > 0 ? randint1(n) : -randint1(-n);
54 * @brief 生成されたベースアイテムに魔法的な強化を与えるメインルーチン
55 * Complete the "creation" of an object by applying "magic" to the item
56 * @param owner_ptr プレーヤーへの参照ポインタ
57 * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
62 * エゴ&アーティファクトの生成、呪い、pval強化
64 void apply_magic(player_type *owner_ptr, object_type *o_ptr, DEPTH lev, BIT_FLAGS mode)
66 if (owner_ptr->pseikaku == PERSONALITY_MUNCHKIN)
67 lev += randint0(owner_ptr->lev / 2 + 10);
68 if (lev > MAX_DEPTH - 1)
72 if (f1 > d_info[owner_ptr->dungeon_idx].obj_good)
73 f1 = d_info[owner_ptr->dungeon_idx].obj_good;
76 if ((owner_ptr->pseikaku != PERSONALITY_MUNCHKIN) && (f2 > d_info[owner_ptr->dungeon_idx].obj_great))
77 f2 = d_info[owner_ptr->dungeon_idx].obj_great;
79 if (has_good_luck(owner_ptr)) {
82 } else if (owner_ptr->muta3 & MUT3_BAD_LUCK) {
88 if ((mode & AM_GOOD) || magik(f1)) {
90 if ((mode & AM_GREAT) || magik(f2)) {
92 if (mode & AM_SPECIAL)
95 } else if (magik(f1)) {
100 if (mode & AM_CURSED) {
112 if (mode & (AM_GREAT | AM_SPECIAL))
114 if ((mode & AM_NO_FIXED_ART) || o_ptr->name1)
117 for (int i = 0; i < rolls; i++) {
118 if (make_artifact(owner_ptr, o_ptr))
120 if (has_good_luck(owner_ptr) && one_in_(77)) {
121 if (make_artifact(owner_ptr, o_ptr))
126 if (object_is_fixed_artifact(o_ptr)) {
127 artifact_type *a_ptr = &a_info[o_ptr->name1];
129 if (current_world_ptr->character_dungeon)
130 a_ptr->floor_id = owner_ptr->floor_id;
132 o_ptr->pval = a_ptr->pval;
133 o_ptr->ac = a_ptr->ac;
134 o_ptr->dd = a_ptr->dd;
135 o_ptr->ds = a_ptr->ds;
136 o_ptr->to_a = a_ptr->to_a;
137 o_ptr->to_h = a_ptr->to_h;
138 o_ptr->to_d = a_ptr->to_d;
139 o_ptr->weight = a_ptr->weight;
140 o_ptr->xtra2 = a_ptr->act_idx;
142 if (o_ptr->name1 == ART_MILIM) {
143 if (owner_ptr->pseikaku == PERSONALITY_SEXY) {
149 o_ptr->ident |= (IDENT_BROKEN);
150 if (a_ptr->gen_flags & TRG_CURSED)
151 o_ptr->curse_flags |= (TRC_CURSED);
152 if (a_ptr->gen_flags & TRG_HEAVY_CURSE)
153 o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
154 if (a_ptr->gen_flags & TRG_PERMA_CURSE)
155 o_ptr->curse_flags |= (TRC_PERMA_CURSE);
156 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE0))
157 o_ptr->curse_flags |= get_curse(owner_ptr, 0, o_ptr);
158 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE1))
159 o_ptr->curse_flags |= get_curse(owner_ptr, 1, o_ptr);
160 if (a_ptr->gen_flags & (TRG_RANDOM_CURSE2))
161 o_ptr->curse_flags |= get_curse(owner_ptr, 2, o_ptr);
166 switch (o_ptr->tval) {
174 apply_magic_weapon(owner_ptr, o_ptr, lev, power);
178 if (power && !(o_ptr->sval == SV_DEATH_SCYTHE))
179 apply_magic_weapon(owner_ptr, o_ptr, lev, power);
183 if (power && !(o_ptr->sval == SV_POISON_NEEDLE))
184 apply_magic_weapon(owner_ptr, o_ptr, lev, power);
196 if (((o_ptr->tval == TV_CLOAK) && (o_ptr->sval == SV_ELVEN_CLOAK)) || ((o_ptr->tval == TV_SOFT_ARMOR) && (o_ptr->sval == SV_KUROSHOUZOKU)))
197 o_ptr->pval = randint1(4);
199 if (power || ((o_ptr->tval == TV_HELM) && (o_ptr->sval == SV_DRAGON_HELM)) || ((o_ptr->tval == TV_SHIELD) && (o_ptr->sval == SV_DRAGON_SHIELD))
200 || ((o_ptr->tval == TV_GLOVES) && (o_ptr->sval == SV_SET_OF_DRAGON_GLOVES))
201 || ((o_ptr->tval == TV_BOOTS) && (o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE)))
202 apply_magic_armor(owner_ptr, o_ptr, lev, power);
208 if (!power && (randint0(100) < 50))
210 apply_magic_accessary(owner_ptr, o_ptr, lev, power);
214 apply_magic_others(owner_ptr, o_ptr, power);
219 if ((o_ptr->tval == TV_SOFT_ARMOR) && (o_ptr->sval == SV_ABUNAI_MIZUGI) && (owner_ptr->pseikaku == PERSONALITY_SEXY)) {
221 add_flag(o_ptr->art_flags, TR_STR);
222 add_flag(o_ptr->art_flags, TR_INT);
223 add_flag(o_ptr->art_flags, TR_WIS);
224 add_flag(o_ptr->art_flags, TR_DEX);
225 add_flag(o_ptr->art_flags, TR_CON);
226 add_flag(o_ptr->art_flags, TR_CHR);
229 if (object_is_ego(o_ptr)) {
230 ego_item_type *e_ptr = &e_info[o_ptr->name2];
232 o_ptr->ident |= (IDENT_BROKEN);
234 if (e_ptr->gen_flags & TRG_CURSED)
235 o_ptr->curse_flags |= (TRC_CURSED);
236 if (e_ptr->gen_flags & TRG_HEAVY_CURSE)
237 o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
238 if (e_ptr->gen_flags & TRG_PERMA_CURSE)
239 o_ptr->curse_flags |= (TRC_PERMA_CURSE);
240 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE0))
241 o_ptr->curse_flags |= get_curse(owner_ptr, 0, o_ptr);
242 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE1))
243 o_ptr->curse_flags |= get_curse(owner_ptr, 1, o_ptr);
244 if (e_ptr->gen_flags & (TRG_RANDOM_CURSE2))
245 o_ptr->curse_flags |= get_curse(owner_ptr, 2, o_ptr);
247 if (e_ptr->gen_flags & (TRG_ONE_SUSTAIN))
249 if (e_ptr->gen_flags & (TRG_XTRA_POWER))
251 if (e_ptr->gen_flags & (TRG_XTRA_H_RES))
252 one_high_resistance(o_ptr);
253 if (e_ptr->gen_flags & (TRG_XTRA_E_RES))
254 one_ele_resistance(o_ptr);
255 if (e_ptr->gen_flags & (TRG_XTRA_D_RES))
256 one_dragon_ele_resistance(o_ptr);
257 if (e_ptr->gen_flags & (TRG_XTRA_L_RES))
258 one_lordly_high_resistance(o_ptr);
259 if (e_ptr->gen_flags & (TRG_XTRA_RES))
260 one_resistance(o_ptr);
261 if (e_ptr->gen_flags & (TRG_XTRA_DICE)) {
264 } while (one_in_(o_ptr->dd));
271 o_ptr->xtra2 = (XTRA8)e_ptr->act_idx;
273 if ((object_is_cursed(o_ptr) || object_is_broken(o_ptr)) && !(e_ptr->gen_flags & (TRG_POWERFUL))) {
275 o_ptr->to_h -= randint1(e_ptr->max_to_h);
277 o_ptr->to_d -= randint1(e_ptr->max_to_d);
279 o_ptr->to_a -= randint1(e_ptr->max_to_a);
281 o_ptr->pval -= randint1(e_ptr->max_pval);
283 o_ptr->to_h += (HIT_PROB)randint1_signed(e_ptr->max_to_h);
284 o_ptr->to_d += randint1_signed(e_ptr->max_to_d);
285 o_ptr->to_a += (ARMOUR_CLASS)randint1_signed(e_ptr->max_to_a);
287 if (o_ptr->name2 == EGO_ACCURACY) {
288 while (o_ptr->to_h < o_ptr->to_d + 10) {
292 o_ptr->to_h = MAX(o_ptr->to_h, 15);
295 if (o_ptr->name2 == EGO_VELOCITY) {
296 while (o_ptr->to_d < o_ptr->to_h + 10) {
300 o_ptr->to_d = MAX(o_ptr->to_d, 15);
303 if ((o_ptr->name2 == EGO_PROTECTION) || (o_ptr->name2 == EGO_S_PROTECTION) || (o_ptr->name2 == EGO_H_PROTECTION)) {
304 o_ptr->to_a = MAX(o_ptr->to_a, 15);
307 if (e_ptr->max_pval) {
308 if ((o_ptr->name2 == EGO_HA) && (has_flag(o_ptr->art_flags, TR_BLOWS))) {
310 if ((lev > 60) && one_in_(3) && ((o_ptr->dd * (o_ptr->ds + 1)) < 15))
312 } else if (o_ptr->name2 == EGO_DEMON) {
313 if (has_flag(o_ptr->art_flags, TR_BLOWS)) {
314 o_ptr->pval += randint1(2);
316 o_ptr->pval += randint1(e_ptr->max_pval);
318 } else if (o_ptr->name2 == EGO_ATTACKS) {
319 o_ptr->pval = randint1(e_ptr->max_pval * lev / 100 + 1);
322 if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_HAYABUSA))
323 o_ptr->pval += randint1(2);
324 } else if (o_ptr->name2 == EGO_BAT) {
325 o_ptr->pval = randint1(e_ptr->max_pval);
326 if (o_ptr->sval == SV_ELVEN_CLOAK)
327 o_ptr->pval += randint1(2);
328 } else if (o_ptr->name2 == EGO_A_DEMON || o_ptr->name2 == EGO_DRUID || o_ptr->name2 == EGO_OLOG) {
329 o_ptr->pval = randint1(e_ptr->max_pval);
331 o_ptr->pval += randint1(e_ptr->max_pval);
335 if ((o_ptr->name2 == EGO_SPEED) && (lev < 50)) {
336 o_ptr->pval = randint1(o_ptr->pval);
339 if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_HAYABUSA) && (o_ptr->pval > 2) && (o_ptr->name2 != EGO_ATTACKS))
347 object_kind *k_ptr = &k_info[o_ptr->k_idx];
348 if (!k_info[o_ptr->k_idx].cost)
349 o_ptr->ident |= (IDENT_BROKEN);
351 if (k_ptr->gen_flags & (TRG_CURSED))
352 o_ptr->curse_flags |= (TRC_CURSED);
353 if (k_ptr->gen_flags & (TRG_HEAVY_CURSE))
354 o_ptr->curse_flags |= TRC_HEAVY_CURSE;
355 if (k_ptr->gen_flags & (TRG_PERMA_CURSE))
356 o_ptr->curse_flags |= TRC_PERMA_CURSE;
357 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE0))
358 o_ptr->curse_flags |= get_curse(owner_ptr, 0, o_ptr);
359 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE1))
360 o_ptr->curse_flags |= get_curse(owner_ptr, 1, o_ptr);
361 if (k_ptr->gen_flags & (TRG_RANDOM_CURSE2))
362 o_ptr->curse_flags |= get_curse(owner_ptr, 2, o_ptr);