1 #include "cmd-item/cmd-destroy.h"
2 #include "autopick/autopick-registry.h"
3 #include "autopick/autopick.h"
4 #include "core/asking-player.h"
5 #include "core/stuff-handler.h"
6 #include "core/window-redrawer.h"
7 #include "flavor/flavor-describer.h"
8 #include "flavor/object-flavor-types.h"
9 #include "floor/floor-object.h"
10 #include "game-option/input-options.h"
11 #include "inventory/inventory-object.h"
12 #include "inventory/inventory-slot-types.h"
13 #include "io/input-key-acceptor.h"
14 #include "io/input-key-requester.h"
15 #include "main/sound-definitions-table.h"
16 #include "main/sound-of-music.h"
17 #include "object-hook/hook-expendable.h"
18 #include "object-hook/hook-magic.h"
19 #include "object/item-use-flags.h"
20 #include "object/object-generator.h"
21 #include "object/object-stack.h"
22 #include "object/object-value.h"
23 #include "player/attack-defense-types.h"
24 #include "player/avatar.h"
25 #include "player/special-defense-types.h"
26 #include "racial/racial-android.h"
27 #include "realm/realm-names-table.h"
28 #include "status/action-setter.h"
29 #include "status/experience.h"
30 #include "system/object-type-definition.h"
31 #include "term/screen-processor.h"
32 #include "util/int-char-converter.h"
33 #include "view/display-messages.h"
35 typedef struct destroy_type {
42 GAME_TEXT o_name[MAX_NLEN];
43 char out_val[MAX_NLEN + 40];
46 static destroy_type *initialize_destroy_type(destroy_type *destroy_ptr, object_type *o_ptr)
49 destroy_ptr->force = FALSE;
50 destroy_ptr->q_ptr = o_ptr;
54 static bool check_destory_item(player_type *creature_ptr, destroy_type *destroy_ptr)
56 if (destroy_ptr->force || (!confirm_destroy && (object_value(creature_ptr, destroy_ptr->o_ptr) <= 0)))
59 describe_flavor(creature_ptr, destroy_ptr->o_name, destroy_ptr->o_ptr, OD_OMIT_PREFIX);
60 sprintf(destroy_ptr->out_val, _("
\96{
\93\96\82É%s
\82ð
\89ó
\82µ
\82Ü
\82·
\82©? [y/n/Auto]", "Really destroy %s? [y/n/Auto]"), destroy_ptr->o_name);
62 message_add(destroy_ptr->out_val);
63 creature_ptr->window |= PW_MESSAGE;
64 handle_stuff(creature_ptr);
66 prt(destroy_ptr->out_val, 0, 0);
69 if (i == 'y' || i == 'Y')
72 if (i == ESCAPE || i == 'n' || i == 'N')
78 if (autopick_autoregister(creature_ptr, destroy_ptr->o_ptr))
79 autopick_alter_item(creature_ptr, destroy_ptr->item, TRUE);
85 static bool select_destroying_item(player_type *creature_ptr, destroy_type *destroy_ptr)
87 concptr q = _("
\82Ç
\82Ì
\83A
\83C
\83e
\83\80\82ð
\89ó
\82µ
\82Ü
\82·
\82©? ", "Destroy which item? ");
88 concptr s = _("
\89ó
\82¹
\82é
\83A
\83C
\83e
\83\80\82ð
\8e\9d\82Á
\82Ä
\82¢
\82È
\82¢
\81B", "You have nothing to destroy.");
89 destroy_ptr->o_ptr = choose_object(creature_ptr, &destroy_ptr->item, q, s, USE_INVEN | USE_FLOOR, 0);
90 if (destroy_ptr->o_ptr == NULL)
93 if (!check_destory_item(creature_ptr, destroy_ptr))
96 if (destroy_ptr->o_ptr->number <= 1)
99 destroy_ptr->amt = get_quantity(NULL, destroy_ptr->o_ptr->number);
100 return destroy_ptr->amt > 0;
104 * @brief
\83A
\83C
\83e
\83\80\82ð
\94j
\89ó
\82·
\82é
\83R
\83}
\83\93\83h
\82Ì
\83\81\83C
\83\93\83\8b\81[
\83`
\83\93 / Destroy an item
105 * @param creature_ptr
\83v
\83\8c\81[
\83\84\81[
\82Ö
\82Ì
\8eQ
\8fÆ
\83|
\83C
\83\93\83^
108 void do_cmd_destroy(player_type *creature_ptr)
110 if (creature_ptr->special_defense & KATA_MUSOU)
111 set_action(creature_ptr, ACTION_NONE);
114 destroy_type tmp_destroy;
115 destroy_type *destroy_ptr = initialize_destroy_type(&tmp_destroy, &forge);
117 destroy_ptr->force = TRUE;
119 if (!select_destroying_item(creature_ptr, destroy_ptr))
122 destroy_ptr->old_number = destroy_ptr->o_ptr->number;
123 destroy_ptr->o_ptr->number = destroy_ptr->amt;
124 describe_flavor(creature_ptr, destroy_ptr->o_name, destroy_ptr->o_ptr, 0);
125 destroy_ptr->o_ptr->number = destroy_ptr->old_number;
126 take_turn(creature_ptr, 100);
127 if (!can_player_destroy_object(creature_ptr, destroy_ptr->o_ptr)) {
128 free_turn(creature_ptr);
129 msg_format(_("%s
\82Í
\94j
\89ó
\95s
\89Â
\94\
\82¾
\81B", "You cannot destroy %s."), destroy_ptr->o_name);
133 object_copy(destroy_ptr->q_ptr, destroy_ptr->o_ptr);
134 msg_format(_("%s
\82ð
\89ó
\82µ
\82½
\81B", "You destroy %s."), destroy_ptr->o_name);
135 sound(SOUND_DESTITEM);
136 reduce_charges(destroy_ptr->o_ptr, destroy_ptr->amt);
137 vary_item(creature_ptr, destroy_ptr->item, -destroy_ptr->amt);
138 if (item_tester_high_level_book(destroy_ptr->q_ptr)) {
139 bool gain_expr = FALSE;
140 if (creature_ptr->prace == RACE_ANDROID) {
141 } else if ((creature_ptr->pclass == CLASS_WARRIOR) || (creature_ptr->pclass == CLASS_BERSERKER)) {
143 } else if (creature_ptr->pclass == CLASS_PALADIN) {
144 if (is_good_realm(creature_ptr->realm1)) {
145 if (!is_good_realm(tval2realm(destroy_ptr->q_ptr->tval)))
148 if (is_good_realm(tval2realm(destroy_ptr->q_ptr->tval)))
153 if (gain_expr && (creature_ptr->exp < PY_MAX_EXP)) {
154 s32b tester_exp = creature_ptr->max_exp / 20;
155 if (tester_exp > 10000)
158 if (destroy_ptr->q_ptr->sval < 3)
164 msg_print(_("
\8dX
\82É
\8co
\8c±
\82ð
\90Ï
\82ñ
\82¾
\82æ
\82¤
\82È
\8bC
\82ª
\82·
\82é
\81B", "You feel more experienced."));
165 gain_exp(creature_ptr, tester_exp * destroy_ptr->amt);
168 if (item_tester_high_level_book(destroy_ptr->q_ptr) && destroy_ptr->q_ptr->tval == TV_LIFE_BOOK) {
169 chg_virtue(creature_ptr, V_UNLIFE, 1);
170 chg_virtue(creature_ptr, V_VITALITY, -1);
171 } else if (item_tester_high_level_book(destroy_ptr->q_ptr) && destroy_ptr->q_ptr->tval == TV_DEATH_BOOK) {
172 chg_virtue(creature_ptr, V_UNLIFE, -1);
173 chg_virtue(creature_ptr, V_VITALITY, 1);
176 if ((destroy_ptr->q_ptr->to_a != 0) || (destroy_ptr->q_ptr->to_h != 0) || (destroy_ptr->q_ptr->to_d != 0))
177 chg_virtue(creature_ptr, V_ENCHANT, -1);
179 if (object_value_real(creature_ptr, destroy_ptr->q_ptr) > 30000)
180 chg_virtue(creature_ptr, V_SACRIFICE, 2);
181 else if (object_value_real(creature_ptr, destroy_ptr->q_ptr) > 10000)
182 chg_virtue(creature_ptr, V_SACRIFICE, 1);
185 if ((destroy_ptr->q_ptr->to_a != 0) || (destroy_ptr->q_ptr->to_d != 0) || (destroy_ptr->q_ptr->to_h != 0))
186 chg_virtue(creature_ptr, V_HARMONY, 1);
188 if (destroy_ptr->item >= INVEN_RARM)
189 calc_android_exp(creature_ptr);