OSDN Git Service

Merge pull request #1712 from Hourier/Make-Quest-Completion-Checker-Class
[hengbandforosx/hengbandosx.git] / src / effect / effect-monster-charm.cpp
1 #include "effect/effect-monster-charm.h"
2 #include "avatar/avatar.h"
3 #include "dungeon/quest.h"
4 #include "effect/effect-monster-util.h"
5 #include "effect/spells-effect-util.h"
6 #include "monster-floor/monster-remover.h"
7 #include "monster-race/monster-race-hook.h"
8 #include "monster-race/monster-race.h"
9 #include "monster-race/race-flags1.h"
10 #include "monster-race/race-flags3.h"
11 #include "monster-race/race-flags7.h"
12 #include "monster-race/race-indice-types.h"
13 #include "monster/monster-flag-types.h"
14 #include "monster/monster-info.h"
15 #include "monster/monster-list.h"
16 #include "monster/monster-status-setter.h"
17 #include "monster/monster-status.h"
18 #include "object-enchant/trc-types.h"
19 #include "pet/pet-fall-off.h"
20 #include "pet/pet-util.h"
21 #include "player/player-status-flags.h"
22 #include "spell/spells-diceroll.h"
23 #include "status/bad-status-setter.h"
24 #include "system/floor-type-definition.h"
25 #include "system/grid-type-definition.h"
26 #include "system/monster-race-definition.h"
27 #include "system/monster-type-definition.h"
28 #include "system/player-type-definition.h"
29 #include "util/bit-flags-calculator.h"
30 #include "view/display-messages.h"
31
32 static void effect_monster_charm_resist(player_type *player_ptr, effect_monster_type *em_ptr)
33 {
34     if (common_saving_throw_charm(player_ptr, em_ptr->dam, em_ptr->m_ptr)) {
35         em_ptr->note = _("には効果がなかった。", " is unaffected.");
36         em_ptr->obvious = false;
37
38         if (one_in_(4))
39             em_ptr->m_ptr->mflag2.set(MFLAG2::NOPET);
40     } else if (has_aggravate(player_ptr)) {
41         em_ptr->note = _("はあなたに敵意を抱いている!", " hates you too much!");
42         if (one_in_(4))
43             em_ptr->m_ptr->mflag2.set(MFLAG2::NOPET);
44     } else {
45         em_ptr->note = _("は突然友好的になったようだ!", " suddenly seems friendly!");
46         set_pet(player_ptr, em_ptr->m_ptr);
47
48         chg_virtue(player_ptr, V_INDIVIDUALISM, -1);
49         if (em_ptr->r_ptr->flags3 & RF3_ANIMAL)
50             chg_virtue(player_ptr, V_NATURE, 1);
51     }
52 }
53
54 process_result effect_monster_charm(player_type *player_ptr, effect_monster_type *em_ptr)
55 {
56     int vir = virtue_number(player_ptr, V_HARMONY);
57     if (vir) {
58         em_ptr->dam += player_ptr->virtues[vir - 1] / 10;
59     }
60
61     vir = virtue_number(player_ptr, V_INDIVIDUALISM);
62     if (vir) {
63         em_ptr->dam -= player_ptr->virtues[vir - 1] / 20;
64     }
65
66     if (em_ptr->seen)
67         em_ptr->obvious = true;
68
69     effect_monster_charm_resist(player_ptr, em_ptr);
70     em_ptr->dam = 0;
71     return PROCESS_CONTINUE;
72 }
73
74 process_result effect_monster_control_undead(player_type *player_ptr, effect_monster_type *em_ptr)
75 {
76     if (em_ptr->seen)
77         em_ptr->obvious = true;
78
79     int vir = virtue_number(player_ptr, V_UNLIFE);
80     if (vir) {
81         em_ptr->dam += player_ptr->virtues[vir - 1] / 10;
82     }
83
84     vir = virtue_number(player_ptr, V_INDIVIDUALISM);
85     if (vir) {
86         em_ptr->dam -= player_ptr->virtues[vir - 1] / 20;
87     }
88
89     if (common_saving_throw_control(player_ptr, em_ptr->dam, em_ptr->m_ptr) || !(em_ptr->r_ptr->flags3 & RF3_UNDEAD)) {
90         em_ptr->note = _("には効果がなかった。", " is unaffected.");
91         em_ptr->obvious = false;
92         if (one_in_(4))
93             em_ptr->m_ptr->mflag2.set(MFLAG2::NOPET);
94     } else if (has_aggravate(player_ptr)) {
95         em_ptr->note = _("はあなたに敵意を抱いている!", " hates you too much!");
96         if (one_in_(4))
97             em_ptr->m_ptr->mflag2.set(MFLAG2::NOPET);
98     } else {
99         em_ptr->note = _("は既にあなたの奴隷だ!", " is in your thrall!");
100         set_pet(player_ptr, em_ptr->m_ptr);
101     }
102
103     em_ptr->dam = 0;
104     return PROCESS_CONTINUE;
105 }
106
107 process_result effect_monster_control_demon(player_type *player_ptr, effect_monster_type *em_ptr)
108 {
109     if (em_ptr->seen)
110         em_ptr->obvious = true;
111
112     int vir = virtue_number(player_ptr, V_UNLIFE);
113     if (vir) {
114         em_ptr->dam += player_ptr->virtues[vir - 1] / 10;
115     }
116
117     vir = virtue_number(player_ptr, V_INDIVIDUALISM);
118     if (vir) {
119         em_ptr->dam -= player_ptr->virtues[vir - 1] / 20;
120     }
121
122     if (common_saving_throw_control(player_ptr, em_ptr->dam, em_ptr->m_ptr) || !(em_ptr->r_ptr->flags3 & RF3_DEMON)) {
123         em_ptr->note = _("には効果がなかった。", " is unaffected.");
124         em_ptr->obvious = false;
125         if (one_in_(4))
126             em_ptr->m_ptr->mflag2.set(MFLAG2::NOPET);
127     } else if (has_aggravate(player_ptr)) {
128         em_ptr->note = _("はあなたに敵意を抱いている!", " hates you too much!");
129         if (one_in_(4))
130             em_ptr->m_ptr->mflag2.set(MFLAG2::NOPET);
131     } else {
132         em_ptr->note = _("は既にあなたの奴隷だ!", " is in your thrall!");
133         set_pet(player_ptr, em_ptr->m_ptr);
134     }
135
136     em_ptr->dam = 0;
137     return PROCESS_CONTINUE;
138 }
139
140 process_result effect_monster_control_animal(player_type *player_ptr, effect_monster_type *em_ptr)
141 {
142     if (em_ptr->seen)
143         em_ptr->obvious = true;
144
145     int vir = virtue_number(player_ptr, V_NATURE);
146     if (vir) {
147         em_ptr->dam += player_ptr->virtues[vir - 1] / 10;
148     }
149
150     vir = virtue_number(player_ptr, V_INDIVIDUALISM);
151     if (vir) {
152         em_ptr->dam -= player_ptr->virtues[vir - 1] / 20;
153     }
154
155     if (common_saving_throw_control(player_ptr, em_ptr->dam, em_ptr->m_ptr) || !(em_ptr->r_ptr->flags3 & RF3_ANIMAL)) {
156         em_ptr->note = _("には効果がなかった。", " is unaffected.");
157         em_ptr->obvious = false;
158         if (one_in_(4))
159             em_ptr->m_ptr->mflag2.set(MFLAG2::NOPET);
160     } else if (has_aggravate(player_ptr)) {
161         em_ptr->note = _("はあなたに敵意を抱いている!", " hates you too much!");
162         if (one_in_(4))
163             em_ptr->m_ptr->mflag2.set(MFLAG2::NOPET);
164     } else {
165         em_ptr->note = _("はなついた。", " is tamed!");
166         set_pet(player_ptr, em_ptr->m_ptr);
167         if (em_ptr->r_ptr->flags3 & RF3_ANIMAL)
168             chg_virtue(player_ptr, V_NATURE, 1);
169     }
170
171     em_ptr->dam = 0;
172     return PROCESS_CONTINUE;
173 }
174
175 process_result effect_monster_charm_living(player_type *player_ptr, effect_monster_type *em_ptr)
176 {
177     int vir = virtue_number(player_ptr, V_UNLIFE);
178     if (em_ptr->seen)
179         em_ptr->obvious = true;
180
181     vir = virtue_number(player_ptr, V_UNLIFE);
182     if (vir) {
183         em_ptr->dam -= player_ptr->virtues[vir - 1] / 10;
184     }
185
186     vir = virtue_number(player_ptr, V_INDIVIDUALISM);
187     if (vir) {
188         em_ptr->dam -= player_ptr->virtues[vir - 1] / 20;
189     }
190
191     msg_format(_("%sを見つめた。", "You stare at %s."), em_ptr->m_name);
192
193     if (common_saving_throw_charm(player_ptr, em_ptr->dam, em_ptr->m_ptr) || !monster_living(em_ptr->m_ptr->r_idx)) {
194         em_ptr->note = _("には効果がなかった。", " is unaffected.");
195         em_ptr->obvious = false;
196         if (one_in_(4))
197             em_ptr->m_ptr->mflag2.set(MFLAG2::NOPET);
198     } else if (has_aggravate(player_ptr)) {
199         em_ptr->note = _("はあなたに敵意を抱いている!", " hates you too much!");
200         if (one_in_(4))
201             em_ptr->m_ptr->mflag2.set(MFLAG2::NOPET);
202     } else {
203         em_ptr->note = _("を支配した。", " is tamed!");
204         set_pet(player_ptr, em_ptr->m_ptr);
205         if (em_ptr->r_ptr->flags3 & RF3_ANIMAL)
206             chg_virtue(player_ptr, V_NATURE, 1);
207     }
208
209     em_ptr->dam = 0;
210     return PROCESS_CONTINUE;
211 }
212
213 static void effect_monster_domination_corrupted_addition(player_type *player_ptr, effect_monster_type *em_ptr)
214 {
215     BadStatusSetter bss(player_ptr);
216     switch (randint1(4)) {
217     case 1:
218         (void)bss.mod_stun(em_ptr->dam / 2);
219         return;
220     case 2:
221         (void)bss.mod_confusion(em_ptr->dam / 2);
222         return;
223     default:
224         if (any_bits(em_ptr->r_ptr->flags3, RF3_NO_FEAR)) {
225             em_ptr->note = _("には効果がなかった。", " is unaffected.");
226         } else {
227             (void)bss.mod_afraidness(static_cast<TIME_EFFECT>(em_ptr->dam));
228         }
229
230         return;
231     }
232 }
233
234 // Powerful demons & undead can turn a mindcrafter's attacks back on them.
235 static void effect_monster_domination_corrupted(player_type *player_ptr, effect_monster_type *em_ptr)
236 {
237     bool is_corrupted = ((em_ptr->r_ptr->flags3 & (RF3_UNDEAD | RF3_DEMON)) != 0) && (em_ptr->r_ptr->level > player_ptr->lev / 2) && (one_in_(2));
238     if (!is_corrupted) {
239         em_ptr->note = _("には効果がなかった。", " is unaffected.");
240         em_ptr->obvious = false;
241         return;
242     }
243
244     em_ptr->note = nullptr;
245     msg_format(_("%^sの堕落した精神は攻撃を跳ね返した!",
246                    (em_ptr->seen ? "%^s's corrupted mind backlashes your attack!" : "%^ss corrupted mind backlashes your attack!")),
247         em_ptr->m_name);
248     if (randint0(100 + em_ptr->r_ptr->level / 2) < player_ptr->skill_sav) {
249         msg_print(_("しかし効力を跳ね返した!", "You resist the effects!"));
250         return;
251     }
252
253     effect_monster_domination_corrupted_addition(player_ptr, em_ptr);
254 }
255
256 static void effect_monster_domination_addition(effect_monster_type *em_ptr)
257 {
258     switch (randint1(4)) {
259     case 1:
260         em_ptr->do_stun = em_ptr->dam / 2;
261         break;
262     case 2:
263         em_ptr->do_conf = em_ptr->dam / 2;
264         break;
265     default:
266         em_ptr->do_fear = em_ptr->dam;
267     }
268 }
269
270 process_result effect_monster_domination(player_type *player_ptr, effect_monster_type *em_ptr)
271 {
272     if (!is_hostile(em_ptr->m_ptr))
273         return PROCESS_CONTINUE;
274
275     if (em_ptr->seen)
276         em_ptr->obvious = true;
277
278     if ((em_ptr->r_ptr->flags1 & (RF1_UNIQUE | RF1_QUESTOR)) || (em_ptr->r_ptr->flags3 & RF3_NO_CONF)
279         || (em_ptr->r_ptr->level > randint1((em_ptr->dam - 10) < 1 ? 1 : (em_ptr->dam - 10)) + 10)) {
280         if (((em_ptr->r_ptr->flags3 & RF3_NO_CONF) != 0) && is_original_ap_and_seen(player_ptr, em_ptr->m_ptr))
281             em_ptr->r_ptr->r_flags3 |= (RF3_NO_CONF);
282
283         em_ptr->do_conf = 0;
284         effect_monster_domination_corrupted(player_ptr, em_ptr);
285         em_ptr->dam = 0;
286         return PROCESS_CONTINUE;
287     }
288
289     if (!common_saving_throw_charm(player_ptr, em_ptr->dam, em_ptr->m_ptr)) {
290         em_ptr->note = _("があなたに隷属した。", " is in your thrall!");
291         set_pet(player_ptr, em_ptr->m_ptr);
292         em_ptr->dam = 0;
293         return PROCESS_CONTINUE;
294     }
295
296     effect_monster_domination_addition(em_ptr);
297     em_ptr->dam = 0;
298     return PROCESS_CONTINUE;
299 }
300
301 static bool effect_monster_crusade_domination(player_type *player_ptr, effect_monster_type *em_ptr)
302 {
303     if (((em_ptr->r_ptr->flags3 & RF3_GOOD) == 0) || player_ptr->current_floor_ptr->inside_arena)
304         return false;
305
306     if (em_ptr->r_ptr->flags3 & RF3_NO_CONF)
307         em_ptr->dam -= 50;
308     if (em_ptr->dam < 1)
309         em_ptr->dam = 1;
310
311     if (is_pet(em_ptr->m_ptr)) {
312         em_ptr->note = _("の動きが速くなった。", " starts moving faster.");
313         (void)set_monster_fast(player_ptr, em_ptr->g_ptr->m_idx, monster_fast_remaining(em_ptr->m_ptr) + 100);
314         return true;
315     }
316
317     if ((em_ptr->r_ptr->flags1 & RF1_QUESTOR) || (em_ptr->r_ptr->flags1 & RF1_UNIQUE) || em_ptr->m_ptr->mflag2.has(MFLAG2::NOPET) || has_aggravate(player_ptr)
318         || ((em_ptr->r_ptr->level + 10) > randint1(em_ptr->dam))) {
319         if (one_in_(4))
320             em_ptr->m_ptr->mflag2.set(MFLAG2::NOPET);
321
322         return false;
323     }
324
325     em_ptr->note = _("を支配した。", " is tamed!");
326     set_pet(player_ptr, em_ptr->m_ptr);
327     (void)set_monster_fast(player_ptr, em_ptr->g_ptr->m_idx, monster_fast_remaining(em_ptr->m_ptr) + 100);
328     if (is_original_ap_and_seen(player_ptr, em_ptr->m_ptr))
329         em_ptr->r_ptr->r_flags3 |= RF3_GOOD;
330
331     return true;
332 }
333
334 process_result effect_monster_crusade(player_type *player_ptr, effect_monster_type *em_ptr)
335 {
336     if (em_ptr->seen)
337         em_ptr->obvious = true;
338     bool success = effect_monster_crusade_domination(player_ptr, em_ptr);
339     if (success) {
340         em_ptr->dam = 0;
341         return PROCESS_CONTINUE;
342     }
343
344     if ((em_ptr->r_ptr->flags3 & RF3_NO_FEAR) == 0)
345         em_ptr->do_fear = randint1(90) + 10;
346     else if (is_original_ap_and_seen(player_ptr, em_ptr->m_ptr))
347         em_ptr->r_ptr->r_flags3 |= RF3_NO_FEAR;
348
349     em_ptr->dam = 0;
350     return PROCESS_CONTINUE;
351 }
352
353 /*!
354  * @brief モンスターボールで捕まえられる最大HPを計算する
355  * @param player_ptr プレイヤー情報への参照ポインタ
356  * @param m_ptr モンスター情報への参照ポインタ
357  * @param hp 計算対象のHP
358  * @return 捕まえられる最大HP
359  */
360 static HIT_POINT calcutate_capturable_hp(player_type *player_ptr, monster_type *m_ptr, HIT_POINT hp)
361 {
362     if (is_pet(m_ptr))
363         return hp * 4L;
364
365     if ((player_ptr->pclass == CLASS_BEASTMASTER) && monster_living(m_ptr->r_idx))
366         return hp * 3 / 10;
367
368     return hp * 3 / 20;
369 }
370
371 /*!
372  * @brief モンスターボールで捕らえた処理
373  * @param player_ptr プレイヤー情報への参照ポインタ
374  * @param em_ptr 効果情報への参照ポインタ
375  */
376 static void effect_monster_captured(player_type *player_ptr, effect_monster_type *em_ptr)
377 {
378     if (em_ptr->m_ptr->mflag2.has(MFLAG2::CHAMELEON))
379         choose_new_monster(player_ptr, em_ptr->g_ptr->m_idx, false, MON_CHAMELEON);
380
381     msg_format(_("%sを捕えた!", "You capture %^s!"), em_ptr->m_name);
382     cap_mon = em_ptr->m_ptr->r_idx;
383     cap_mspeed = em_ptr->m_ptr->mspeed;
384     cap_hp = em_ptr->m_ptr->hp;
385     cap_maxhp = em_ptr->m_ptr->max_maxhp;
386     cap_nickname = em_ptr->m_ptr->nickname;
387     if ((em_ptr->g_ptr->m_idx == player_ptr->riding) && process_fall_off_horse(player_ptr, -1, false))
388         msg_format(_("地面に落とされた。", "You have fallen from %s."), em_ptr->m_name);
389
390     delete_monster_idx(player_ptr, em_ptr->g_ptr->m_idx);
391     calculate_upkeep(player_ptr);
392 }
393
394 /*!
395  * @brief モンスターボールで捕らえる効果(GF_CAPTURE)
396  * @param player_ptr プレイヤー情報への参照ポインタ
397  * @param em_ptr 効果情報への参照ポインタ
398  * @return 効果発動結果
399  */
400 process_result effect_monster_capture(player_type *player_ptr, effect_monster_type *em_ptr)
401 {
402     floor_type *floor_ptr = player_ptr->current_floor_ptr;
403     if ((floor_ptr->inside_quest && (quest[floor_ptr->inside_quest].type == QuestKindType::KILL_ALL) && !is_pet(em_ptr->m_ptr))
404         || any_bits(em_ptr->r_ptr->flags1, RF1_UNIQUE | RF1_QUESTOR) || any_bits(em_ptr->r_ptr->flags7, RF7_NAZGUL | RF7_UNIQUE2)
405         || em_ptr->m_ptr->parent_m_idx) {
406         msg_format(_("%sには効果がなかった。", "%s is unaffected."), em_ptr->m_name);
407         em_ptr->skipped = true;
408         return PROCESS_CONTINUE;
409     }
410
411     auto r_max_hp = em_ptr->r_ptr->hdice * em_ptr->r_ptr->hside;
412     auto threshold_hp = calcutate_capturable_hp(player_ptr, em_ptr->m_ptr, r_max_hp);
413     auto capturable_hp = MAX(2, calcutate_capturable_hp(player_ptr, em_ptr->m_ptr, em_ptr->m_ptr->max_maxhp));
414
415     if (threshold_hp < 2 || em_ptr->m_ptr->hp >= capturable_hp) {
416         msg_format(_("もっと弱らせないと。", "You need to weaken %s more."), em_ptr->m_name);
417         em_ptr->skipped = true;
418         return PROCESS_CONTINUE;
419     }
420
421     if (em_ptr->m_ptr->hp <= randint1(capturable_hp)) {
422         effect_monster_captured(player_ptr, em_ptr);
423         return PROCESS_TRUE;
424     }
425
426     msg_format(_("うまく捕まえられなかった。", "You failed to capture %s."), em_ptr->m_name);
427     em_ptr->skipped = true;
428     return PROCESS_CONTINUE;
429 }