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-info/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, _("本当に%sを壊しますか? [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 = _("どのアイテムを壊しますか? ", "Destroy which item? ");
88 concptr s = _("壊せるアイテムを持っていない。", "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 一部職業で高位魔法書の破壊による経験値上昇の判定
105 * @param creature_ptr プレーヤーへの参照ポインタ
106 * @param destory_ptr アイテム破壊構造体への参照ポインタ
107 * return 魔法書の破壊によって経験値が入るならばTRUE
109 static bool decide_magic_book_exp(player_type *creature_ptr, destroy_type *destroy_ptr)
111 if (creature_ptr->prace == RACE_ANDROID)
114 if ((creature_ptr->pclass == CLASS_WARRIOR) || (creature_ptr->pclass == CLASS_BERSERKER))
117 if (creature_ptr->pclass != CLASS_PALADIN)
120 bool gain_expr = FALSE;
121 if (is_good_realm(creature_ptr->realm1)) {
122 if (!is_good_realm(tval2realm(destroy_ptr->q_ptr->tval)))
125 if (is_good_realm(tval2realm(destroy_ptr->q_ptr->tval)))
132 static void gain_exp_by_destroying_magic_book(player_type *creature_ptr, destroy_type *destroy_ptr)
134 bool gain_expr = decide_magic_book_exp(creature_ptr, destroy_ptr);
135 if (!gain_expr || (creature_ptr->exp >= PY_MAX_EXP))
138 s32b tester_exp = creature_ptr->max_exp / 20;
139 if (tester_exp > 10000)
142 if (destroy_ptr->q_ptr->sval < 3)
148 msg_print(_("更に経験を積んだような気がする。", "You feel more experienced."));
149 gain_exp(creature_ptr, tester_exp * destroy_ptr->amt);
152 static void process_destroy_magic_book(player_type *creature_ptr, destroy_type *destroy_ptr)
154 if (!item_tester_high_level_book(destroy_ptr->q_ptr))
157 gain_exp_by_destroying_magic_book(creature_ptr, destroy_ptr);
158 if (item_tester_high_level_book(destroy_ptr->q_ptr) && destroy_ptr->q_ptr->tval == TV_LIFE_BOOK) {
159 chg_virtue(creature_ptr, V_UNLIFE, 1);
160 chg_virtue(creature_ptr, V_VITALITY, -1);
161 } else if (item_tester_high_level_book(destroy_ptr->q_ptr) && destroy_ptr->q_ptr->tval == TV_DEATH_BOOK) {
162 chg_virtue(creature_ptr, V_UNLIFE, -1);
163 chg_virtue(creature_ptr, V_VITALITY, 1);
166 if ((destroy_ptr->q_ptr->to_a != 0) || (destroy_ptr->q_ptr->to_h != 0) || (destroy_ptr->q_ptr->to_d != 0))
167 chg_virtue(creature_ptr, V_ENCHANT, -1);
169 if (object_value_real(creature_ptr, destroy_ptr->q_ptr) > 30000)
170 chg_virtue(creature_ptr, V_SACRIFICE, 2);
171 else if (object_value_real(creature_ptr, destroy_ptr->q_ptr) > 10000)
172 chg_virtue(creature_ptr, V_SACRIFICE, 1);
175 static void exe_destroy_item(player_type *creature_ptr, destroy_type *destroy_ptr)
177 object_copy(destroy_ptr->q_ptr, destroy_ptr->o_ptr);
178 msg_format(_("%sを壊した。", "You destroy %s."), destroy_ptr->o_name);
179 sound(SOUND_DESTITEM);
180 reduce_charges(destroy_ptr->o_ptr, destroy_ptr->amt);
181 vary_item(creature_ptr, destroy_ptr->item, -destroy_ptr->amt);
182 process_destroy_magic_book(creature_ptr, destroy_ptr);
183 if ((destroy_ptr->q_ptr->to_a != 0) || (destroy_ptr->q_ptr->to_d != 0) || (destroy_ptr->q_ptr->to_h != 0))
184 chg_virtue(creature_ptr, V_HARMONY, 1);
186 if (destroy_ptr->item >= INVEN_RARM)
187 calc_android_exp(creature_ptr);
191 * @brief アイテムを破壊するコマンドのメインルーチン / Destroy an item
192 * @param creature_ptr プレーヤーへの参照ポインタ
195 void do_cmd_destroy(player_type *creature_ptr)
197 if (creature_ptr->special_defense & KATA_MUSOU)
198 set_action(creature_ptr, ACTION_NONE);
201 destroy_type tmp_destroy;
202 destroy_type *destroy_ptr = initialize_destroy_type(&tmp_destroy, &forge);
204 destroy_ptr->force = TRUE;
206 if (!select_destroying_item(creature_ptr, destroy_ptr))
209 destroy_ptr->old_number = destroy_ptr->o_ptr->number;
210 destroy_ptr->o_ptr->number = destroy_ptr->amt;
211 describe_flavor(creature_ptr, destroy_ptr->o_name, destroy_ptr->o_ptr, 0);
212 destroy_ptr->o_ptr->number = destroy_ptr->old_number;
213 take_turn(creature_ptr, 100);
214 if (!can_player_destroy_object(creature_ptr, destroy_ptr->o_ptr)) {
215 free_turn(creature_ptr);
216 msg_format(_("%sは破壊不可能だ。", "You cannot destroy %s."), destroy_ptr->o_name);
220 exe_destroy_item(creature_ptr, destroy_ptr);