OSDN Git Service

10307e92a5facfaf9194e84b0502dbb78802e9d0
[hengbandforosx/hengbandosx.git] / src / mspell / mspell-special.cpp
1 /*!
2  * @brief 特殊な行動を取るモンスターの具体的な行動定義 (MonsterRaceDefinitionsのSPECIALフラグ)
3  * @date 2020/05/16
4  * @author Hourier
5  */
6
7 #include "mspell/mspell-special.h"
8 #include "core/disturbance.h"
9 #include "effect/attribute-types.h"
10 #include "effect/effect-characteristics.h"
11 #include "effect/effect-processor.h"
12 #include "floor/cave.h"
13 #include "main/sound-definitions-table.h"
14 #include "main/sound-of-music.h"
15 #include "melee/melee-postprocess.h"
16 #include "monster-floor/monster-death.h"
17 #include "monster-floor/monster-remover.h"
18 #include "monster-floor/monster-summon.h"
19 #include "monster-race/monster-race.h"
20 #include "monster-race/race-flags7.h"
21 #include "monster-race/race-indice-types.h"
22 #include "monster/monster-describer.h"
23 #include "monster/monster-description-types.h"
24 #include "monster/monster-info.h"
25 #include "monster/monster-util.h"
26 #include "mspell/mspell-checker.h"
27 #include "mspell/mspell-result.h"
28 #include "mspell/mspell-util.h"
29 #include "player/player-damage.h"
30 #include "spell-kind/spells-teleport.h"
31 #include "spell-realm/spells-crusade.h"
32 #include "system/floor-type-definition.h"
33 #include "system/grid-type-definition.h"
34 #include "system/monster-entity.h"
35 #include "system/monster-race-info.h"
36 #include "system/player-type-definition.h"
37 #include "system/redrawing-flags-updater.h"
38 #include "timed-effect/player-blindness.h"
39 #include "timed-effect/timed-effects.h"
40 #include "view/display-messages.h"
41
42 /*!
43  * @brief バーノール・ルパートのRF6_SPECIALの処理。分裂・合体。 /
44  * @param player_ptr プレイヤーへの参照ポインタ
45  * @param m_idx 呪文を唱えるモンスターID
46  */
47 static MonsterSpellResult spell_RF6_SPECIAL_BANORLUPART(PlayerType *player_ptr, MONSTER_IDX m_idx)
48 {
49     auto *floor_ptr = player_ptr->current_floor_ptr;
50     auto *m_ptr = &floor_ptr->m_list[m_idx];
51     int dummy_hp, dummy_maxhp;
52     POSITION dummy_y = m_ptr->fy;
53     POSITION dummy_x = m_ptr->fx;
54     BIT_FLAGS mode = 0L;
55
56     if (see_monster(player_ptr, m_idx) && monster_near_player(floor_ptr, m_idx, 0)) {
57         disturb(player_ptr, true, true);
58     }
59
60     switch (m_ptr->r_idx) {
61     case MonsterRaceId::BANORLUPART:
62         dummy_hp = (m_ptr->hp + 1) / 2;
63         dummy_maxhp = m_ptr->maxhp / 2;
64
65         if (floor_ptr->inside_arena || player_ptr->phase_out || !summon_possible(player_ptr, m_ptr->fy, m_ptr->fx)) {
66             return MonsterSpellResult::make_invalid();
67         }
68
69         delete_monster_idx(player_ptr, floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].m_idx);
70         summon_named_creature(player_ptr, 0, dummy_y, dummy_x, MonsterRaceId::BANOR, mode);
71         floor_ptr->m_list[hack_m_idx_ii].hp = dummy_hp;
72         floor_ptr->m_list[hack_m_idx_ii].maxhp = dummy_maxhp;
73         summon_named_creature(player_ptr, 0, dummy_y, dummy_x, MonsterRaceId::LUPART, mode);
74         floor_ptr->m_list[hack_m_idx_ii].hp = dummy_hp;
75         floor_ptr->m_list[hack_m_idx_ii].maxhp = dummy_maxhp;
76
77         msg_print(_("『バーノール・ルパート』が分裂した!", "Banor=Rupart splits into two persons!"));
78         break;
79
80     case MonsterRaceId::BANOR:
81     case MonsterRaceId::LUPART:
82         dummy_hp = 0;
83         dummy_maxhp = 0;
84
85         if (!monraces_info[MonsterRaceId::BANOR].cur_num || !monraces_info[MonsterRaceId::LUPART].cur_num) {
86             return MonsterSpellResult::make_invalid();
87         }
88
89         for (MONSTER_IDX k = 1; k < floor_ptr->m_max; k++) {
90             if (floor_ptr->m_list[k].r_idx == MonsterRaceId::BANOR || floor_ptr->m_list[k].r_idx == MonsterRaceId::LUPART) {
91                 dummy_hp += floor_ptr->m_list[k].hp;
92                 dummy_maxhp += floor_ptr->m_list[k].maxhp;
93                 if (floor_ptr->m_list[k].r_idx != m_ptr->r_idx) {
94                     dummy_y = floor_ptr->m_list[k].fy;
95                     dummy_x = floor_ptr->m_list[k].fx;
96                 }
97                 delete_monster_idx(player_ptr, k);
98             }
99         }
100         summon_named_creature(player_ptr, 0, dummy_y, dummy_x, MonsterRaceId::BANORLUPART, mode);
101         floor_ptr->m_list[hack_m_idx_ii].hp = dummy_hp;
102         floor_ptr->m_list[hack_m_idx_ii].maxhp = dummy_maxhp;
103
104         msg_print(_("『バーノール』と『ルパート』が合体した!", "Banor and Rupart combine into one!"));
105         break;
106
107     default:
108         break;
109     }
110
111     return MonsterSpellResult::make_valid();
112 }
113
114 /*!
115  * @brief ロレントのRF6_SPECIALの処理。手榴弾の召喚。 /
116  * @param player_ptr プレイヤーへの参照ポインタ
117  * @param y 対象の地点のy座標
118  * @param x 対象の地点のx座標
119  * @param m_idx 呪文を唱えるモンスターID
120  * @param t_idx 呪文を受けるモンスターID。プレイヤーの場合はdummyで0とする。
121  * @param target_type プレイヤーを対象とする場合MONSTER_TO_PLAYER、モンスターを対象とする場合MONSTER_TO_MONSTER
122  */
123 static MonsterSpellResult spell_RF6_SPECIAL_ROLENTO(PlayerType *player_ptr, POSITION y, POSITION x, MONSTER_IDX m_idx, MONSTER_IDX t_idx, int target_type)
124 {
125     int count = 0, k;
126     int num = 1 + randint1(3);
127     BIT_FLAGS mode = 0L;
128     auto *floor_ptr = player_ptr->current_floor_ptr;
129     bool see_either = see_monster(player_ptr, m_idx) || see_monster(player_ptr, t_idx);
130     bool mon_to_mon = target_type == MONSTER_TO_MONSTER;
131     bool mon_to_player = target_type == MONSTER_TO_PLAYER;
132     bool known = monster_near_player(floor_ptr, m_idx, t_idx);
133
134     mspell_cast_msg_blind msg(_("%s^が何か大量に投げた。", "%s^ spreads something."),
135         _("%s^は手榴弾をばらまいた。", "%s^ throws some hand grenades."), _("%s^は手榴弾をばらまいた。", "%s^ throws some hand grenades."));
136
137     monspell_message(player_ptr, m_idx, t_idx, msg, target_type);
138     if (mon_to_player || (mon_to_mon && known && see_either)) {
139         disturb(player_ptr, true, true);
140     }
141
142     for (k = 0; k < num; k++) {
143         count += summon_named_creature(player_ptr, m_idx, y, x, MonsterRaceId::GRENADE, mode);
144     }
145     if (player_ptr->effects()->blindness()->is_blind() && count) {
146         msg_print(_("多くのものが間近にばらまかれる音がする。", "You hear many things scattered nearby."));
147     }
148
149     return MonsterSpellResult::make_valid();
150 }
151
152 /*!
153  * @brief BシンボルのRF6_SPECIALの処理。投げ落とす攻撃。 /
154  * @param player_ptr プレイヤーへの参照ポインタ
155  * @param y 対象の地点のy座標
156  * @param x 対象の地点のx座標
157  * @param m_idx 呪文を唱えるモンスターID
158  * @param t_idx 呪文を受けるモンスターID。プレイヤーの場合はdummyで0とする。
159  * @param target_type プレイヤーを対象とする場合MONSTER_TO_PLAYER、モンスターを対象とする場合MONSTER_TO_MONSTER
160  */
161 static MonsterSpellResult spell_RF6_SPECIAL_B(PlayerType *player_ptr, POSITION y, POSITION x, MONSTER_IDX m_idx, MONSTER_IDX t_idx, int target_type)
162 {
163     mspell_cast_msg_simple msg;
164     auto *floor_ptr = player_ptr->current_floor_ptr;
165     auto *m_ptr = &floor_ptr->m_list[m_idx];
166     MonsterEntity *t_ptr = &floor_ptr->m_list[t_idx];
167     MonsterRaceInfo *tr_ptr = &monraces_info[t_ptr->r_idx];
168     bool monster_to_player = (target_type == MONSTER_TO_PLAYER);
169     bool monster_to_monster = (target_type == MONSTER_TO_MONSTER);
170     bool direct = player_bold(player_ptr, y, x);
171     const auto m_name = monster_name(player_ptr, m_idx);
172
173     disturb(player_ptr, true, true);
174     if (one_in_(3) || !direct) {
175         msg.to_player = _("%s^は突然視界から消えた!", "You lose sight of %s!");
176         msg.to_mons = _("%s^は突然急上昇して視界から消えた!", "You lose sight of %s!");
177
178         simple_monspell_message(player_ptr, m_idx, t_idx, msg, target_type);
179
180         teleport_away(player_ptr, m_idx, 10, TELEPORT_NONMAGICAL);
181         RedrawingFlagsUpdater::get_instance().set_flag(StatusRedrawingFlag::MONSTER_STATUSES);
182         return MonsterSpellResult::make_valid();
183     }
184
185     if (direct) {
186         sound(SOUND_FALL);
187     }
188
189     msg.to_player = _("%s^があなたを掴んで空中から投げ落とした。", "%s^ snatches you, soars into the sky, and drops you.");
190     msg.to_mons = _("%s^が%sを掴んで空中から投げ落とした。", "%s^ snatches %s, soars into the sky, and releases its grip.");
191
192     simple_monspell_message(player_ptr, m_idx, t_idx, msg, target_type);
193
194     bool fear, dead; /* dummy */
195     int dam = damroll(4, 8);
196
197     if (monster_to_player || t_idx == player_ptr->riding) {
198         teleport_player_to(player_ptr, m_ptr->fy, m_ptr->fx, i2enum<teleport_flags>(TELEPORT_NONMAGICAL | TELEPORT_PASSIVE));
199     } else {
200         teleport_monster_to(player_ptr, t_idx, m_ptr->fy, m_ptr->fx, 100, i2enum<teleport_flags>(TELEPORT_NONMAGICAL | TELEPORT_PASSIVE));
201     }
202
203     if ((monster_to_player && player_ptr->levitation) || (monster_to_monster && tr_ptr->feature_flags.has(MonsterFeatureType::CAN_FLY))) {
204         msg.to_player = _("あなたは静かに着地した。", "You float gently down to the ground.");
205         msg.to_mons = _("%s^は静かに着地した。", "%s^ floats gently down to the ground.");
206     } else {
207         msg.to_player = _("あなたは地面に叩きつけられた。", "You crashed into the ground.");
208         msg.to_mons = _("%s^は地面に叩きつけられた。", "%s^ crashed into the ground.");
209     }
210
211     simple_monspell_message(player_ptr, m_idx, t_idx, msg, target_type);
212     dam += damroll(6, 8);
213
214     if (monster_to_player || (monster_to_monster && player_ptr->riding == t_idx)) {
215         int get_damage = take_hit(player_ptr, DAMAGE_NOESCAPE, dam, m_name.data());
216         if (player_ptr->tim_eyeeye && get_damage > 0 && !player_ptr->is_dead) {
217             const auto m_name_self = monster_desc(player_ptr, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE | MD_OBJECTIVE);
218             msg_print(_(format("攻撃が%s自身を傷つけた!", m_name.data()), format("The attack of %s has wounded %s!", m_name.data(), m_name_self.data())));
219             project(player_ptr, 0, 0, m_ptr->fy, m_ptr->fx, get_damage, AttributeType::MISSILE, PROJECT_KILL);
220             set_tim_eyeeye(player_ptr, player_ptr->tim_eyeeye - 5, true);
221         }
222     }
223
224     if (monster_to_player && player_ptr->riding) {
225         const auto &m_ref = floor_ptr->m_list[player_ptr->riding];
226         mon_take_hit_mon(player_ptr, player_ptr->riding, dam, &dead, &fear, extract_note_dies(m_ref.get_real_r_idx()), m_idx);
227     }
228
229     if (monster_to_monster) {
230         mon_take_hit_mon(player_ptr, t_idx, dam, &dead, &fear, extract_note_dies(t_ptr->get_real_r_idx()), m_idx);
231     }
232
233     return MonsterSpellResult::make_valid();
234 }
235
236 /*!
237  * @brief RF6_SPECIALの処理。モンスターの種類によって実処理に振り分ける。 /
238  * @param player_ptr プレイヤーへの参照ポインタ
239  * @param y 対象の地点のy座標
240  * @param x 対象の地点のx座標
241  * @param m_idx 呪文を唱えるモンスターID
242  * @param t_idx 呪文を受けるモンスターID。プレイヤーの場合はdummyで0とする。
243  * @param target_type プレイヤーを対象とする場合MONSTER_TO_PLAYER、モンスターを対象とする場合MONSTER_TO_MONSTER
244  *
245  * ラーニング不可。
246  */
247 MonsterSpellResult spell_RF6_SPECIAL(PlayerType *player_ptr, POSITION y, POSITION x, MONSTER_IDX m_idx, MONSTER_IDX t_idx, int target_type)
248 {
249     auto *floor_ptr = player_ptr->current_floor_ptr;
250     auto *m_ptr = &floor_ptr->m_list[m_idx];
251     auto *r_ptr = &monraces_info[m_ptr->r_idx];
252
253     switch (m_ptr->r_idx) {
254     case MonsterRaceId::OHMU:
255         return MonsterSpellResult::make_invalid();
256
257     case MonsterRaceId::BANORLUPART:
258     case MonsterRaceId::BANOR:
259     case MonsterRaceId::LUPART:
260         return spell_RF6_SPECIAL_BANORLUPART(player_ptr, m_idx);
261
262     case MonsterRaceId::ROLENTO:
263         return spell_RF6_SPECIAL_ROLENTO(player_ptr, y, x, m_idx, t_idx, target_type);
264         break;
265
266     default:
267         if (r_ptr->d_char == 'B') {
268             return spell_RF6_SPECIAL_B(player_ptr, y, x, m_idx, t_idx, target_type);
269             break;
270         } else {
271             return MonsterSpellResult::make_invalid();
272         }
273     }
274 }