OSDN Git Service

[Refactor] #39963 Moved effect_monster_capture() from effect-monster-switcher.c to...
[hengband/hengband.git] / src / effect / effect-monster-domination.c
1 #include "angband.h"
2 #include "effect/effect-monster-util.h"
3 #include "effect/effect-monster-domination.h"
4 #include "player-effects.h"
5 #include "spells-diceroll.h"
6 #include "monster-status.h"
7 #include "effect/spells-effect-util.h"
8 #include "cmd/cmd-pet.h" // 暫定、後で消すかも.
9 #include "quest.h"
10 #include "monsterrace-hook.h"
11
12 static void effect_monster_domination_corrupted_addition(player_type *caster_ptr, effect_monster_type *em_ptr)
13 {
14         switch (randint1(4))
15         {
16         case 1:
17                 set_stun(caster_ptr, caster_ptr->stun + em_ptr->dam / 2);
18                 break;
19         case 2:
20                 set_confused(caster_ptr, caster_ptr->confused + em_ptr->dam / 2);
21                 break;
22         default:
23         {
24                 if (em_ptr->r_ptr->flags3 & RF3_NO_FEAR)
25                         em_ptr->note = _("には効果がなかった。", " is unaffected.");
26                 else
27                         set_afraid(caster_ptr, caster_ptr->afraid + em_ptr->dam);
28         }
29         }
30 }
31
32
33 // Powerful demons & undead can turn a mindcrafter's attacks back on them.
34 static void effect_monster_domination_corrupted(player_type *caster_ptr, effect_monster_type *em_ptr)
35 {
36         bool is_corrupted = ((em_ptr->r_ptr->flags3 & (RF3_UNDEAD | RF3_DEMON)) != 0) &&
37                 (em_ptr->r_ptr->level > caster_ptr->lev / 2) &&
38                 (one_in_(2));
39         if (!is_corrupted)
40         {
41                 em_ptr->note = _("には効果がなかった。", " is unaffected.");
42                 em_ptr->obvious = FALSE;
43                 return;
44         }
45
46         em_ptr->note = NULL;
47         msg_format(_("%^sの堕落した精神は攻撃を跳ね返した!",
48                 (em_ptr->seen ? "%^s's corrupted mind backlashes your attack!" :
49                         "%^ss corrupted mind backlashes your attack!")), em_ptr->m_name);
50         if (randint0(100 + em_ptr->r_ptr->level / 2) < caster_ptr->skill_sav)
51         {
52                 msg_print(_("しかし効力を跳ね返した!", "You resist the effects!"));
53                 return;
54         }
55
56         effect_monster_domination_corrupted_addition(caster_ptr, em_ptr);
57 }
58
59
60 static void effect_monster_domination_addition(effect_monster_type *em_ptr)
61 {
62         switch (randint1(4))
63         {
64         case 1:
65                 em_ptr->do_stun = em_ptr->dam / 2;
66                 break;
67         case 2:
68                 em_ptr->do_conf = em_ptr->dam / 2;
69                 break;
70         default:
71                 em_ptr->do_fear = em_ptr->dam;
72         }
73 }
74
75
76 gf_switch_result effect_monster_domination(player_type *caster_ptr, effect_monster_type *em_ptr)
77 {
78         if (!is_hostile(em_ptr->m_ptr)) return GF_SWITCH_CONTINUE;
79
80         if (em_ptr->seen) em_ptr->obvious = TRUE;
81
82         if ((em_ptr->r_ptr->flags1 & (RF1_UNIQUE | RF1_QUESTOR)) ||
83                 (em_ptr->r_ptr->flags3 & RF3_NO_CONF) ||
84                 (em_ptr->r_ptr->level > randint1((em_ptr->dam - 10) < 1 ? 1 : (em_ptr->dam - 10)) + 10))
85         {
86                 if (((em_ptr->r_ptr->flags3 & RF3_NO_CONF) != 0) && is_original_ap_and_seen(caster_ptr, em_ptr->m_ptr))
87                         em_ptr->r_ptr->r_flags3 |= (RF3_NO_CONF);
88
89                 em_ptr->do_conf = 0;
90                 effect_monster_domination_corrupted(caster_ptr, em_ptr);
91                 em_ptr->dam = 0;
92                 return GF_SWITCH_CONTINUE;
93         }
94
95         if (!common_saving_throw_charm(caster_ptr, em_ptr->dam, em_ptr->m_ptr))
96         {
97                 em_ptr->note = _("があなたに隷属した。", " is in your thrall!");
98                 set_pet(caster_ptr, em_ptr->m_ptr);
99                 em_ptr->dam = 0;
100                 return GF_SWITCH_CONTINUE;
101         }
102
103         effect_monster_domination_addition(em_ptr);
104         em_ptr->dam = 0;
105         return GF_SWITCH_CONTINUE;
106 }
107
108
109 static bool effect_monster_crusade_domination(player_type *caster_ptr, effect_monster_type *em_ptr)
110 {
111         if (((em_ptr->r_ptr->flags3 & RF3_GOOD) == 0) || caster_ptr->current_floor_ptr->inside_arena)
112                 return FALSE;
113
114         if (em_ptr->r_ptr->flags3 & RF3_NO_CONF) em_ptr->dam -= 50;
115         if (em_ptr->dam < 1) em_ptr->dam = 1;
116
117         if (is_pet(em_ptr->m_ptr))
118         {
119                 em_ptr->note = _("の動きが速くなった。", " starts moving faster.");
120                 (void)set_monster_fast(caster_ptr, em_ptr->g_ptr->m_idx, MON_FAST(em_ptr->m_ptr) + 100);
121                 return TRUE;
122         }
123
124         if ((em_ptr->r_ptr->flags1 & RF1_QUESTOR) ||
125                 (em_ptr->r_ptr->flags1 & RF1_UNIQUE) ||
126                 (em_ptr->m_ptr->mflag2 & MFLAG2_NOPET) ||
127                 (caster_ptr->cursed & TRC_AGGRAVATE) ||
128                 ((em_ptr->r_ptr->level + 10) > randint1(em_ptr->dam)))
129         {
130                 if (one_in_(4))
131                         em_ptr->m_ptr->mflag2 |= MFLAG2_NOPET;
132
133                 return FALSE;
134         }
135
136         em_ptr->note = _("を支配した。", " is tamed!");
137         set_pet(caster_ptr, em_ptr->m_ptr);
138         (void)set_monster_fast(caster_ptr, em_ptr->g_ptr->m_idx, MON_FAST(em_ptr->m_ptr) + 100);
139         if (is_original_ap_and_seen(caster_ptr, em_ptr->m_ptr))
140                 em_ptr->r_ptr->r_flags3 |= RF3_GOOD;
141
142         return TRUE;
143 }
144
145
146 gf_switch_result effect_monster_crusade(player_type *caster_ptr, effect_monster_type *em_ptr)
147 {
148         if (em_ptr->seen) em_ptr->obvious = TRUE;
149         bool success = effect_monster_crusade_domination(caster_ptr, em_ptr);
150         if (success)
151         {
152                 em_ptr->dam = 0;
153                 return GF_SWITCH_CONTINUE;
154         }
155
156         if ((em_ptr->r_ptr->flags3 & RF3_NO_FEAR) == 0)
157                 em_ptr->do_fear = randint1(90) + 10;
158         else if (is_original_ap_and_seen(caster_ptr, em_ptr->m_ptr))
159                 em_ptr->r_ptr->r_flags3 |= RF3_NO_FEAR;
160
161         em_ptr->dam = 0;
162         return GF_SWITCH_CONTINUE;
163 }
164
165
166 static bool effect_monster_capture_attemption(player_type *caster_ptr, effect_monster_type *em_ptr, int capturable_hp)
167 {
168         if (em_ptr->m_ptr->hp >= randint0(capturable_hp)) return FALSE;
169
170         if (em_ptr->m_ptr->mflag2 & MFLAG2_CHAMELEON)
171                 choose_new_monster(caster_ptr, em_ptr->g_ptr->m_idx, FALSE, MON_CHAMELEON);
172
173         msg_format(_("%sを捕えた!", "You capture %^s!"), em_ptr->m_name);
174         cap_mon = em_ptr->m_ptr->r_idx;
175         cap_mspeed = em_ptr->m_ptr->mspeed;
176         cap_hp = em_ptr->m_ptr->hp;
177         cap_maxhp = em_ptr->m_ptr->max_maxhp;
178         cap_nickname = em_ptr->m_ptr->nickname;
179         if ((em_ptr->g_ptr->m_idx == caster_ptr->riding) && rakuba(caster_ptr, -1, FALSE))
180                 msg_format(_("地面に落とされた。", "You have fallen from %s."), em_ptr->m_name);
181
182         delete_monster_idx(caster_ptr, em_ptr->g_ptr->m_idx);
183         return TRUE;
184 }
185
186
187 gf_switch_result effect_monster_capture(player_type *caster_ptr, effect_monster_type *em_ptr)
188 {
189         floor_type *floor_ptr = caster_ptr->current_floor_ptr;
190         int capturable_hp;
191         if ((floor_ptr->inside_quest && (quest[floor_ptr->inside_quest].type == QUEST_TYPE_KILL_ALL) && !is_pet(em_ptr->m_ptr)) ||
192                 (em_ptr->r_ptr->flags1 & (RF1_UNIQUE)) || (em_ptr->r_ptr->flags7 & (RF7_NAZGUL)) || (em_ptr->r_ptr->flags7 & (RF7_UNIQUE2)) || (em_ptr->r_ptr->flags1 & RF1_QUESTOR) || em_ptr->m_ptr->parent_m_idx)
193         {
194                 msg_format(_("%sには効果がなかった。", "%s is unaffected."), em_ptr->m_name);
195                 em_ptr->skipped = TRUE;
196                 return GF_SWITCH_CONTINUE;
197         }
198
199         if (is_pet(em_ptr->m_ptr)) capturable_hp = em_ptr->m_ptr->maxhp * 4L;
200         else if ((caster_ptr->pclass == CLASS_BEASTMASTER) && monster_living(em_ptr->m_ptr->r_idx))
201                 capturable_hp = em_ptr->m_ptr->maxhp * 3 / 10;
202         else
203                 capturable_hp = em_ptr->m_ptr->maxhp * 3 / 20;
204
205         if (em_ptr->m_ptr->hp >= capturable_hp)
206         {
207                 msg_format(_("もっと弱らせないと。", "You need to weaken %s more."), em_ptr->m_name);
208                 em_ptr->skipped = TRUE;
209                 return GF_SWITCH_CONTINUE;
210         }
211
212         if (effect_monster_capture_attemption(caster_ptr, em_ptr, capturable_hp))
213                 return GF_SWITCH_TRUE;
214
215         msg_format(_("うまく捕まえられなかった。", "You failed to capture %s."), em_ptr->m_name);
216         em_ptr->skipped = TRUE;
217         return GF_SWITCH_CONTINUE;
218 }