OSDN Git Service

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