7 #include "object-use/read/read-execution.h"
8 #include "action/action-limited.h"
9 #include "avatar/avatar.h"
10 #include "core/window-redrawer.h"
11 #include "inventory/inventory-object.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-use/read/read-executor-factory.h"
16 #include "object/object-info.h"
17 #include "perception/object-perception.h"
18 #include "player-base/player-class.h"
19 #include "player-status/player-energy.h"
20 #include "spell-realm/spells-hex.h"
21 #include "spell-realm/spells-song.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 "util/bit-flags-calculator.h"
28 #include "view/display-messages.h"
32 * @param player_ptr プレイヤーへの参照ポインタ
33 * @param item 読むオブジェクトの所持品ID
35 ObjectReadEntity::ObjectReadEntity(PlayerType *player_ptr, INVENTORY_IDX item)
36 : player_ptr(player_ptr)
43 * @param known 判明済ならばTRUE
45 void ObjectReadEntity::execute(bool known)
47 auto *o_ptr = ref_item(this->player_ptr, this->item);
48 PlayerEnergy(this->player_ptr).set_player_turn_energy(100);
49 if (!this->can_read()) {
53 if (music_singing_any(this->player_ptr)) {
54 stop_singing(this->player_ptr);
57 SpellHex spell_hex(this->player_ptr);
58 if (spell_hex.is_spelling_any() && ((this->player_ptr->lev < 35) || spell_hex.is_casting_full_capacity())) {
59 (void)SpellHex(this->player_ptr).stop_all_spells();
62 auto executor = ReadExecutorFactory::create(player_ptr, o_ptr, known);
63 auto used_up = executor->read();
64 auto &rfu = RedrawingFlagsUpdater::get_instance();
65 using Srf = StatusRecalculatingFlag;
66 EnumClassFlagGroup<Srf> flags_srf = { Srf::COMBINATION, Srf::REORDER };
67 if (rfu.has(Srf::AUTO_DESTRUCTION)) {
68 flags_srf.set(Srf::AUTO_DESTRUCTION);
71 rfu.reset_flags(flags_srf);
72 this->change_virtue_as_read(*o_ptr);
74 this->gain_exp_from_item_use(o_ptr, executor->is_identified());
75 static constexpr auto flags_swrf = {
76 SubWindowRedrawingFlag::INVENTORY,
77 SubWindowRedrawingFlag::EQUIPMENT,
78 SubWindowRedrawingFlag::PLAYER,
80 rfu.set_flags(flags_swrf);
81 rfu.set_flags(flags_srf);
87 vary_item(this->player_ptr, this->item, -1);
90 bool ObjectReadEntity::can_read() const
92 if (cmd_limit_time_walk(this->player_ptr)) {
96 if (PlayerClass(this->player_ptr).equals(PlayerClassType::BERSERKER)) {
97 msg_print(_("巻物なんて読めない。", "You cannot read."));
101 return ItemUseChecker(this->player_ptr).check_stun(_("朦朧としていて読めなかった!", "You too stunned to read it!"));
104 void ObjectReadEntity::change_virtue_as_read(ItemEntity &o_ref)
106 if (o_ref.is_aware()) {
110 chg_virtue(this->player_ptr, Virtue::PATIENCE, -1);
111 chg_virtue(this->player_ptr, Virtue::CHANCE, 1);
112 chg_virtue(this->player_ptr, Virtue::KNOWLEDGE, -1);
115 void ObjectReadEntity::gain_exp_from_item_use(ItemEntity *o_ptr, bool is_identified)
117 if (!is_identified || o_ptr->is_aware()) {
121 object_aware(this->player_ptr, o_ptr);
122 auto lev = o_ptr->get_baseitem().level;
123 gain_exp(this->player_ptr, (lev + (this->player_ptr->lev >> 1)) / this->player_ptr->lev);