OSDN Git Service

Merge remote-tracking branch 'remotes/origin/feature/Fix-saved-floor-exceed' into...
[hengband/hengband.git] / src / spell-kind / spells-equipment.c
1 #include "spell-kind/spells-equipment.h"
2 #include "core/player-update-types.h"
3 #include "core/window-redrawer.h"
4 #include "flavor/flavor-describer.h"
5 #include "flavor/object-flavor-types.h"
6 #include "inventory/inventory-slot-types.h"
7 #include "object-hook/hook-enchant.h"
8 #include "object-hook/hook-weapon.h"
9 #include "object/object-info.h"
10 #include "player-info/avatar.h"
11 #include "racial/racial-android.h"
12 #include "system/object-type-definition.h"
13 #include "view/display-messages.h"
14
15 /*!
16  * @brief プレイヤーの装備劣化処理 /
17  * Apply disenchantment to the player's stuff
18  * @param target_ptr プレーヤーへの参照ポインタ
19  * @param mode 最下位ビットが1ならば劣化処理が若干低減される
20  * @return 劣化処理に関するメッセージが発せられた場合はTRUEを返す /
21  * Return "TRUE" if the player notices anything
22  */
23 bool apply_disenchant(player_type *target_ptr, BIT_FLAGS mode)
24 {
25     int t = 0;
26     switch (randint1(8)) {
27     case 1:
28         t = INVEN_MAIN_HAND;
29         break;
30     case 2:
31         t = INVEN_SUB_HAND;
32         break;
33     case 3:
34         t = INVEN_BOW;
35         break;
36     case 4:
37         t = INVEN_BODY;
38         break;
39     case 5:
40         t = INVEN_OUTER;
41         break;
42     case 6:
43         t = INVEN_HEAD;
44         break;
45     case 7:
46         t = INVEN_ARMS;
47         break;
48     case 8:
49         t = INVEN_FEET;
50         break;
51     }
52
53     object_type *o_ptr;
54     o_ptr = &target_ptr->inventory_list[t];
55     if (!o_ptr->k_idx)
56         return FALSE;
57
58     if (!object_is_weapon_armour_ammo(target_ptr, o_ptr))
59         return FALSE;
60
61     if ((o_ptr->to_h <= 0) && (o_ptr->to_d <= 0) && (o_ptr->to_a <= 0) && (o_ptr->pval <= 1)) {
62         return FALSE;
63     }
64
65     GAME_TEXT o_name[MAX_NLEN];
66     describe_flavor(target_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
67     if (object_is_artifact(o_ptr) && (randint0(100) < 71)) {
68 #ifdef JP
69         msg_format("%s(%c)は劣化を跳ね返した!", o_name, index_to_label(t));
70 #else
71         msg_format("Your %s (%c) resist%s disenchantment!", o_name, index_to_label(t), ((o_ptr->number != 1) ? "" : "s"));
72 #endif
73         return TRUE;
74     }
75
76     int to_h = o_ptr->to_h;
77     int to_d = o_ptr->to_d;
78     int to_a = o_ptr->to_a;
79     int pval = o_ptr->pval;
80
81     if (o_ptr->to_h > 0)
82         o_ptr->to_h--;
83     if ((o_ptr->to_h > 5) && (randint0(100) < 20))
84         o_ptr->to_h--;
85
86     if (o_ptr->to_d > 0)
87         o_ptr->to_d--;
88     if ((o_ptr->to_d > 5) && (randint0(100) < 20))
89         o_ptr->to_d--;
90
91     if (o_ptr->to_a > 0)
92         o_ptr->to_a--;
93     if ((o_ptr->to_a > 5) && (randint0(100) < 20))
94         o_ptr->to_a--;
95
96     if ((o_ptr->pval > 1) && one_in_(13) && !(mode & 0x01))
97         o_ptr->pval--;
98
99     bool is_actually_disenchanted = to_h != o_ptr->to_h;
100     is_actually_disenchanted |= to_d != o_ptr->to_d;
101     is_actually_disenchanted |= to_a != o_ptr->to_a;
102     is_actually_disenchanted |= pval != o_ptr->pval;
103     if (!is_actually_disenchanted)
104         return TRUE;
105
106 #ifdef JP
107     msg_format("%s(%c)は劣化してしまった!", o_name, index_to_label(t));
108 #else
109     msg_format("Your %s (%c) %s disenchanted!", o_name, index_to_label(t), ((o_ptr->number != 1) ? "were" : "was"));
110 #endif
111     chg_virtue(target_ptr, V_HARMONY, 1);
112     chg_virtue(target_ptr, V_ENCHANT, -2);
113     target_ptr->update |= (PU_BONUS);
114     target_ptr->window |= (PW_EQUIP | PW_PLAYER);
115
116     calc_android_exp(target_ptr);
117     return TRUE;
118 }