2 * @brief プレイヤーの食べるコマンド実装
7 #include "cmd-item/cmd-eat.h"
8 #include "avatar/avatar.h"
9 #include "core/player-update-types.h"
10 #include "core/window-redrawer.h"
11 #include "flavor/flavor-describer.h"
12 #include "flavor/object-flavor-types.h"
13 #include "floor/floor-object.h"
14 #include "hpmp/hp-mp-processor.h"
15 #include "inventory/inventory-object.h"
16 #include "main/sound-definitions-table.h"
17 #include "main/sound-of-music.h"
18 #include "monster-race/monster-race.h"
19 #include "object-enchant/special-object-flags.h"
20 #include "object-hook/hook-expendable.h"
21 #include "object/item-tester-hooker.h"
22 #include "object/item-use-flags.h"
23 #include "object/object-info.h"
24 #include "object/object-kind-hook.h"
25 #include "object/object-kind.h"
26 #include "perception/object-perception.h"
27 #include "player-base/player-class.h"
28 #include "player-base/player-race.h"
29 #include "player-info/class-info.h"
30 #include "player-info/mimic-info-table.h"
31 #include "player-info/samurai-data-type.h"
32 #include "player-status/player-energy.h"
33 #include "player/attack-defense-types.h"
34 #include "player/digestion-processor.h"
35 #include "player/player-damage.h"
36 #include "player/player-status-flags.h"
37 #include "player/special-defense-types.h"
38 #include "spell-realm/spells-hex.h"
39 #include "spell-realm/spells-song.h"
40 #include "spell/spells-status.h"
41 #include "status/action-setter.h"
42 #include "status/bad-status-setter.h"
43 #include "status/base-status.h"
44 #include "status/element-resistance.h"
45 #include "status/experience.h"
46 #include "sv-definition/sv-food-types.h"
47 #include "sv-definition/sv-other-types.h"
48 #include "system/monster-race-definition.h"
49 #include "system/object-type-definition.h"
50 #include "system/player-type-definition.h"
51 #include "util/string-processor.h"
52 #include "view/display-messages.h"
53 #include "view/object-describer.h"
56 * @brief 食料タイプの食料を食べたときの効果を発動
57 * @param player_ptr プレイヤー情報への参照ポインタ
58 * @param o_ptr 食べるオブジェクト
59 * @return 鑑定されるならTRUE、されないならFALSE
61 bool exe_eat_food_type_object(PlayerType *player_ptr, ObjectType *o_ptr)
63 if (o_ptr->tval != ItemKindType::FOOD) {
67 BadStatusSetter bss(player_ptr);
68 switch (o_ptr->sval) {
70 return (!(has_resist_pois(player_ptr) || is_oppose_pois(player_ptr))) && bss.mod_poison(randint0(10) + 10);
71 case SV_FOOD_BLINDNESS:
72 return !has_resist_blind(player_ptr) && bss.mod_blindness(randint0(200) + 200);
73 case SV_FOOD_PARANOIA:
74 return !has_resist_fear(player_ptr) && bss.mod_fear(randint0(10) + 10);
75 case SV_FOOD_CONFUSION:
76 return !has_resist_conf(player_ptr) && bss.mod_confusion(randint0(10) + 10);
77 case SV_FOOD_HALLUCINATION:
78 return !has_resist_chaos(player_ptr) && bss.mod_hallucination(randint0(250) + 250);
79 case SV_FOOD_PARALYSIS:
80 return !player_ptr->free_act && bss.mod_paralysis(randint0(10) + 10);
81 case SV_FOOD_WEAKNESS:
82 take_hit(player_ptr, DAMAGE_NOESCAPE, damroll(6, 6), _("毒入り食料", "poisonous food"));
83 (void)do_dec_stat(player_ptr, A_STR);
85 case SV_FOOD_SICKNESS:
86 take_hit(player_ptr, DAMAGE_NOESCAPE, damroll(6, 6), _("毒入り食料", "poisonous food"));
87 (void)do_dec_stat(player_ptr, A_CON);
89 case SV_FOOD_STUPIDITY:
90 take_hit(player_ptr, DAMAGE_NOESCAPE, damroll(8, 8), _("毒入り食料", "poisonous food"));
91 (void)do_dec_stat(player_ptr, A_INT);
94 take_hit(player_ptr, DAMAGE_NOESCAPE, damroll(8, 8), _("毒入り食料", "poisonous food"));
95 (void)do_dec_stat(player_ptr, A_WIS);
97 case SV_FOOD_UNHEALTH:
98 take_hit(player_ptr, DAMAGE_NOESCAPE, damroll(10, 10), _("毒入り食料", "poisonous food"));
99 (void)do_dec_stat(player_ptr, A_CON);
101 case SV_FOOD_DISEASE:
102 take_hit(player_ptr, DAMAGE_NOESCAPE, damroll(10, 10), _("毒入り食料", "poisonous food"));
103 (void)do_dec_stat(player_ptr, A_STR);
105 case SV_FOOD_CURE_POISON:
106 return bss.poison(0);
107 case SV_FOOD_CURE_BLINDNESS:
108 return bss.blindness(0);
109 case SV_FOOD_CURE_PARANOIA:
111 case SV_FOOD_CURE_CONFUSION:
112 return bss.confusion(0);
113 case SV_FOOD_CURE_SERIOUS:
114 return cure_serious_wounds(player_ptr, 4, 8);
115 case SV_FOOD_RESTORE_STR:
116 return do_res_stat(player_ptr, A_STR);
117 case SV_FOOD_RESTORE_CON:
118 return do_res_stat(player_ptr, A_CON);
119 case SV_FOOD_RESTORING:
120 return restore_all_status(player_ptr);
121 case SV_FOOD_BISCUIT:
122 msg_print(_("甘くてサクサクしてとてもおいしい。", "That is sweet, crispy, and very delicious."));
125 msg_print(_("歯ごたえがあっておいしい。", "That is chewy and delicious."));
127 case SV_FOOD_SLIME_MOLD:
128 msg_print(_("これはなんとも形容しがたい味だ。", "That is an indescribable taste."));
131 msg_print(_("これはおいしい。", "That tastes good."));
133 case SV_FOOD_WAYBREAD:
134 msg_print(_("これはひじょうに美味だ。", "That tastes very good."));
136 (void)hp_player(player_ptr, damroll(4, 8));
138 case SV_FOOD_PINT_OF_ALE:
139 case SV_FOOD_PINT_OF_WINE:
140 msg_print(_("のどごし爽やかだ。", "That is refreshing and warms the innards."));
148 * @brief 魔法道具のチャージをの食料として食べたときの効果を発動
149 * @param player_ptr プレイヤー情報への参照ポインタ
150 * @param o_ptr 食べるオブジェクト
151 * @param item オブジェクトのインベントリ番号
152 * @return 食べようとしたらTRUE、しなかったらFALSE
154 bool exe_eat_charge_of_magic_device(PlayerType *player_ptr, ObjectType *o_ptr, INVENTORY_IDX item)
156 if (o_ptr->tval != ItemKindType::STAFF && o_ptr->tval != ItemKindType::WAND) {
160 if (PlayerRace(player_ptr).food() == PlayerRaceFoodType::MANA) {
163 if (o_ptr->tval == ItemKindType::STAFF && (item < 0) && (o_ptr->number > 1)) {
164 msg_print(_("まずは杖を拾わなければ。", "You must first pick up the staffs."));
168 staff = (o_ptr->tval == ItemKindType::STAFF) ? _("杖", "staff") : _("魔法棒", "wand");
171 if (o_ptr->pval == 0) {
172 msg_format(_("この%sにはもう魔力が残っていない。", "The %s has no charges left."), staff);
173 o_ptr->ident |= (IDENT_EMPTY);
174 player_ptr->window_flags |= (PW_INVEN);
178 msg_format(_("あなたは%sの魔力をエネルギー源として吸収した。", "You absorb mana of the %s as your energy."), staff);
180 /* Use a single charge */
184 set_food(player_ptr, player_ptr->food + 5000);
186 /* XXX Hack -- unstack if necessary */
187 if (o_ptr->tval == ItemKindType::STAFF && (item >= 0) && (o_ptr->number > 1)) {
191 q_ptr->copy_from(o_ptr);
193 /* Modify quantity */
196 /* Restore the charges */
199 /* Unstack the used item */
201 item = store_item_to_inventory(player_ptr, q_ptr);
203 msg_format(_("杖をまとめなおした。", "You unstack your staff."));
207 inven_item_charges(player_ptr, item);
209 floor_item_charges(player_ptr->current_floor_ptr, 0 - item);
212 player_ptr->window_flags |= (PW_INVEN | PW_EQUIP);
220 * @brief 食料を食べるコマンドのサブルーチン
221 * @param item 食べるオブジェクトの所持品ID
223 void exe_eat_food(PlayerType *player_ptr, INVENTORY_IDX item)
225 if (music_singing_any(player_ptr)) {
226 stop_singing(player_ptr);
229 SpellHex spell_hex(player_ptr);
230 if (spell_hex.is_spelling_any()) {
231 (void)spell_hex.stop_all_spells();
234 auto *o_ptr = ref_item(player_ptr, item);
238 PlayerEnergy(player_ptr).set_player_turn_energy(100);
241 int lev = k_info[o_ptr->k_idx].level;
243 /* Identity not known yet */
244 int ident = exe_eat_food_type_object(player_ptr, o_ptr);
247 * Store what may have to be updated for the inventory (including
248 * autodestroy if set by something else). Then turn off those flags
249 * so that updates triggered by calling gain_exp() or set_food() below
250 * do not rearrange the inventory before the food item is destroyed in
253 BIT_FLAGS inventory_flags = (PU_COMBINE | PU_REORDER | (player_ptr->update & PU_AUTODESTROY));
254 player_ptr->update &= ~(PU_COMBINE | PU_REORDER | PU_AUTODESTROY);
256 if (!(o_ptr->is_aware())) {
257 chg_virtue(player_ptr, V_KNOWLEDGE, -1);
258 chg_virtue(player_ptr, V_PATIENCE, -1);
259 chg_virtue(player_ptr, V_CHANCE, 1);
262 /* We have tried it */
263 if (o_ptr->tval == ItemKindType::FOOD) {
267 /* The player is now aware of the object */
268 if (ident && !o_ptr->is_aware()) {
269 object_aware(player_ptr, o_ptr);
270 gain_exp(player_ptr, (lev + (player_ptr->lev >> 1)) / player_ptr->lev);
273 player_ptr->window_flags |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
275 /* Undeads drain recharge of magic device */
276 if (exe_eat_charge_of_magic_device(player_ptr, o_ptr, item)) {
277 player_ptr->update |= inventory_flags;
281 auto food_type = PlayerRace(player_ptr).food();
283 /* Balrogs change humanoid corpses to energy */
284 const auto corpse_r_idx = i2enum<MonsterRaceId>(o_ptr->pval);
285 if (food_type == PlayerRaceFoodType::CORPSE && (o_ptr->tval == ItemKindType::CORPSE && o_ptr->sval == SV_CORPSE && angband_strchr("pht", r_info[corpse_r_idx].d_char))) {
286 GAME_TEXT o_name[MAX_NLEN];
287 describe_flavor(player_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
288 msg_format(_("%sは燃え上り灰になった。精力を吸収した気がする。", "%^s is burnt to ashes. You absorb its vitality!"), o_name);
289 (void)set_food(player_ptr, PY_FOOD_MAX - 1);
291 player_ptr->update |= inventory_flags;
292 vary_item(player_ptr, item, -1);
296 if (PlayerRace(player_ptr).equals(PlayerRaceType::SKELETON)) {
297 if (!((o_ptr->sval == SV_FOOD_WAYBREAD) || (o_ptr->sval < SV_FOOD_BISCUIT))) {
299 auto *q_ptr = &forge;
301 msg_print(_("食べ物がアゴを素通りして落ちた!", "The food falls through your jaws!"));
302 q_ptr->prep(lookup_kind(o_ptr->tval, o_ptr->sval));
304 /* Drop the object from heaven */
305 (void)drop_near(player_ptr, q_ptr, -1, player_ptr->y, player_ptr->x);
307 msg_print(_("食べ物がアゴを素通りして落ち、消えた!", "The food falls through your jaws and vanishes!"));
309 } else if (food_type == PlayerRaceFoodType::BLOOD) {
310 /* Vampires are filled only by bloods, so reduced nutritional benefit */
311 (void)set_food(player_ptr, player_ptr->food + (o_ptr->pval / 10));
312 msg_print(_("あなたのような者にとって食糧など僅かな栄養にしかならない。", "Mere victuals hold scant sustenance for a being such as yourself."));
314 if (player_ptr->food < PY_FOOD_ALERT) { /* Hungry */
315 msg_print(_("あなたの飢えは新鮮な血によってのみ満たされる!", "Your hunger can only be satisfied with fresh blood!"));
317 } else if (food_type == PlayerRaceFoodType::WATER) {
318 msg_print(_("動物の食物はあなたにとってほとんど栄養にならない。", "The food of animals is poor sustenance for you."));
319 set_food(player_ptr, player_ptr->food + ((o_ptr->pval) / 20));
320 } else if (food_type != PlayerRaceFoodType::RATION) {
321 msg_print(_("生者の食物はあなたにとってほとんど栄養にならない。", "The food of mortals is poor sustenance for you."));
322 set_food(player_ptr, player_ptr->food + ((o_ptr->pval) / 20));
324 if (o_ptr->tval == ItemKindType::FOOD && o_ptr->sval == SV_FOOD_WAYBREAD) {
325 /* Waybread is always fully satisfying. */
326 set_food(player_ptr, std::max<short>(player_ptr->food, PY_FOOD_MAX - 1));
328 /* Food can feed the player */
329 (void)set_food(player_ptr, player_ptr->food + o_ptr->pval);
333 player_ptr->update |= inventory_flags;
334 vary_item(player_ptr, item, -1);
338 * @brief 食料を食べるコマンドのメインルーチン /
339 * Eat some food (from the pack or floor)
341 void do_cmd_eat_food(PlayerType *player_ptr)
346 PlayerClass(player_ptr).break_samurai_stance({ SamuraiStanceType::MUSOU, SamuraiStanceType::KOUKIJIN });
348 q = _("どれを食べますか? ", "Eat which item? ");
349 s = _("食べ物がない。", "You have nothing to eat.");
351 if (!choose_object(player_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), FuncItemTester(item_tester_hook_eatable, player_ptr))) {
355 exe_eat_food(player_ptr, item);