OSDN Git Service

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