OSDN Git Service

Merge pull request #3814 from Slimebreath6078/feature/Add_Laffey_II
[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-indice-types.h"
21 #include "monster/monster-describer.h"
22 #include "monster/monster-description-types.h"
23 #include "monster/monster-info.h"
24 #include "monster/monster-util.h"
25 #include "mspell/mspell-checker.h"
26 #include "mspell/mspell-result.h"
27 #include "mspell/mspell-util.h"
28 #include "player/player-damage.h"
29 #include "spell-kind/spells-teleport.h"
30 #include "spell-realm/spells-crusade.h"
31 #include "system/angband-system.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 #include <algorithm>
42 #include <sstream>
43
44 /*!
45  * @brief ユニークの分離・合体処理
46  * @param player_ptr プレイヤーへの参照ポインタ
47  * @param m_idx 呪文を唱えるモンスターID
48  */
49 static MonsterSpellResult spell_RF6_SPECIAL_UNIFICATION(PlayerType *player_ptr, MONSTER_IDX m_idx)
50 {
51     auto *floor_ptr = player_ptr->current_floor_ptr;
52     auto *m_ptr = &floor_ptr->m_list[m_idx];
53     auto dummy_y = m_ptr->fy;
54     auto dummy_x = m_ptr->fx;
55     if (see_monster(player_ptr, m_idx) && monster_near_player(floor_ptr, m_idx, 0)) {
56         disturb(player_ptr, true, true);
57     }
58
59     const auto &monraces = MonraceList::get_instance();
60     const auto &unified_uniques = MonraceList::get_unified_uniques();
61     if (const auto it_unified = unified_uniques.find(m_ptr->r_idx); it_unified != unified_uniques.end()) {
62         const int separates_size = it_unified->second.size();
63         const auto separated_hp = (m_ptr->hp + 1) / separates_size;
64         const auto separated_maxhp = m_ptr->maxhp / separates_size;
65         if (floor_ptr->inside_arena || AngbandSystem::get_instance().is_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         for (const auto separate : it_unified->second) {
71             summon_named_creature(player_ptr, 0, dummy_y, dummy_x, separate, MD_NONE);
72             floor_ptr->m_list[hack_m_idx_ii].hp = separated_hp;
73             floor_ptr->m_list[hack_m_idx_ii].maxhp = separated_maxhp;
74         }
75
76         const auto &m_name = monraces[it_unified->first].name;
77         msg_format(_("%sが分離した!", "%s splits!"), m_name.data());
78         return MonsterSpellResult::make_valid();
79     }
80
81     for (const auto &[unified_unique, separates] : unified_uniques) {
82         if (!separates.contains(m_ptr->r_idx)) {
83             continue;
84         }
85
86         if (!monraces.exists_separates(unified_unique)) {
87             return MonsterSpellResult::make_invalid();
88         }
89
90         auto unified_hp = 0;
91         auto unified_maxhp = 0;
92         for (short k = 1; k < floor_ptr->m_max; k++) {
93             const auto &monster = floor_ptr->m_list[k];
94             if (!separates.contains(monster.r_idx)) {
95                 continue;
96             }
97
98             unified_hp += monster.hp;
99             unified_maxhp += monster.maxhp;
100             if (monster.r_idx != m_ptr->r_idx) {
101                 dummy_y = monster.fy;
102                 dummy_x = monster.fx;
103             }
104
105             delete_monster_idx(player_ptr, k);
106         }
107
108         summon_named_creature(player_ptr, 0, dummy_y, dummy_x, unified_unique, MD_NONE);
109         floor_ptr->m_list[hack_m_idx_ii].hp = unified_hp;
110         floor_ptr->m_list[hack_m_idx_ii].maxhp = unified_maxhp;
111         std::vector<std::string> m_names;
112         for (const auto &separate : separates) {
113             const auto &monrace = monraces[separate];
114             m_names.push_back(monrace.name);
115         }
116
117         std::stringstream ss;
118         ss << *m_names.begin();
119         for (size_t i = 1; i < m_names.size(); i++) { // @todo clang v14 はstd::views::drop() 非対応
120             const auto &m_name = m_names[i];
121             ss << _("と", " and ");
122             ss << m_name;
123         }
124
125         const auto fmt = _("%sが合体した!", "%s combine into one!");
126         msg_print(format(fmt, ss.str().data()));
127         return MonsterSpellResult::make_valid();
128     }
129
130     return MonsterSpellResult::make_valid();
131 }
132
133 /*!
134  * @brief ロレントのRF6_SPECIALの処理。手榴弾の召喚。 /
135  * @param player_ptr プレイヤーへの参照ポインタ
136  * @param y 対象の地点のy座標
137  * @param x 対象の地点のx座標
138  * @param m_idx 呪文を唱えるモンスターID
139  * @param t_idx 呪文を受けるモンスターID。プレイヤーの場合はdummyで0とする。
140  * @param target_type プレイヤーを対象とする場合MONSTER_TO_PLAYER、モンスターを対象とする場合MONSTER_TO_MONSTER
141  */
142 static MonsterSpellResult spell_RF6_SPECIAL_ROLENTO(PlayerType *player_ptr, POSITION y, POSITION x, MONSTER_IDX m_idx, MONSTER_IDX t_idx, int target_type)
143 {
144     int count = 0, k;
145     int num = 1 + randint1(3);
146     BIT_FLAGS mode = 0L;
147     auto *floor_ptr = player_ptr->current_floor_ptr;
148     bool see_either = see_monster(player_ptr, m_idx) || see_monster(player_ptr, t_idx);
149     bool mon_to_mon = target_type == MONSTER_TO_MONSTER;
150     bool mon_to_player = target_type == MONSTER_TO_PLAYER;
151     bool known = monster_near_player(floor_ptr, m_idx, t_idx);
152
153     mspell_cast_msg_blind msg(_("%s^が何か大量に投げた。", "%s^ spreads something."),
154         _("%s^は手榴弾をばらまいた。", "%s^ throws some hand grenades."), _("%s^は手榴弾をばらまいた。", "%s^ throws some hand grenades."));
155
156     monspell_message(player_ptr, m_idx, t_idx, msg, target_type);
157     if (mon_to_player || (mon_to_mon && known && see_either)) {
158         disturb(player_ptr, true, true);
159     }
160
161     for (k = 0; k < num; k++) {
162         count += summon_named_creature(player_ptr, m_idx, y, x, MonsterRaceId::GRENADE, mode);
163     }
164     if (player_ptr->effects()->blindness()->is_blind() && count) {
165         msg_print(_("多くのものが間近にばらまかれる音がする。", "You hear many things scattered nearby."));
166     }
167
168     return MonsterSpellResult::make_valid();
169 }
170
171 /*!
172  * @brief BシンボルのRF6_SPECIALの処理。投げ落とす攻撃。 /
173  * @param player_ptr プレイヤーへの参照ポインタ
174  * @param y 対象の地点のy座標
175  * @param x 対象の地点のx座標
176  * @param m_idx 呪文を唱えるモンスターID
177  * @param t_idx 呪文を受けるモンスターID。プレイヤーの場合はdummyで0とする。
178  * @param target_type プレイヤーを対象とする場合MONSTER_TO_PLAYER、モンスターを対象とする場合MONSTER_TO_MONSTER
179  */
180 static MonsterSpellResult spell_RF6_SPECIAL_B(PlayerType *player_ptr, POSITION y, POSITION x, MONSTER_IDX m_idx, MONSTER_IDX t_idx, int target_type)
181 {
182     mspell_cast_msg_simple msg;
183     auto *floor_ptr = player_ptr->current_floor_ptr;
184     auto *m_ptr = &floor_ptr->m_list[m_idx];
185     MonsterEntity *t_ptr = &floor_ptr->m_list[t_idx];
186     MonsterRaceInfo *tr_ptr = &t_ptr->get_monrace();
187     bool monster_to_player = (target_type == MONSTER_TO_PLAYER);
188     bool monster_to_monster = (target_type == MONSTER_TO_MONSTER);
189     bool direct = player_ptr->is_located_at({ y, x });
190     const auto m_name = monster_name(player_ptr, m_idx);
191
192     disturb(player_ptr, true, true);
193     if (one_in_(3) || !direct) {
194         msg.to_player = _("%s^は突然視界から消えた!", "You lose sight of %s!");
195         msg.to_mons = _("%s^は突然急上昇して視界から消えた!", "You lose sight of %s!");
196
197         simple_monspell_message(player_ptr, m_idx, t_idx, msg, target_type);
198
199         teleport_away(player_ptr, m_idx, 10, TELEPORT_NONMAGICAL);
200         RedrawingFlagsUpdater::get_instance().set_flag(StatusRecalculatingFlag::MONSTER_STATUSES);
201         return MonsterSpellResult::make_valid();
202     }
203
204     if (direct) {
205         sound(SOUND_FALL);
206     }
207
208     msg.to_player = _("%s^があなたを掴んで空中から投げ落とした。", "%s^ snatches you, soars into the sky, and drops you.");
209     msg.to_mons = _("%s^が%sを掴んで空中から投げ落とした。", "%s^ snatches %s, soars into the sky, and releases its grip.");
210
211     simple_monspell_message(player_ptr, m_idx, t_idx, msg, target_type);
212
213     bool fear, dead; /* dummy */
214     int dam = damroll(4, 8);
215
216     if (monster_to_player || t_idx == player_ptr->riding) {
217         teleport_player_to(player_ptr, m_ptr->fy, m_ptr->fx, i2enum<teleport_flags>(TELEPORT_NONMAGICAL | TELEPORT_PASSIVE));
218     } else {
219         teleport_monster_to(player_ptr, t_idx, m_ptr->fy, m_ptr->fx, 100, i2enum<teleport_flags>(TELEPORT_NONMAGICAL | TELEPORT_PASSIVE));
220     }
221
222     if ((monster_to_player && player_ptr->levitation) || (monster_to_monster && tr_ptr->feature_flags.has(MonsterFeatureType::CAN_FLY))) {
223         msg.to_player = _("あなたは静かに着地した。", "You float gently down to the ground.");
224         msg.to_mons = _("%s^は静かに着地した。", "%s^ floats gently down to the ground.");
225     } else {
226         msg.to_player = _("あなたは地面に叩きつけられた。", "You crashed into the ground.");
227         msg.to_mons = _("%s^は地面に叩きつけられた。", "%s^ crashed into the ground.");
228     }
229
230     simple_monspell_message(player_ptr, m_idx, t_idx, msg, target_type);
231     dam += damroll(6, 8);
232
233     if (monster_to_player || (monster_to_monster && player_ptr->riding == t_idx)) {
234         int get_damage = take_hit(player_ptr, DAMAGE_NOESCAPE, dam, m_name);
235         if (player_ptr->tim_eyeeye && get_damage > 0 && !player_ptr->is_dead) {
236             const auto m_name_self = monster_desc(player_ptr, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE | MD_OBJECTIVE);
237             msg_print(_(format("攻撃が%s自身を傷つけた!", m_name.data()), format("The attack of %s has wounded %s!", m_name.data(), m_name_self.data())));
238             project(player_ptr, 0, 0, m_ptr->fy, m_ptr->fx, get_damage, AttributeType::MISSILE, PROJECT_KILL);
239             set_tim_eyeeye(player_ptr, player_ptr->tim_eyeeye - 5, true);
240         }
241     }
242
243     if (monster_to_player && player_ptr->riding) {
244         const auto &m_ref = floor_ptr->m_list[player_ptr->riding];
245         mon_take_hit_mon(player_ptr, player_ptr->riding, dam, &dead, &fear, m_ref.get_died_message(), m_idx);
246     }
247
248     if (monster_to_monster) {
249         mon_take_hit_mon(player_ptr, t_idx, dam, &dead, &fear, t_ptr->get_died_message(), m_idx);
250     }
251
252     return MonsterSpellResult::make_valid();
253 }
254
255 /*!
256  * @brief RF6_SPECIALの処理。モンスターの種類によって実処理に振り分ける。 /
257  * @param player_ptr プレイヤーへの参照ポインタ
258  * @param y 対象の地点のy座標
259  * @param x 対象の地点のx座標
260  * @param m_idx 呪文を唱えるモンスターID
261  * @param t_idx 呪文を受けるモンスターID。プレイヤーの場合はdummyで0とする。
262  * @param target_type プレイヤーを対象とする場合MONSTER_TO_PLAYER、モンスターを対象とする場合MONSTER_TO_MONSTER
263  *
264  * ラーニング不可。
265  */
266 MonsterSpellResult spell_RF6_SPECIAL(PlayerType *player_ptr, POSITION y, POSITION x, MONSTER_IDX m_idx, MONSTER_IDX t_idx, int target_type)
267 {
268     const auto &floor = *player_ptr->current_floor_ptr;
269     const auto &monster = floor.m_list[m_idx];
270     const auto &monrace = monster.get_monrace();
271     const auto r_idx = monster.r_idx;
272     if (MonraceList::get_instance().can_unify_separate(r_idx)) {
273         return spell_RF6_SPECIAL_UNIFICATION(player_ptr, m_idx);
274     }
275
276     switch (r_idx) {
277     case MonsterRaceId::OHMU:
278         return MonsterSpellResult::make_invalid();
279     case MonsterRaceId::ROLENTO:
280         return spell_RF6_SPECIAL_ROLENTO(player_ptr, y, x, m_idx, t_idx, target_type);
281     default:
282         if (monrace.d_char == 'B') {
283             return spell_RF6_SPECIAL_B(player_ptr, y, x, m_idx, t_idx, target_type);
284         }
285
286         return MonsterSpellResult::make_invalid();
287     }
288 }