OSDN Git Service

Merge pull request #1779 from sikabane-works/feature/get_value-default-value-heng
[hengbandforosx/hengbandosx.git] / src / cmd-item / cmd-equipment.cpp
1 #include "cmd-item/cmd-equipment.h"
2 #include "action/weapon-shield.h"
3 #include "artifact/fixed-art-types.h"
4 #include "autopick/autopick.h"
5 #include "avatar/avatar.h"
6 #include "core/asking-player.h"
7 #include "core/player-redraw-types.h"
8 #include "core/player-update-types.h"
9 #include "core/window-redrawer.h"
10 #include "dungeon/quest.h" //!< @todo 違和感、何故アイテムを装備するとクエストの成功判定が走るのか?.
11 #include "flavor/flavor-describer.h"
12 #include "flavor/object-flavor-types.h"
13 #include "floor/floor-object.h"
14 #include "game-option/birth-options.h"
15 #include "game-option/input-options.h"
16 #include "inventory/inventory-describer.h"
17 #include "inventory/inventory-object.h"
18 #include "inventory/inventory-slot-types.h"
19 #include "io/input-key-acceptor.h"
20 #include "io/input-key-requester.h"
21 #include "main/sound-definitions-table.h"
22 #include "main/sound-of-music.h"
23 #include "object-enchant/item-feeling.h"
24 #include "object-enchant/special-object-flags.h"
25 #include "object-enchant/trc-types.h"
26 #include "object-hook/hook-armor.h"
27 #include "object-hook/hook-weapon.h"
28 #include "object/item-tester-hooker.h"
29 #include "object/item-use-flags.h"
30 #include "object/object-info.h"
31 #include "object/object-mark-types.h"
32 #include "perception/object-perception.h"
33 #include "player-base/player-class.h"
34 #include "player-info/samurai-data-type.h"
35 #include "player-info/equipment-info.h"
36 #include "player-status/player-energy.h"
37 #include "player-status/player-hand-types.h"
38 #include "player/attack-defense-types.h"
39 #include "player/player-status.h"
40 #include "player/special-defense-types.h"
41 #include "racial/racial-android.h"
42 #include "spell-kind/spells-perception.h"
43 #include "status/action-setter.h"
44 #include "status/shape-changer.h"
45 #include "system/object-type-definition.h"
46 #include "system/player-type-definition.h"
47 #include "term/screen-processor.h"
48 #include "util/int-char-converter.h"
49 #include "view/display-inventory.h"
50 #include "view/display-messages.h"
51
52 /*!
53  * @brief 装備一覧を表示するコマンドのメインルーチン / Display equipment
54  */
55 void do_cmd_equip(player_type *player_ptr)
56 {
57     char out_val[160];
58     command_wrk = true;
59     if (easy_floor)
60         command_wrk = USE_EQUIP;
61
62     screen_save();
63     (void)show_equipment(player_ptr, 0, USE_FULL, AllMatchItemTester());
64     WEIGHT weight = calc_inventory_weight(player_ptr);
65     WEIGHT weight_lim = calc_weight_limit(player_ptr);
66 #ifdef JP
67     sprintf(out_val, "装備: 合計 %3d.%1d kg (限界の%ld%%) コマンド: ", (int)lbtokg1(weight), (int)lbtokg2(weight), (long int)((weight * 100) / weight_lim));
68 #else
69     sprintf(out_val, "Equipment: carrying %d.%d pounds (%ld%% of capacity). Command: ", (int)(weight / 10), (int)(weight % 10),
70         (long int)((weight * 100) / weight_lim));
71 #endif
72
73     prt(out_val, 0, 0);
74     command_new = inkey();
75     screen_load();
76
77     if (command_new != ESCAPE) {
78         command_see = true;
79         return;
80     }
81
82     TERM_LEN wid, hgt;
83     term_get_size(&wid, &hgt);
84     command_new = 0;
85     command_gap = wid - 30;
86 }
87
88 /*!
89  * @brief 装備するコマンドのメインルーチン / Wield or wear a single item from the pack or floor
90  * @param player_ptr プレイヤーへの参照ポインタ
91  */
92 void do_cmd_wield(player_type *player_ptr)
93 {
94     OBJECT_IDX item, slot;
95     object_type forge;
96     object_type *q_ptr;
97     object_type *o_ptr;
98     concptr act;
99     GAME_TEXT o_name[MAX_NLEN];
100     OBJECT_IDX need_switch_wielding = 0;
101     PlayerClass(player_ptr).break_samurai_stance({ SamuraiStance::MUSOU });
102
103     concptr q = _("どれを装備しますか? ", "Wear/Wield which item? ");
104     concptr s = _("装備可能なアイテムがない。", "You have nothing you can wear or wield.");
105     o_ptr = choose_object(player_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), FuncItemTester(item_tester_hook_wear, player_ptr));
106     if (!o_ptr)
107         return;
108
109     slot = wield_slot(player_ptr, o_ptr);
110
111     const auto o_ptr_mh = &player_ptr->inventory_list[INVEN_MAIN_HAND];
112     const auto o_ptr_sh = &player_ptr->inventory_list[INVEN_SUB_HAND];
113
114     switch (o_ptr->tval) {
115     case ItemKindType::CAPTURE:
116     case ItemKindType::SHIELD:
117     case ItemKindType::CARD:
118         if (has_melee_weapon(player_ptr, INVEN_MAIN_HAND) && has_melee_weapon(player_ptr, INVEN_SUB_HAND)) {
119             q = _("どちらの武器と取り替えますか?", "Replace which weapon? ");
120             s = _("おっと。", "Oops.");
121             if (!choose_object(player_ptr, &slot, q, s, (USE_EQUIP | IGNORE_BOTHHAND_SLOT), FuncItemTester(&object_type::is_melee_weapon)))
122                 return;
123
124             if (slot == INVEN_MAIN_HAND)
125                 need_switch_wielding = INVEN_SUB_HAND;
126         } else if (has_melee_weapon(player_ptr, INVEN_SUB_HAND))
127             slot = INVEN_MAIN_HAND;
128         else if (o_ptr_mh->k_idx && o_ptr_sh->k_idx &&
129                  ((o_ptr->tval == ItemKindType::CAPTURE) || (!o_ptr_mh->is_melee_weapon() && !o_ptr_sh->is_melee_weapon()))) {
130             q = _("どちらの手に装備しますか?", "Equip which hand? ");
131             s = _("おっと。", "Oops.");
132             if (!choose_object(player_ptr, &slot, q, s, (USE_EQUIP), FuncItemTester(&object_type::is_wieldable_in_etheir_hand)))
133                 return;
134         }
135
136         break;
137     case ItemKindType::DIGGING:
138     case ItemKindType::HAFTED:
139     case ItemKindType::POLEARM:
140     case ItemKindType::SWORD:
141         if (slot == INVEN_SUB_HAND) {
142             if (!get_check(_("二刀流で戦いますか?", "Dual wielding? ")))
143                 slot = INVEN_MAIN_HAND;
144         } else if (!o_ptr_mh->k_idx && has_melee_weapon(player_ptr, INVEN_SUB_HAND)) {
145             if (!get_check(_("二刀流で戦いますか?", "Dual wielding? ")))
146                 slot = INVEN_SUB_HAND;
147         } else if (o_ptr_mh->k_idx && o_ptr_sh->k_idx) {
148             q = _("どちらの手に装備しますか?", "Equip which hand? ");
149             s = _("おっと。", "Oops.");
150             if (!choose_object(player_ptr, &slot, q, s, (USE_EQUIP), FuncItemTester(&object_type::is_wieldable_in_etheir_hand)))
151                 return;
152
153             if ((slot == INVEN_SUB_HAND) && !has_melee_weapon(player_ptr, INVEN_MAIN_HAND))
154                 need_switch_wielding = INVEN_MAIN_HAND;
155         }
156
157         break;
158     case ItemKindType::RING:
159         if (player_ptr->inventory_list[INVEN_SUB_RING].k_idx && player_ptr->inventory_list[INVEN_MAIN_RING].k_idx)
160             q = _("どちらの指輪と取り替えますか?", "Replace which ring? ");
161         else
162             q = _("どちらの手に装備しますか?", "Equip which hand? ");
163
164         s = _("おっと。", "Oops.");
165         player_ptr->select_ring_slot = true;
166         if (!choose_object(player_ptr, &slot, q, s, (USE_EQUIP | IGNORE_BOTHHAND_SLOT))) {
167             player_ptr->select_ring_slot = false;
168             return;
169         }
170
171         player_ptr->select_ring_slot = false;
172         break;
173
174     default:
175         break;
176     }
177
178     if (player_ptr->inventory_list[slot].is_cursed()) {
179         describe_flavor(player_ptr, o_name, &player_ptr->inventory_list[slot], OD_OMIT_PREFIX | OD_NAME_ONLY);
180 #ifdef JP
181         msg_format("%s%sは呪われているようだ。", describe_use(player_ptr, slot), o_name);
182 #else
183         msg_format("The %s you are %s appears to be cursed.", o_name, describe_use(player_ptr, slot));
184 #endif
185         return;
186     }
187
188     if (confirm_wear
189         && ((o_ptr->is_cursed() && o_ptr->is_known())
190             || ((o_ptr->ident & IDENT_SENSE) && (FEEL_BROKEN <= o_ptr->feeling) && (o_ptr->feeling <= FEEL_CURSED)))) {
191         char dummy[MAX_NLEN + 80];
192         describe_flavor(player_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
193         sprintf(dummy, _("本当に%s{呪われている}を使いますか?", "Really use the %s {cursed}? "), o_name);
194
195         if (!get_check(dummy))
196             return;
197     }
198
199     if ((o_ptr->name1 == ART_STONEMASK) && o_ptr->is_known() && (player_ptr->prace != PlayerRaceType::VAMPIRE)
200         && (player_ptr->prace != PlayerRaceType::ANDROID)) {
201         char dummy[MAX_NLEN + 100];
202         describe_flavor(player_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
203         sprintf(dummy,
204             _("%sを装備すると吸血鬼になります。よろしいですか?", "%s will transform you into a vampire permanently when equipped. Do you become a vampire? "),
205             o_name);
206
207         if (!get_check(dummy))
208             return;
209     }
210
211     sound(SOUND_WIELD);
212     if (need_switch_wielding && !player_ptr->inventory_list[need_switch_wielding].is_cursed()) {
213         object_type *slot_o_ptr = &player_ptr->inventory_list[slot];
214         object_type *switch_o_ptr = &player_ptr->inventory_list[need_switch_wielding];
215         object_type object_tmp;
216         object_type *otmp_ptr = &object_tmp;
217         GAME_TEXT switch_name[MAX_NLEN];
218         describe_flavor(player_ptr, switch_name, switch_o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
219         otmp_ptr->copy_from(switch_o_ptr);
220         switch_o_ptr->copy_from(slot_o_ptr);
221         slot_o_ptr->copy_from(otmp_ptr);
222         msg_format(_("%sを%sに構えなおした。", "You wield %s at %s hand."), switch_name,
223             (slot == INVEN_MAIN_HAND) ? (left_hander ? _("左手", "left") : _("右手", "right")) : (left_hander ? _("右手", "right") : _("左手", "left")));
224         slot = need_switch_wielding;
225     }
226
227     check_find_art_quest_completion(player_ptr, o_ptr);
228     if (player_ptr->ppersonality == PERSONALITY_MUNCHKIN) {
229         identify_item(player_ptr, o_ptr);
230         autopick_alter_item(player_ptr, item, false);
231     }
232
233     PlayerEnergy(player_ptr).set_player_turn_energy(100);
234     q_ptr = &forge;
235     q_ptr->copy_from(o_ptr);
236     q_ptr->number = 1;
237     if (item >= 0) {
238         inven_item_increase(player_ptr, item, -1);
239         inven_item_optimize(player_ptr, item);
240     } else {
241         floor_item_increase(player_ptr, 0 - item, -1);
242         floor_item_optimize(player_ptr, 0 - item);
243     }
244
245     o_ptr = &player_ptr->inventory_list[slot];
246     if (o_ptr->k_idx)
247         (void)inven_takeoff(player_ptr, slot, 255);
248
249     o_ptr->copy_from(q_ptr);
250     o_ptr->marked |= OM_TOUCHED;
251     player_ptr->equip_cnt++;
252
253 #define STR_WIELD_HAND_RIGHT _("%s(%c)を右手に装備した。", "You are wielding %s (%c) in your right hand.")
254 #define STR_WIELD_HAND_LEFT _("%s(%c)を左手に装備した。", "You are wielding %s (%c) in your left hand.")
255 #define STR_WIELD_HANDS_TWO _("%s(%c)を両手で構えた。", "You are wielding %s (%c) with both hands.")
256
257     switch (slot) {
258     case INVEN_MAIN_HAND:
259         if (o_ptr->allow_two_hands_wielding() && (empty_hands(player_ptr, false) == EMPTY_HAND_SUB) && can_two_hands_wielding(player_ptr))
260             act = STR_WIELD_HANDS_TWO;
261         else
262             act = (left_hander ? STR_WIELD_HAND_LEFT : STR_WIELD_HAND_RIGHT);
263
264         break;
265     case INVEN_SUB_HAND:
266         if (o_ptr->allow_two_hands_wielding() && (empty_hands(player_ptr, false) == EMPTY_HAND_MAIN) && can_two_hands_wielding(player_ptr))
267             act = STR_WIELD_HANDS_TWO;
268         else
269             act = (left_hander ? STR_WIELD_HAND_RIGHT : STR_WIELD_HAND_LEFT);
270
271         break;
272     case INVEN_BOW:
273         act = _("%s(%c)を射撃用に装備した。", "You are shooting with %s (%c).");
274         break;
275     case INVEN_LITE:
276         act = _("%s(%c)を光源にした。", "Your light source is %s (%c).");
277         break;
278     default:
279         act = _("%s(%c)を装備した。", "You are wearing %s (%c).");
280         break;
281     }
282
283     describe_flavor(player_ptr, o_name, o_ptr, 0);
284     msg_format(act, o_name, index_to_label(slot));
285     if (o_ptr->is_cursed()) {
286         msg_print(_("うわ! すさまじく冷たい!", "Oops! It feels deathly cold!"));
287         chg_virtue(player_ptr, V_HARMONY, -1);
288         o_ptr->ident |= (IDENT_SENSE);
289     }
290
291     if ((o_ptr->name1 == ART_STONEMASK) && (player_ptr->prace != PlayerRaceType::VAMPIRE) && (player_ptr->prace != PlayerRaceType::ANDROID))
292         change_race(player_ptr, PlayerRaceType::VAMPIRE, "");
293
294     calc_android_exp(player_ptr);
295     player_ptr->update |= PU_BONUS | PU_TORCH | PU_MANA;
296     player_ptr->redraw |= PR_EQUIPPY;
297     player_ptr->window_flags |= PW_INVEN | PW_EQUIP | PW_PLAYER;
298 }
299
300 /*!
301  * @brief 装備を外すコマンドのメインルーチン / Take off an item
302  */
303 void do_cmd_takeoff(player_type *player_ptr)
304 {
305     OBJECT_IDX item;
306     object_type *o_ptr;
307     PlayerClass(player_ptr).break_samurai_stance({ SamuraiStance::MUSOU });
308
309     concptr q = _("どれを装備からはずしますか? ", "Take off which item? ");
310     concptr s = _("はずせる装備がない。", "You are not wearing anything to take off.");
311     o_ptr = choose_object(player_ptr, &item, q, s, (USE_EQUIP | IGNORE_BOTHHAND_SLOT));
312     if (!o_ptr)
313         return;
314
315     PlayerEnergy energy(player_ptr);
316     if (o_ptr->is_cursed()) {
317         if (o_ptr->curse_flags.has(TRC::PERMA_CURSE) || (player_ptr->pclass != PlayerClassType::BERSERKER)) {
318             msg_print(_("ふーむ、どうやら呪われているようだ。", "Hmmm, it seems to be cursed."));
319             return;
320         }
321
322         if ((o_ptr->curse_flags.has(TRC::HEAVY_CURSE) && one_in_(7)) || one_in_(4)) {
323             msg_print(_("呪われた装備を力づくで剥がした!", "You tore off a piece of cursed equipment by sheer strength!"));
324             o_ptr->ident |= (IDENT_SENSE);
325             o_ptr->curse_flags.clear();
326             o_ptr->feeling = FEEL_NONE;
327             player_ptr->update |= PU_BONUS;
328             player_ptr->window_flags |= PW_EQUIP;
329             msg_print(_("呪いを打ち破った。", "You break the curse."));
330         } else {
331             msg_print(_("装備を外せなかった。", "You couldn't remove the equipment."));
332             energy.set_player_turn_energy(50);
333             return;
334         }
335     }
336
337     sound(SOUND_TAKE_OFF);
338     energy.set_player_turn_energy(50);
339     (void)inven_takeoff(player_ptr, item, 255);
340     verify_equip_slot(player_ptr, item);
341     calc_android_exp(player_ptr);
342     player_ptr->update |= PU_BONUS | PU_TORCH | PU_MANA;
343     player_ptr->redraw |= PR_EQUIPPY;
344     player_ptr->window_flags |= PW_INVEN | PW_EQUIP | PW_PLAYER;
345 }