OSDN Git Service

89fb976ab9a3fa9fbde353e444e2bae9ce356d27
[hengband/hengband.git] / src / object-curse.c
1 #include "angband.h"
2 #include "object-flavor.h"
3 #include "object-hook.h"
4
5 /*!
6  * @brief アイテムに付加される可能性のある呪いを指定する。
7  * @param power 呪いの段階
8  * @param o_ptr 呪いをかけられる装備オブジェクトの構造体参照ポインタ
9  * @return 与える呪いのID
10  */
11 BIT_FLAGS get_curse(int power, object_type *o_ptr)
12 {
13         BIT_FLAGS new_curse;
14
15         while(1)
16         {
17                 new_curse = (1 << (randint0(MAX_CURSE)+4));
18                 if (power == 2)
19                 {
20                         if (!(new_curse & TRC_HEAVY_MASK)) continue;
21                 }
22                 else if (power == 1)
23                 {
24                         if (new_curse & TRC_SPECIAL_MASK) continue;
25                 }
26                 else if (power == 0)
27                 {
28                         if (new_curse & TRC_HEAVY_MASK) continue;
29                 }
30                 if (new_curse == TRC_LOW_MELEE && !object_is_weapon(o_ptr)) continue;
31                 if (new_curse == TRC_LOW_AC && !object_is_armour(o_ptr)) continue;
32                 break;
33         }
34         return new_curse;
35 }
36
37 /*!
38  * @brief 装備への呪い付加判定と付加処理
39  * @param chance 呪いの基本確率
40  * @param heavy_chance さらに重い呪いとなる確率
41  * @return なし
42  */
43 void curse_equipment(PERCENTAGE chance, PERCENTAGE heavy_chance)
44 {
45         bool changed = FALSE;
46         int curse_power = 0;
47         BIT_FLAGS new_curse;
48         BIT_FLAGS oflgs[TR_FLAG_SIZE];
49         object_type *o_ptr = &inventory[INVEN_RARM + randint0(12)];
50         GAME_TEXT o_name[MAX_NLEN];
51
52         if (randint1(100) > chance) return;
53         if (!o_ptr->k_idx) return;
54         object_flags(o_ptr, oflgs);
55         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
56
57         /* Extra, biased saving throw for blessed items */
58         if (have_flag(oflgs, TR_BLESSED))
59         {
60 #ifdef JP
61                 msg_format("祝福された%sは呪いを跳ね返した!", o_name);
62 #else
63                 msg_format("Your blessed %s resist%s cursing!", o_name, ((o_ptr->number > 1) ? "" : "s"));
64 #endif
65                 /* Hmmm -- can we wear multiple items? If not, this is unnecessary */
66                 return;
67         }
68
69         if ((randint1(100) <= heavy_chance) &&
70             (object_is_artifact(o_ptr) || object_is_ego(o_ptr)))
71         {
72                 if (!(o_ptr->curse_flags & TRC_HEAVY_CURSE))
73                         changed = TRUE;
74                 o_ptr->curse_flags |= TRC_HEAVY_CURSE;
75                 o_ptr->curse_flags |= TRC_CURSED;
76                 curse_power++;
77         }
78         else
79         {
80                 if (!object_is_cursed(o_ptr))
81                         changed = TRUE;
82                 o_ptr->curse_flags |= TRC_CURSED;
83         }
84         if (heavy_chance >= 50) curse_power++;
85
86         new_curse = get_curse(curse_power, o_ptr);
87         if (!(o_ptr->curse_flags & new_curse))
88         {
89                 changed = TRUE;
90                 o_ptr->curse_flags |= new_curse;
91         }
92
93         if (changed)
94         {
95                 msg_format(_("悪意に満ちた黒いオーラが%sをとりまいた...", "There is a malignant black aura surrounding %s..."), o_name);
96                 o_ptr->feeling = FEEL_NONE;
97         }
98         p_ptr->update |= (PU_BONUS);
99 }
100