OSDN Git Service

Merge remote-tracking branch 'remotes/origin/feature/Fix-saved-floor-exceed' into...
[hengband/hengband.git] / src / inventory / inventory-damage.c
1 #include "inventory/inventory-damage.h"
2 #include "flavor/flavor-describer.h"
3 #include "flavor/object-flavor-types.h"
4 #include "inventory/inventory-object.h"
5 #include "inventory/inventory-slot-types.h"
6 #include "mind/mind-mirror-master.h"
7 #include "object-hook/hook-enchant.h"
8 #include "object-hook/hook-expendable.h"
9 #include "object/object-broken.h"
10 #include "object/object-info.h"
11 #include "object/object-stack.h"
12 #include "system/floor-type-definition.h"
13 #include "view/display-messages.h"
14
15 /*!
16  * @brief アイテムを指定確率で破損させる /
17  * Destroys a type of item on a given percent chance
18  * @param player_ptr プレーヤーへの参照ポインタ
19  * @param typ 破損判定関数ポインタ
20  * @param perc 基本確率
21  * @return なし
22  * @details
23  * Note that missiles are no longer necessarily all destroyed
24  * Destruction taken from "melee.c" code for "stealing".
25  * New-style wands and rods handled correctly. -LM-
26  */
27 void inventory_damage(player_type *player_ptr, inven_func typ, int perc)
28 {
29     INVENTORY_IDX i;
30     int j, amt;
31     object_type *o_ptr;
32     GAME_TEXT o_name[MAX_NLEN];
33
34     if (check_multishadow(player_ptr) || player_ptr->current_floor_ptr->inside_arena)
35         return;
36
37     /* Scan through the slots backwards */
38     for (i = 0; i < INVEN_PACK; i++) {
39         o_ptr = &player_ptr->inventory_list[i];
40         if (!o_ptr->k_idx)
41             continue;
42
43         /* Hack -- for now, skip artifacts */
44         if (object_is_artifact(o_ptr))
45             continue;
46
47         /* Give this item slot a shot at death */
48         if (!(*typ)(player_ptr, o_ptr))
49             continue;
50
51         /* Count the casualties */
52         for (amt = j = 0; j < o_ptr->number; ++j) {
53             if (randint0(100) < perc)
54                 amt++;
55         }
56
57         /* Some casualities */
58         if (!amt)
59             continue;
60
61         describe_flavor(player_ptr, o_name, o_ptr, OD_OMIT_PREFIX);
62
63         msg_format(_("%s(%c)が%s壊れてしまった!", "%sour %s (%c) %s destroyed!"),
64 #ifdef JP
65             o_name, index_to_label(i), ((o_ptr->number > 1) ? ((amt == o_ptr->number) ? "全部" : (amt > 1 ? "何個か" : "一個")) : ""));
66 #else
67             ((o_ptr->number > 1) ? ((amt == o_ptr->number) ? "All of y" : (amt > 1 ? "Some of y" : "One of y")) : "Y"), o_name, index_to_label(i),
68             ((amt > 1) ? "were" : "was"));
69 #endif
70
71 #ifdef JP
72         if (is_echizen(player_ptr))
73             msg_print("やりやがったな!");
74         else if (player_ptr->pseikaku == PERSONALITY_CHARGEMAN) {
75             if (randint0(2) == 0)
76                 msg_print(_("ジュラル星人め!", ""));
77             else
78                 msg_print(_("弱い者いじめは止めるんだ!", ""));
79         }
80 #endif
81
82         /* Potions smash open */
83         if (object_is_potion(o_ptr)) {
84             (void)potion_smash_effect(player_ptr, 0, player_ptr->y, player_ptr->x, o_ptr->k_idx);
85         }
86
87         /* Reduce the charges of rods/wands */
88         reduce_charges(o_ptr, amt);
89
90         /* Destroy "amt" items */
91         inven_item_increase(player_ptr, i, -amt);
92         inven_item_optimize(player_ptr, i);
93     }
94 }