OSDN Git Service

73cf68aa5939f7dd65f3c4583cd9a0360a2227c8
[hengbandforosx/hengbandosx.git] / src / action / weapon-shield.cpp
1 /*!
2  * @file weapon-shield.cpp
3  * @brief 手装備持ち替え処理実装
4  */
5
6 #include "action/weapon-shield.h"
7 #include "flavor/flavor-describer.h"
8 #include "game-option/birth-options.h"
9 #include "inventory/inventory-object.h"
10 #include "inventory/inventory-slot-types.h"
11 #include "object-hook/hook-weapon.h"
12 #include "player-info/equipment-info.h"
13 #include "player-status/player-hand-types.h"
14 #include "system/item-entity.h"
15 #include "system/player-type-definition.h"
16 #include "view/display-messages.h"
17
18 /*!
19  * @brief 持ち替え処理
20  * @param player_ptr プレイヤーへの参照ポインタ
21  * @param item 持ち替えを行いたい装備部位ID
22  */
23 void verify_equip_slot(PlayerType *player_ptr, INVENTORY_IDX item)
24 {
25     ItemEntity *o_ptr, *new_o_ptr;
26     std::string item_name;
27     if (item == INVEN_MAIN_HAND) {
28         if (!has_melee_weapon(player_ptr, INVEN_SUB_HAND)) {
29             return;
30         }
31
32         o_ptr = &player_ptr->inventory_list[INVEN_SUB_HAND];
33         item_name = describe_flavor(player_ptr, o_ptr, 0);
34
35         if (o_ptr->is_cursed()) {
36             if (o_ptr->allow_two_hands_wielding() && can_two_hands_wielding(player_ptr)) {
37                 msg_format(_("%sを両手で構えた。", "You are wielding %s with both hands."), item_name.data());
38             }
39             return;
40         }
41
42         new_o_ptr = &player_ptr->inventory_list[INVEN_MAIN_HAND];
43         new_o_ptr->copy_from(o_ptr);
44         inven_item_increase(player_ptr, INVEN_SUB_HAND, -((int)o_ptr->number));
45         inven_item_optimize(player_ptr, INVEN_SUB_HAND);
46         if (new_o_ptr->allow_two_hands_wielding() && can_two_hands_wielding(player_ptr)) {
47             msg_format(_("%sを両手で構えた。", "You are wielding %s with both hands."), item_name.data());
48         } else {
49             const auto mes = _("%sを%sで構えた。", "You are wielding %s in your %s hand.");
50             msg_format(mes, item_name.data(), (left_hander ? _("左手", "left") : _("右手", "right")));
51         }
52         return;
53     }
54
55     if (item != INVEN_SUB_HAND) {
56         return;
57     }
58
59     o_ptr = &player_ptr->inventory_list[INVEN_MAIN_HAND];
60     if (o_ptr->is_valid()) {
61         item_name = describe_flavor(player_ptr, o_ptr, 0);
62     }
63
64     if (has_melee_weapon(player_ptr, INVEN_MAIN_HAND)) {
65         if (o_ptr->allow_two_hands_wielding() && can_two_hands_wielding(player_ptr)) {
66             msg_format(_("%sを両手で構えた。", "You are wielding %s with both hands."), item_name.data());
67         }
68
69         return;
70     }
71
72     if ((empty_hands(player_ptr, false) & EMPTY_HAND_MAIN) || o_ptr->is_cursed()) {
73         return;
74     }
75
76     new_o_ptr = &player_ptr->inventory_list[INVEN_SUB_HAND];
77     new_o_ptr->copy_from(o_ptr);
78     inven_item_increase(player_ptr, INVEN_MAIN_HAND, -((int)o_ptr->number));
79     inven_item_optimize(player_ptr, INVEN_MAIN_HAND);
80     msg_format(_("%sを持ち替えた。", "You shifted %s to your other hand."), item_name.data());
81 }