6 #include "object-use/use-execution.h"
7 #include "action/action-limited.h"
8 #include "avatar/avatar.h"
9 #include "cmd-item/cmd-usestaff.h"
10 #include "core/window-redrawer.h"
11 #include "floor/floor-object.h"
12 #include "game-option/disturbance-options.h"
13 #include "inventory/inventory-object.h"
14 #include "main/sound-definitions-table.h"
15 #include "main/sound-of-music.h"
16 #include "object-enchant/special-object-flags.h"
17 #include "object-use/item-use-checker.h"
18 #include "object/object-info.h"
19 #include "perception/object-perception.h"
20 #include "player-base/player-class.h"
21 #include "player-status/player-energy.h"
22 #include "status/experience.h"
23 #include "system/baseitem-info.h"
24 #include "system/item-entity.h"
25 #include "system/player-type-definition.h"
26 #include "system/redrawing-flags-updater.h"
27 #include "term/screen-processor.h"
28 #include "timed-effect/player-confusion.h"
29 #include "timed-effect/timed-effects.h"
30 #include "util/bit-flags-calculator.h"
31 #include "view/display-messages.h"
32 #include "view/object-describer.h"
36 * @param player_ptr プレイヤーへの参照ポインタ
37 * @param i_idx 使うオブジェクトの所持品ID
39 ObjectUseEntity::ObjectUseEntity(PlayerType *player_ptr, INVENTORY_IDX i_idx)
40 : player_ptr(player_ptr)
48 void ObjectUseEntity::execute()
50 auto use_charge = true;
51 auto *o_ptr = ref_item(this->player_ptr, this->i_idx);
52 if ((this->i_idx < 0) && (o_ptr->number > 1)) {
53 msg_print(_("まずは杖を拾わなければ。", "You must first pick up the staffs."));
57 PlayerEnergy(this->player_ptr).set_player_turn_energy(100);
58 if (!this->check_can_use()) {
62 auto lev = o_ptr->get_baseitem().level;
64 lev = 50 + (lev - 50) / 2;
67 auto chance = this->player_ptr->skill_dev;
68 if (this->player_ptr->effects()->confusion()->is_confused()) {
72 chance = chance - lev;
73 if ((chance < USE_DEVICE) && one_in_(USE_DEVICE - chance + 1)) {
77 if ((chance < USE_DEVICE) || (randint1(chance) < USE_DEVICE) || PlayerClass(this->player_ptr).equals(PlayerClassType::BERSERKER)) {
82 msg_print(_("杖をうまく使えなかった。", "You failed to use the staff properly."));
87 if (o_ptr->pval <= 0) {
92 msg_print(_("この杖にはもう魔力が残っていない。", "The staff has no charges left."));
93 o_ptr->ident |= IDENT_EMPTY;
94 auto &rfu = RedrawingFlagsUpdater::get_instance();
95 static constexpr auto flags = {
96 StatusRecalculatingFlag::COMBINATION,
97 StatusRecalculatingFlag::REORDER,
100 rfu.set_flag(SubWindowRedrawingFlag::INVENTORY);
105 auto ident = staff_effect(this->player_ptr, *o_ptr->bi_key.sval(), &use_charge, false, false, o_ptr->is_aware());
106 if (!(o_ptr->is_aware())) {
107 chg_virtue(this->player_ptr, Virtue::PATIENCE, -1);
108 chg_virtue(this->player_ptr, Virtue::CHANCE, 1);
109 chg_virtue(this->player_ptr, Virtue::KNOWLEDGE, -1);
112 auto &rfu = RedrawingFlagsUpdater::get_instance();
113 using Srf = StatusRecalculatingFlag;
114 EnumClassFlagGroup<Srf> flags_srf = { Srf::COMBINATION, Srf::REORDER };
115 if (rfu.has(Srf::AUTO_DESTRUCTION)) {
116 flags_srf.set(Srf::AUTO_DESTRUCTION);
119 rfu.reset_flags(flags_srf);
120 o_ptr->mark_as_tried();
121 if (ident && !o_ptr->is_aware()) {
122 object_aware(this->player_ptr, o_ptr);
123 gain_exp(this->player_ptr, (lev + (this->player_ptr->lev >> 1)) / this->player_ptr->lev);
126 static constexpr auto flags_swrf = {
127 SubWindowRedrawingFlag::INVENTORY,
128 SubWindowRedrawingFlag::EQUIPMENT,
129 SubWindowRedrawingFlag::PLAYER,
130 SubWindowRedrawingFlag::FLOOR_ITEMS,
131 SubWindowRedrawingFlag::FOUND_ITEMS,
133 rfu.set_flags(flags_swrf);
134 rfu.set_flags(flags_srf);
140 if ((this->i_idx >= 0) && (o_ptr->number > 1)) {
142 auto *q_ptr = &forge;
143 q_ptr->copy_from(o_ptr);
147 this->i_idx = store_item_to_inventory(this->player_ptr, q_ptr);
148 msg_print(_("杖をまとめなおした。", "You unstack your staff."));
151 if (this->i_idx >= 0) {
152 inven_item_charges(this->player_ptr->inventory_list[this->i_idx]);
154 floor_item_charges(this->player_ptr->current_floor_ptr, 0 - this->i_idx);
158 bool ObjectUseEntity::check_can_use()
160 if (cmd_limit_time_walk(this->player_ptr)) {
164 return ItemUseChecker(this->player_ptr).check_stun(_("朦朧としていて杖を振れなかった!", "You are too stunned to use it!"));