7 #include "object-use/read/read-execution.h"
8 #include "action/action-limited.h"
9 #include "avatar/avatar.h"
10 #include "core/player-update-types.h"
11 #include "core/window-redrawer.h"
12 #include "inventory/inventory-object.h"
13 #include "main/sound-definitions-table.h"
14 #include "main/sound-of-music.h"
15 #include "object-use/item-use-checker.h"
16 #include "object-use/read/read-executor-factory.h"
17 #include "object/object-info.h"
18 #include "perception/object-perception.h"
19 #include "player-base/player-class.h"
20 #include "player-status/player-energy.h"
21 #include "spell-realm/spells-hex.h"
22 #include "spell-realm/spells-song.h"
23 #include "status/experience.h"
24 #include "system/baseitem-info.h"
25 #include "system/item-entity.h"
26 #include "system/player-type-definition.h"
27 #include "system/redrawing-flags-updater.h"
28 #include "util/bit-flags-calculator.h"
29 #include "view/display-messages.h"
33 * @param player_ptr プレイヤーへの参照ポインタ
34 * @param item 読むオブジェクトの所持品ID
36 ObjectReadEntity::ObjectReadEntity(PlayerType *player_ptr, INVENTORY_IDX item)
37 : player_ptr(player_ptr)
44 * @param known 判明済ならばTRUE
46 void ObjectReadEntity::execute(bool known)
48 auto *o_ptr = ref_item(this->player_ptr, this->item);
49 PlayerEnergy(this->player_ptr).set_player_turn_energy(100);
50 if (!this->can_read()) {
54 if (music_singing_any(this->player_ptr)) {
55 stop_singing(this->player_ptr);
58 SpellHex spell_hex(this->player_ptr);
59 if (spell_hex.is_spelling_any() && ((this->player_ptr->lev < 35) || spell_hex.is_casting_full_capacity())) {
60 (void)SpellHex(this->player_ptr).stop_all_spells();
63 auto executor = ReadExecutorFactory::create(player_ptr, o_ptr, known);
64 auto used_up = executor->read();
65 auto &rfu = RedrawingFlagsUpdater::get_instance();
66 using Srf = StatusRedrawingFlag;
67 EnumClassFlagGroup<Srf> flags_srf = { Srf::COMBINATION, Srf::REORDER };
68 if (rfu.has(Srf::AUTO_DESTRUCTION)) {
69 flags_srf.set(Srf::AUTO_DESTRUCTION);
72 rfu.reset_flags(flags_srf);
73 this->change_virtue_as_read(*o_ptr);
75 this->gain_exp_from_item_use(o_ptr, executor->is_identified());
76 this->player_ptr->window_flags |= PW_INVENTORY | PW_EQUIPMENT | PW_PLAYER;
77 rfu.set_flags(flags_srf);
83 vary_item(this->player_ptr, this->item, -1);
86 bool ObjectReadEntity::can_read() const
88 if (cmd_limit_time_walk(this->player_ptr)) {
92 if (PlayerClass(this->player_ptr).equals(PlayerClassType::BERSERKER)) {
93 msg_print(_("巻物なんて読めない。", "You cannot read."));
97 return ItemUseChecker(this->player_ptr).check_stun(_("朦朧としていて読めなかった!", "You too stunned to read it!"));
100 void ObjectReadEntity::change_virtue_as_read(ItemEntity &o_ref)
102 if (o_ref.is_aware()) {
106 chg_virtue(this->player_ptr, Virtue::PATIENCE, -1);
107 chg_virtue(this->player_ptr, Virtue::CHANCE, 1);
108 chg_virtue(this->player_ptr, Virtue::KNOWLEDGE, -1);
111 void ObjectReadEntity::gain_exp_from_item_use(ItemEntity *o_ptr, bool is_identified)
113 if (!is_identified || o_ptr->is_aware()) {
117 object_aware(this->player_ptr, o_ptr);
118 auto lev = o_ptr->get_baseitem().level;
119 gain_exp(this->player_ptr, (lev + (this->player_ptr->lev >> 1)) / this->player_ptr->lev);