1 #include "cmd-item/cmd-destroy.h"
2 #include "autopick/autopick-registry.h"
3 #include "autopick/autopick.h"
4 #include "avatar/avatar.h"
5 #include "core/asking-player.h"
6 #include "core/stuff-handler.h"
7 #include "core/window-redrawer.h"
8 #include "flavor/flavor-describer.h"
9 #include "flavor/object-flavor-types.h"
10 #include "floor/floor-object.h"
11 #include "game-option/input-options.h"
12 #include "inventory/inventory-object.h"
13 #include "inventory/inventory-slot-types.h"
14 #include "io/input-key-acceptor.h"
15 #include "io/input-key-requester.h"
16 #include "main/sound-definitions-table.h"
17 #include "main/sound-of-music.h"
18 #include "object-hook/hook-expendable.h"
19 #include "object-hook/hook-magic.h"
20 #include "object/item-use-flags.h"
21 #include "object/object-stack.h"
22 #include "object/object-value.h"
23 #include "player-base/player-class.h"
24 #include "player-info/samurai-data-type.h"
25 #include "player-status/player-energy.h"
26 #include "player/attack-defense-types.h"
27 #include "player/special-defense-types.h"
28 #include "racial/racial-android.h"
29 #include "realm/realm-names-table.h"
30 #include "status/action-setter.h"
31 #include "status/experience.h"
32 #include "system/object-type-definition.h"
33 #include "system/player-type-definition.h"
34 #include "term/screen-processor.h"
35 #include "util/int-char-converter.h"
36 #include "view/display-messages.h"
38 typedef struct destroy_type {
45 GAME_TEXT o_name[MAX_NLEN];
46 char out_val[MAX_NLEN + 40];
49 static destroy_type *initialize_destroy_type(destroy_type *destroy_ptr, object_type *o_ptr)
52 destroy_ptr->force = false;
53 destroy_ptr->q_ptr = o_ptr;
57 static bool check_destory_item(player_type *player_ptr, destroy_type *destroy_ptr)
59 if (destroy_ptr->force || (!confirm_destroy && (object_value(destroy_ptr->o_ptr) <= 0)))
62 describe_flavor(player_ptr, destroy_ptr->o_name, destroy_ptr->o_ptr, OD_OMIT_PREFIX);
63 sprintf(destroy_ptr->out_val, _("本当に%sを壊しますか? [y/n/Auto]", "Really destroy %s? [y/n/Auto]"), destroy_ptr->o_name);
65 message_add(destroy_ptr->out_val);
66 player_ptr->window_flags |= PW_MESSAGE;
67 handle_stuff(player_ptr);
69 prt(destroy_ptr->out_val, 0, 0);
72 if (i == 'y' || i == 'Y')
75 if (i == ESCAPE || i == 'n' || i == 'N')
81 if (autopick_autoregister(player_ptr, destroy_ptr->o_ptr))
82 autopick_alter_item(player_ptr, destroy_ptr->item, true);
88 static bool select_destroying_item(player_type *player_ptr, destroy_type *destroy_ptr)
90 concptr q = _("どのアイテムを壊しますか? ", "Destroy which item? ");
91 concptr s = _("壊せるアイテムを持っていない。", "You have nothing to destroy.");
92 destroy_ptr->o_ptr = choose_object(player_ptr, &destroy_ptr->item, q, s, USE_INVEN | USE_FLOOR);
93 if (destroy_ptr->o_ptr == nullptr)
96 if (!check_destory_item(player_ptr, destroy_ptr))
99 if (destroy_ptr->o_ptr->number <= 1)
102 destroy_ptr->amt = get_quantity(nullptr, destroy_ptr->o_ptr->number);
103 return destroy_ptr->amt > 0;
107 * @brief 一部職業で高位魔法書の破壊による経験値上昇の判定
108 * @param player_ptr プレイヤーへの参照ポインタ
109 * @param destory_ptr アイテム破壊構造体への参照ポインタ
110 * return 魔法書の破壊によって経験値が入るならばTRUE
112 static bool decide_magic_book_exp(player_type *player_ptr, destroy_type *destroy_ptr)
114 if (player_ptr->prace == PlayerRaceType::ANDROID)
117 if ((player_ptr->pclass == PlayerClassType::WARRIOR) || (player_ptr->pclass == PlayerClassType::BERSERKER))
120 if (player_ptr->pclass != PlayerClassType::PALADIN)
123 bool gain_expr = false;
124 if (is_good_realm(player_ptr->realm1)) {
125 if (!is_good_realm(tval2realm(destroy_ptr->q_ptr->tval)))
128 if (is_good_realm(tval2realm(destroy_ptr->q_ptr->tval)))
135 static void gain_exp_by_destroying_magic_book(player_type *player_ptr, destroy_type *destroy_ptr)
137 bool gain_expr = decide_magic_book_exp(player_ptr, destroy_ptr);
138 if (!gain_expr || (player_ptr->exp >= PY_MAX_EXP))
141 int32_t tester_exp = player_ptr->max_exp / 20;
142 if (tester_exp > 10000)
145 if (destroy_ptr->q_ptr->sval < 3)
151 msg_print(_("更に経験を積んだような気がする。", "You feel more experienced."));
152 gain_exp(player_ptr, tester_exp * destroy_ptr->amt);
155 static void process_destroy_magic_book(player_type *player_ptr, destroy_type *destroy_ptr)
157 if (!item_tester_high_level_book(destroy_ptr->q_ptr))
160 gain_exp_by_destroying_magic_book(player_ptr, destroy_ptr);
161 if (item_tester_high_level_book(destroy_ptr->q_ptr) && destroy_ptr->q_ptr->tval == ItemKindType::LIFE_BOOK) {
162 chg_virtue(player_ptr, V_UNLIFE, 1);
163 chg_virtue(player_ptr, V_VITALITY, -1);
164 } else if (item_tester_high_level_book(destroy_ptr->q_ptr) && destroy_ptr->q_ptr->tval == ItemKindType::DEATH_BOOK) {
165 chg_virtue(player_ptr, V_UNLIFE, -1);
166 chg_virtue(player_ptr, V_VITALITY, 1);
169 if ((destroy_ptr->q_ptr->to_a != 0) || (destroy_ptr->q_ptr->to_h != 0) || (destroy_ptr->q_ptr->to_d != 0))
170 chg_virtue(player_ptr, V_ENCHANT, -1);
172 if (object_value_real(destroy_ptr->q_ptr) > 30000)
173 chg_virtue(player_ptr, V_SACRIFICE, 2);
174 else if (object_value_real(destroy_ptr->q_ptr) > 10000)
175 chg_virtue(player_ptr, V_SACRIFICE, 1);
178 static void exe_destroy_item(player_type *player_ptr, destroy_type *destroy_ptr)
180 destroy_ptr->q_ptr->copy_from(destroy_ptr->o_ptr);
181 msg_format(_("%sを壊した。", "You destroy %s."), destroy_ptr->o_name);
182 sound(SOUND_DESTITEM);
183 reduce_charges(destroy_ptr->o_ptr, destroy_ptr->amt);
184 vary_item(player_ptr, destroy_ptr->item, -destroy_ptr->amt);
185 process_destroy_magic_book(player_ptr, destroy_ptr);
186 if ((destroy_ptr->q_ptr->to_a != 0) || (destroy_ptr->q_ptr->to_d != 0) || (destroy_ptr->q_ptr->to_h != 0))
187 chg_virtue(player_ptr, V_HARMONY, 1);
189 if (destroy_ptr->item >= INVEN_MAIN_HAND)
190 calc_android_exp(player_ptr);
194 * @brief アイテムを破壊するコマンドのメインルーチン / Destroy an item
195 * @param player_ptr プレイヤーへの参照ポインタ
197 void do_cmd_destroy(player_type *player_ptr)
199 PlayerClass(player_ptr).break_samurai_stance({ SamuraiStanceType::MUSOU });
202 destroy_type tmp_destroy;
203 destroy_type *destroy_ptr = initialize_destroy_type(&tmp_destroy, &forge);
205 destroy_ptr->force = true;
207 if (!select_destroying_item(player_ptr, destroy_ptr))
210 destroy_ptr->old_number = destroy_ptr->o_ptr->number;
211 destroy_ptr->o_ptr->number = destroy_ptr->amt;
212 describe_flavor(player_ptr, destroy_ptr->o_name, destroy_ptr->o_ptr, 0);
213 destroy_ptr->o_ptr->number = destroy_ptr->old_number;
214 PlayerEnergy energy(player_ptr);
215 energy.set_player_turn_energy(100);
216 if (!can_player_destroy_object(player_ptr, destroy_ptr->o_ptr)) {
217 energy.reset_player_turn();
218 msg_format(_("%sは破壊不可能だ。", "You cannot destroy %s."), destroy_ptr->o_name);
222 exe_destroy_item(player_ptr, destroy_ptr);