1 #include "object-use/zapwand-execution.h"
2 #include "action/action-limited.h"
3 #include "avatar/avatar.h"
4 #include "cmd-item/cmd-zapwand.h" // 相互依存。暫定的措置、後で何とかする.
5 #include "core/window-redrawer.h"
6 #include "floor/floor-object.h"
7 #include "game-option/disturbance-options.h"
8 #include "game-option/input-options.h"
9 #include "main/sound-definitions-table.h"
10 #include "main/sound-of-music.h"
11 #include "object-enchant/special-object-flags.h"
12 #include "object-use/item-use-checker.h"
13 #include "object/object-info.h"
14 #include "perception/object-perception.h"
15 #include "player-base/player-class.h"
16 #include "player-status/player-energy.h"
17 #include "status/experience.h"
18 #include "sv-definition/sv-wand-types.h"
19 #include "system/baseitem-info.h"
20 #include "system/item-entity.h"
21 #include "system/player-type-definition.h"
22 #include "system/redrawing-flags-updater.h"
23 #include "target/target-getter.h"
24 #include "term/screen-processor.h"
25 #include "timed-effect/player-confusion.h"
26 #include "timed-effect/timed-effects.h"
27 #include "util/bit-flags-calculator.h"
28 #include "view/display-messages.h"
29 #include "view/object-describer.h"
31 ObjectZapWandEntity::ObjectZapWandEntity(PlayerType *player_ptr)
32 : player_ptr(player_ptr)
37 * @brief 魔法棒を使うコマンドのサブルーチン /
38 * @param item 使うオブジェクトの所持品ID
40 void ObjectZapWandEntity::execute(INVENTORY_IDX item)
42 auto old_target_pet = target_pet;
43 auto *o_ptr = ref_item(this->player_ptr, item);
44 if ((item < 0) && (o_ptr->number > 1)) {
45 msg_print(_("まずは魔法棒を拾わなければ。", "You must first pick up the wands."));
49 const auto sval = o_ptr->bi_key.sval();
50 if (o_ptr->is_aware() && (sval == SV_WAND_HEAL_MONSTER || sval == SV_WAND_HASTE_MONSTER)) {
55 if (!get_aim_dir(this->player_ptr, &dir)) {
56 target_pet = old_target_pet;
60 target_pet = old_target_pet;
61 PlayerEnergy(this->player_ptr).set_player_turn_energy(100);
62 if (!this->check_can_zap()) {
66 auto lev = o_ptr->get_baseitem().level;
68 lev = 50 + (lev - 50) / 2;
71 auto chance = this->player_ptr->skill_dev;
72 if (this->player_ptr->effects()->confusion()->is_confused()) {
76 chance = chance - lev;
77 if ((chance < USE_DEVICE) && one_in_(USE_DEVICE - chance + 1)) {
81 if ((chance < USE_DEVICE) || (randint1(chance) < USE_DEVICE) || PlayerClass(this->player_ptr).equals(PlayerClassType::BERSERKER)) {
86 msg_print(_("魔法棒をうまく使えなかった。", "You failed to use the wand properly."));
91 auto &rfu = RedrawingFlagsUpdater::get_instance();
92 if (o_ptr->pval <= 0) {
97 msg_print(_("この魔法棒にはもう魔力が残っていない。", "The wand has no charges left."));
98 o_ptr->ident |= IDENT_EMPTY;
99 static constexpr auto flags = {
100 StatusRecalculatingFlag::COMBINATION,
101 StatusRecalculatingFlag::REORDER,
103 rfu.set_flags(flags);
104 rfu.set_flag(SubWindowRedrawingFlag::INVENTORY);
109 auto ident = wand_effect(this->player_ptr, sval.value(), dir, false, false);
110 using Srf = StatusRecalculatingFlag;
111 EnumClassFlagGroup<Srf> flags_srf = { Srf::COMBINATION, Srf::REORDER };
112 if (rfu.has(Srf::AUTO_DESTRUCTION)) {
113 flags_srf.set(Srf::AUTO_DESTRUCTION);
116 rfu.reset_flags(flags_srf);
117 if (!(o_ptr->is_aware())) {
118 chg_virtue(this->player_ptr, Virtue::PATIENCE, -1);
119 chg_virtue(this->player_ptr, Virtue::CHANCE, 1);
120 chg_virtue(this->player_ptr, Virtue::KNOWLEDGE, -1);
124 if (ident && !o_ptr->is_aware()) {
125 object_aware(this->player_ptr, o_ptr);
126 gain_exp(this->player_ptr, (lev + (this->player_ptr->lev >> 1)) / this->player_ptr->lev);
129 static constexpr auto flags_swrf = {
130 SubWindowRedrawingFlag::INVENTORY,
131 SubWindowRedrawingFlag::EQUIPMENT,
132 SubWindowRedrawingFlag::PLAYER,
133 SubWindowRedrawingFlag::FLOOR_ITEMS,
134 SubWindowRedrawingFlag::FOUND_ITEMS,
136 rfu.set_flags(flags_swrf);
137 rfu.set_flags(flags_srf);
140 inven_item_charges(this->player_ptr->inventory_list[item]);
144 floor_item_charges(this->player_ptr->current_floor_ptr, 0 - item);
147 bool ObjectZapWandEntity::check_can_zap() const
149 if (cmd_limit_time_walk(this->player_ptr)) {
153 return ItemUseChecker(this->player_ptr).check_stun(_("朦朧としていて魔法棒を振れなかった!", "You are too stunned to zap it!"));