OSDN Git Service

66defa9aa5b2854f14404521770db6087699dfaf
[hengbandforosx/hengbandosx.git] / src / monster-attack / monster-eating.cpp
1 /*!
2  * @brief プレーヤーのHP/MP、アイテム、お金・明かりの残りターン、充填魔力を盗んだり減少させたりする処理
3  * @date 2020/05/31
4  * @author Hourier
5  */
6
7 #include "monster-attack/monster-eating.h"
8 #include "avatar/avatar.h"
9 #include "core/player-redraw-types.h"
10 #include "core/player-update-types.h"
11 #include "core/window-redrawer.h"
12 #include "flavor/flavor-describer.h"
13 #include "flavor/object-flavor-types.h"
14 #include "inventory/inventory-object.h"
15 #include "inventory/inventory-slot-types.h"
16 #include "mind/mind-mirror-master.h"
17 #include "monster-attack/monster-attack-util.h"
18 #include "monster/monster-status.h"
19 #include "object-hook/hook-enchant.h"
20 #include "object/object-info.h"
21 #include "object/object-kind.h"
22 #include "object/object-mark-types.h"
23 #include "player/mimic-info-table.h"
24 #include "player/player-status-flags.h"
25 #include "player/player-status-table.h"
26 #include "status/experience.h"
27 #include "system/floor-type-definition.h"
28 #include "system/monster-type-definition.h"
29 #include "system/object-type-definition.h"
30 #include "system/player-type-definition.h"
31 #include "view/display-messages.h"
32 #include "world/world-object.h"
33 #include "player/digestion-processor.h"
34
35 void process_eat_gold(player_type *target_ptr, monap_type *monap_ptr)
36 {
37     if (!target_ptr->paralyzed && (randint0(100) < (adj_dex_safe[target_ptr->stat_index[A_DEX]] + target_ptr->lev))) {
38         msg_print(_("しかし素早く財布を守った!", "You quickly protect your money pouch!"));
39         if (randint0(3))
40             monap_ptr->blinked = true;
41
42         return;
43     }
44
45     PRICE gold = (target_ptr->au / 10) + randint1(25);
46     if (gold < 2)
47         gold = 2;
48
49     if (gold > 5000)
50         gold = (target_ptr->au / 20) + randint1(3000);
51
52     if (gold > target_ptr->au)
53         gold = target_ptr->au;
54
55     target_ptr->au -= gold;
56     if (gold <= 0) {
57         msg_print(_("しかし何も盗まれなかった。", "Nothing was stolen."));
58     } else if (target_ptr->au > 0) {
59         msg_print(_("財布が軽くなった気がする。", "Your purse feels lighter."));
60         msg_format(_("$%ld のお金が盗まれた!", "%ld coins were stolen!"), (long)gold);
61         chg_virtue(target_ptr, V_SACRIFICE, 1);
62     } else {
63         msg_print(_("財布が軽くなった気がする。", "Your purse feels lighter."));
64         msg_print(_("お金が全部盗まれた!", "All of your coins were stolen!"));
65         chg_virtue(target_ptr, V_SACRIFICE, 2);
66     }
67
68     target_ptr->redraw |= (PR_GOLD);
69     target_ptr->window_flags |= (PW_PLAYER);
70     monap_ptr->blinked = true;
71 }
72
73 /*!
74  * @brief 盗み打撃の時にアイテムが盗まれるかどうかを判定する
75  * @param target_ptr プレーヤーへの参照ポインタ
76  * @monap_ptr モンスターからモンスターへの直接攻撃構造体への参照ポインタ
77  * @return 盗まれたらTRUE、何も盗まれなかったらFALSE
78  */
79 bool check_eat_item(player_type *target_ptr, monap_type *monap_ptr)
80 {
81     if (monster_confused_remaining(monap_ptr->m_ptr))
82         return false;
83
84     if (target_ptr->is_dead || check_multishadow(target_ptr))
85         return false;
86
87     if (!target_ptr->paralyzed && (randint0(100) < (adj_dex_safe[target_ptr->stat_index[A_DEX]] + target_ptr->lev))) {
88         msg_print(_("しかしあわててザックを取り返した!", "You grab hold of your backpack!"));
89         monap_ptr->blinked = true;
90         monap_ptr->obvious = true;
91         return false;
92     }
93
94     return true;
95 }
96
97 /*!
98  * @brief プレーヤーが持っているアイテムをモンスターに移す
99  * @param target_ptr プレーヤーへの参照ポインタ
100  * @monap_ptr モンスターからモンスターへの直接攻撃構造体への参照ポインタ
101  */
102 static void move_item_to_monster(player_type *target_ptr, monap_type *monap_ptr, const OBJECT_IDX o_idx)
103 {
104     if (o_idx == 0)
105         return;
106
107     object_type *j_ptr;
108     j_ptr = &target_ptr->current_floor_ptr->o_list[o_idx];
109     j_ptr->copy_from(monap_ptr->o_ptr);
110     j_ptr->number = 1;
111     if ((monap_ptr->o_ptr->tval == TV_ROD) || (monap_ptr->o_ptr->tval == TV_WAND)) {
112         j_ptr->pval = monap_ptr->o_ptr->pval / monap_ptr->o_ptr->number;
113         monap_ptr->o_ptr->pval -= j_ptr->pval;
114     }
115
116     j_ptr->marked = OM_TOUCHED;
117     j_ptr->held_m_idx = monap_ptr->m_idx;
118     monap_ptr->m_ptr->hold_o_idx_list.add(target_ptr->current_floor_ptr, o_idx);
119 }
120
121 /*!
122  * @brief アイテム盗み処理
123  * @param target_ptr プレーヤーへの参照ポインタ
124  * @monap_ptr モンスターからモンスターへの直接攻撃構造体への参照ポインタ
125  * @details eatとあるがお金や食べ物と違ってなくならない、盗んだモンスターを倒せば取り戻せる
126  */
127 void process_eat_item(player_type *target_ptr, monap_type *monap_ptr)
128 {
129     for (int i = 0; i < 10; i++) {
130         OBJECT_IDX o_idx;
131         INVENTORY_IDX i_idx = (INVENTORY_IDX)randint0(INVEN_PACK);
132         monap_ptr->o_ptr = &target_ptr->inventory_list[i_idx];
133         if (!monap_ptr->o_ptr->k_idx)
134             continue;
135
136         if (object_is_artifact(monap_ptr->o_ptr))
137             continue;
138
139         describe_flavor(target_ptr, monap_ptr->o_name, monap_ptr->o_ptr, OD_OMIT_PREFIX);
140 #ifdef JP
141         msg_format("%s(%c)を%s盗まれた!", monap_ptr->o_name, index_to_label(i_idx), ((monap_ptr->o_ptr->number > 1) ? "一つ" : ""));
142 #else
143         msg_format("%sour %s (%c) was stolen!", ((monap_ptr->o_ptr->number > 1) ? "One of y" : "Y"), monap_ptr->o_name, index_to_label(i_idx));
144 #endif
145         chg_virtue(target_ptr, V_SACRIFICE, 1);
146         o_idx = o_pop(target_ptr->current_floor_ptr);
147         move_item_to_monster(target_ptr, monap_ptr, o_idx);
148         inven_item_increase(target_ptr, i_idx, -1);
149         inven_item_optimize(target_ptr, i_idx);
150         monap_ptr->obvious = true;
151         monap_ptr->blinked = true;
152         break;
153     }
154 }
155
156 void process_eat_food(player_type *target_ptr, monap_type *monap_ptr)
157 {
158     for (int i = 0; i < 10; i++) {
159         INVENTORY_IDX i_idx = (INVENTORY_IDX)randint0(INVEN_PACK);
160         monap_ptr->o_ptr = &target_ptr->inventory_list[i_idx];
161         if (!monap_ptr->o_ptr->k_idx)
162             continue;
163
164         if ((monap_ptr->o_ptr->tval != TV_FOOD) && !((monap_ptr->o_ptr->tval == TV_CORPSE) && (monap_ptr->o_ptr->sval)))
165             continue;
166
167         describe_flavor(target_ptr, monap_ptr->o_name, monap_ptr->o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
168 #ifdef JP
169         msg_format("%s(%c)を%s食べられてしまった!", monap_ptr->o_name, index_to_label(i_idx), ((monap_ptr->o_ptr->number > 1) ? "一つ" : ""));
170 #else
171         msg_format("%sour %s (%c) was eaten!", ((monap_ptr->o_ptr->number > 1) ? "One of y" : "Y"), monap_ptr->o_name, index_to_label(i_idx));
172 #endif
173         inven_item_increase(target_ptr, i_idx, -1);
174         inven_item_optimize(target_ptr, i_idx);
175         monap_ptr->obvious = true;
176         break;
177     }
178 }
179
180 void process_eat_lite(player_type *target_ptr, monap_type *monap_ptr)
181 {
182     if ((monap_ptr->o_ptr->xtra4 <= 0) || object_is_fixed_artifact(monap_ptr->o_ptr))
183         return;
184
185     monap_ptr->o_ptr->xtra4 -= (s16b)(250 + randint1(250));
186     if (monap_ptr->o_ptr->xtra4 < 1)
187         monap_ptr->o_ptr->xtra4 = 1;
188
189     if (!target_ptr->blind) {
190         msg_print(_("明かりが暗くなってしまった。", "Your light dims."));
191         monap_ptr->obvious = true;
192     }
193
194     target_ptr->window_flags |= (PW_EQUIP);
195 }
196
197 /*!
198  * @brief モンスターからの攻撃による充填魔力吸収処理
199  * @param target_ptr プレーヤーへの参照ポインタ
200  * @monap_ptr モンスターからモンスターへの直接攻撃構造体への参照ポインタ
201  * @return 吸収されたらTRUE、されなかったらFALSE
202  * @details 魔道具使用能力向上フラグがあれば、吸収量は全部ではない
203  * 詳細はOSDN #40911の議論を参照のこと
204  */
205 bool process_un_power(player_type *target_ptr, monap_type *monap_ptr)
206 {
207     if (((monap_ptr->o_ptr->tval != TV_STAFF) && (monap_ptr->o_ptr->tval != TV_WAND)) || (monap_ptr->o_ptr->pval == 0))
208         return false;
209
210     bool is_magic_mastery = has_magic_mastery(target_ptr) != 0;
211     object_kind *kind_ptr = &k_info[monap_ptr->o_ptr->k_idx];
212     PARAMETER_VALUE pval = kind_ptr->pval;
213     DEPTH level = monap_ptr->rlev;
214     HIT_POINT drain = is_magic_mastery ? MIN(pval, pval * level / 400 + pval * randint1(level) / 400) : pval;
215     if (drain <= 0)
216         return false;
217
218     msg_print(_("ザックからエネルギーが吸い取られた!", "Energy was drained from your pack!"));
219     if (is_magic_mastery)
220         msg_print(_("しかし、あなたの魔法を操る力がその一部を取り返した!", "However, your skill of magic mastery got back the part of energy!"));
221
222     monap_ptr->obvious = true;
223     HIT_POINT recovery = drain * kind_ptr->level;
224
225     if (monap_ptr->o_ptr->tval == TV_STAFF)
226         recovery *= monap_ptr->o_ptr->number;
227
228     recovery = MIN(recovery, monap_ptr->m_ptr->maxhp - monap_ptr->m_ptr->hp);
229     monap_ptr->m_ptr->hp += recovery;
230
231     if (target_ptr->health_who == monap_ptr->m_idx)
232         target_ptr->redraw |= PR_HEALTH;
233
234     if (target_ptr->riding == monap_ptr->m_idx)
235         target_ptr->redraw |= PR_UHEALTH;
236
237     monap_ptr->o_ptr->pval = !is_magic_mastery || (monap_ptr->o_ptr->pval == 1) ? 0 : monap_ptr->o_ptr->pval - drain;
238     target_ptr->update |= PU_COMBINE | PU_REORDER;
239     target_ptr->window_flags |= PW_INVEN;
240     return true;
241 }
242
243 bool check_drain_hp(player_type *target_ptr, const s32b d)
244 {
245     bool resist_drain = !drain_exp(target_ptr, d, d / 10, 50);
246     if (target_ptr->mimic_form)
247         return (mimic_info[target_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING) != 0 ? true : resist_drain;
248
249     switch (target_ptr->prace) {
250     case RACE_ZOMBIE:
251     case RACE_VAMPIRE:
252     case RACE_SPECTRE:
253     case RACE_SKELETON:
254     case RACE_BALROG:
255     case RACE_GOLEM:
256     case RACE_ANDROID:
257         return true;
258     default:
259         return resist_drain;
260     }
261 }
262
263 void process_drain_life(player_type *target_ptr, monap_type *monap_ptr, const bool resist_drain)
264 {
265     if ((monap_ptr->damage <= 5) || resist_drain)
266         return;
267
268     bool did_heal = monap_ptr->m_ptr->hp < monap_ptr->m_ptr->maxhp;
269     monap_ptr->m_ptr->hp += damroll(4, monap_ptr->damage / 6);
270     if (monap_ptr->m_ptr->hp > monap_ptr->m_ptr->maxhp)
271         monap_ptr->m_ptr->hp = monap_ptr->m_ptr->maxhp;
272
273     if (target_ptr->health_who == monap_ptr->m_idx)
274         target_ptr->redraw |= (PR_HEALTH);
275
276     if (target_ptr->riding == monap_ptr->m_idx)
277         target_ptr->redraw |= (PR_UHEALTH);
278
279     if (monap_ptr->m_ptr->ml && did_heal)
280         msg_format(_("%sは体力を回復したようだ。", "%^s appears healthier."), monap_ptr->m_name);
281 }
282
283 void process_drain_mana(player_type *target_ptr, monap_type *monap_ptr)
284 {
285     if (check_multishadow(target_ptr)) {
286         msg_print(_("攻撃は幻影に命中し、あなたには届かなかった。", "The attack hits Shadow, but you are unharmed!"));
287         return;
288     }
289
290     monap_ptr->do_cut = 0;
291     target_ptr->csp -= monap_ptr->damage;
292     if (target_ptr->csp < 0) {
293         target_ptr->csp = 0;
294         target_ptr->csp_frac = 0;
295     }
296
297     target_ptr->redraw |= (PR_MANA);
298 }
299
300 /*!
301  * @brief モンスターからの空腹進行処理
302  * @param target_ptr プレーヤーへの参照ポインタ
303  * @monap_ptr モンスターからモンスターへの直接攻撃構造体への参照ポインタ
304  * @details 空腹、衰弱の一歩手前で止める優しさは残す。
305  */
306 void process_monster_attack_hungry(player_type *target_ptr, monap_type *monap_ptr)
307 {
308 #ifdef JP
309     msg_format("あなたは腹が減った!");
310 #else
311     msg_format("You feel hungry!");
312 #endif
313     FEED subtracted_food = target_ptr->food - monap_ptr->damage;
314     if (target_ptr->food > PY_FOOD_ALERT && PY_FOOD_ALERT >= subtracted_food)
315         set_food(target_ptr, PY_FOOD_ALERT);
316     else if (target_ptr->food > PY_FOOD_FAINT && PY_FOOD_FAINT >= subtracted_food)
317         set_food(target_ptr, PY_FOOD_FAINT);
318     else
319         set_food(target_ptr, subtracted_food);
320 }