6 #include "object-use/zaprod-execution.h"
7 #include "action/action-limited.h"
8 #include "avatar/avatar.h"
9 #include "cmd-item/cmd-zaprod.h" // 相互依存。暫定的措置、後で何とかする.
10 #include "core/window-redrawer.h"
11 #include "game-option/disturbance-options.h"
12 #include "main/sound-definitions-table.h"
13 #include "main/sound-of-music.h"
14 #include "object-use/item-use-checker.h"
15 #include "object/object-info.h"
16 #include "perception/object-perception.h"
17 #include "player-base/player-class.h"
18 #include "player-status/player-energy.h"
19 #include "status/experience.h"
20 #include "sv-definition/sv-other-types.h"
21 #include "sv-definition/sv-rod-types.h"
22 #include "system/baseitem-info.h"
23 #include "system/item-entity.h"
24 #include "system/player-type-definition.h"
25 #include "system/redrawing-flags-updater.h"
26 #include "target/target-getter.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"
35 * @param player_ptr プレイヤーへの参照ポインタ
36 * @param item 使うオブジェクトの所持品ID
38 ObjectZapRodEntity::ObjectZapRodEntity(PlayerType *player_ptr)
39 : player_ptr(player_ptr)
46 void ObjectZapRodEntity::execute(INVENTORY_IDX item)
49 auto use_charge = true;
50 auto *o_ptr = ref_item(this->player_ptr, item);
51 if ((item < 0) && (o_ptr->number > 1)) {
52 msg_print(_("まずはロッドを拾わなければ。", "You must first pick up the rods."));
56 if (o_ptr->is_aiming_rod() || !o_ptr->is_aware()) {
57 if (!get_aim_dir(this->player_ptr, &dir)) {
62 PlayerEnergy(this->player_ptr).set_player_turn_energy(100);
63 if (!this->check_can_zap()) {
67 auto lev = o_ptr->get_baseitem().level;
68 auto chance = this->player_ptr->skill_dev;
69 if (this->player_ptr->effects()->confusion()->is_confused()) {
75 fail -= (chance - fail) * 2;
77 chance -= (fail - chance) * 2;
80 if (fail < USE_DEVICE) {
84 if (chance < USE_DEVICE) {
89 if (PlayerClass(this->player_ptr).equals(PlayerClassType::BERSERKER)) {
91 } else if (chance > fail) {
92 success = randint0(chance * 2) >= fail;
94 success = randint0(fail * 2) < chance;
102 msg_print(_("うまくロッドを使えなかった。", "You failed to use the rod properly."));
107 const auto &baseitem = o_ptr->get_baseitem();
108 if ((o_ptr->number == 1) && (o_ptr->timeout)) {
113 msg_print(_("このロッドはまだ魔力を充填している最中だ。", "The rod is still charging."));
115 } else if ((o_ptr->number > 1) && (o_ptr->timeout > baseitem.pval * (o_ptr->number - 1))) {
120 msg_print(_("そのロッドはまだ充填中です。", "The rods are all still charging."));
125 auto ident = rod_effect(this->player_ptr, o_ptr->bi_key.sval().value(), dir, &use_charge, false);
127 o_ptr->timeout += baseitem.pval;
130 auto &rfu = RedrawingFlagsUpdater::get_instance();
131 static constexpr auto flags_srf = {
132 StatusRedrawingFlag::COMBINATION,
133 StatusRedrawingFlag::REORDER,
135 rfu.set_flags(flags_srf);
136 if (!(o_ptr->is_aware())) {
137 chg_virtue(this->player_ptr, Virtue::PATIENCE, -1);
138 chg_virtue(this->player_ptr, Virtue::CHANCE, 1);
139 chg_virtue(this->player_ptr, Virtue::KNOWLEDGE, -1);
143 if ((ident != 0) && !o_ptr->is_aware()) {
144 object_aware(this->player_ptr, o_ptr);
145 gain_exp(this->player_ptr, (lev + (this->player_ptr->lev >> 1)) / this->player_ptr->lev);
148 const auto flags_swrf = {
149 SubWindowRedrawingFlag::INVENTORY,
150 SubWindowRedrawingFlag::EQUIPMENT,
151 SubWindowRedrawingFlag::PLAYER,
152 SubWindowRedrawingFlag::FLOOR_ITEMS,
153 SubWindowRedrawingFlag::FOUND_ITEMS,
155 rfu.set_flags(flags_swrf);
158 bool ObjectZapRodEntity::check_can_zap()
160 if (cmd_limit_time_walk(this->player_ptr)) {
164 return ItemUseChecker(this->player_ptr).check_stun(_("朦朧としていてロッドを振れなかった!", "You are too stunned to zap it!"));