OSDN Git Service

[Refactor] Grid::has_monster()の定義
[hengbandforosx/hengbandosx.git] / src / action / mutation-execution.cpp
1 /*!
2  * @file mutation-execution.cpp
3  * @brief プレイヤーの変異能力実行定義
4  */
5
6 #include "action/mutation-execution.h"
7 #include "cmd-item/cmd-throw.h"
8 #include "core/asking-player.h"
9 #include "dungeon/quest.h"
10 #include "effect/attribute-types.h"
11 #include "effect/spells-effect-util.h"
12 #include "floor/geometry.h"
13 #include "game-option/play-record-options.h"
14 #include "inventory/inventory-slot-types.h"
15 #include "io/write-diary.h"
16 #include "mind/mind-mage.h"
17 #include "mind/mind-warrior.h"
18 #include "monster-floor/monster-remover.h"
19 #include "monster-floor/monster-summon.h"
20 #include "monster-floor/place-monster-types.h"
21 #include "monster-race/monster-race.h"
22 #include "monster/monster-describer.h"
23 #include "monster/monster-description-types.h"
24 #include "monster/monster-flag-types.h"
25 #include "monster/monster-info.h"
26 #include "mutation/mutation-flag-types.h"
27 #include "mutation/mutation-techniques.h"
28 #include "object-enchant/item-feeling.h"
29 #include "player-info/self-info.h"
30 #include "player-status/player-energy.h"
31 #include "player/player-damage.h"
32 #include "player/player-status.h"
33 #include "racial/racial-vampire.h"
34 #include "spell-kind/earthquake.h"
35 #include "spell-kind/spells-charm.h"
36 #include "spell-kind/spells-detection.h"
37 #include "spell-kind/spells-fetcher.h"
38 #include "spell-kind/spells-launcher.h"
39 #include "spell-kind/spells-lite.h"
40 #include "spell-kind/spells-sight.h"
41 #include "spell-kind/spells-teleport.h"
42 #include "spell-kind/spells-world.h"
43 #include "spell-realm/spells-sorcery.h"
44 #include "spell/spells-status.h"
45 #include "spell/summon-types.h"
46 #include "status/element-resistance.h"
47 #include "status/shape-changer.h"
48 #include "system/floor-type-definition.h"
49 #include "system/grid-type-definition.h"
50 #include "system/item-entity.h"
51 #include "system/monster-entity.h"
52 #include "system/monster-race-info.h"
53 #include "system/player-type-definition.h"
54 #include "target/target-getter.h"
55 #include "util/bit-flags-calculator.h"
56 #include "view/display-messages.h"
57
58 /*!
59  * @brief 突然変異のレイシャル効果実装
60  * @param player_ptr プレイヤーへの参照ポインタ
61  * @param power 発動させる突然変異レイシャルのID
62  * @return レイシャルを実行した場合TRUE、キャンセルした場合FALSEを返す
63  */
64 bool exe_mutation_power(PlayerType *player_ptr, PlayerMutationType power)
65 {
66     DIRECTION dir = 0;
67     PLAYER_LEVEL lvl = player_ptr->lev;
68     auto &floor = *player_ptr->current_floor_ptr;
69     switch (power) {
70     case PlayerMutationType::SPIT_ACID:
71         if (!get_aim_dir(player_ptr, &dir)) {
72             return false;
73         }
74
75         stop_mouth(player_ptr);
76         msg_print(_("酸を吐きかけた...", "You spit acid..."));
77         fire_ball(player_ptr, AttributeType::ACID, dir, lvl, 1 + (lvl / 30));
78         return true;
79     case PlayerMutationType::BR_FIRE:
80         if (!get_aim_dir(player_ptr, &dir)) {
81             return false;
82         }
83
84         stop_mouth(player_ptr);
85         msg_print(_("あなたは火炎のブレスを吐いた...", "You breathe fire..."));
86         fire_breath(player_ptr, AttributeType::FIRE, dir, lvl * 2, 1 + (lvl / 20));
87         return true;
88     case PlayerMutationType::HYPN_GAZE:
89         if (!get_aim_dir(player_ptr, &dir)) {
90             return false;
91         }
92
93         msg_print(_("あなたの目は幻惑的になった...", "Your eyes look mesmerizing..."));
94         (void)charm_monster(player_ptr, dir, lvl);
95         return true;
96     case PlayerMutationType::TELEKINES:
97         if (!get_aim_dir(player_ptr, &dir)) {
98             return false;
99         }
100
101         msg_print(_("集中している...", "You concentrate..."));
102         fetch_item(player_ptr, dir, lvl * 10, true);
103         return true;
104     case PlayerMutationType::VTELEPORT:
105         msg_print(_("集中している...", "You concentrate..."));
106         teleport_player(player_ptr, 10 + 4 * lvl, TELEPORT_SPONTANEOUS);
107         return true;
108     case PlayerMutationType::MIND_BLST:
109         if (!get_aim_dir(player_ptr, &dir)) {
110             return false;
111         }
112
113         msg_print(_("集中している...", "You concentrate..."));
114         fire_bolt(player_ptr, AttributeType::PSI, dir, damroll(3 + ((lvl - 1) / 5), 3));
115         return true;
116     case PlayerMutationType::RADIATION:
117         msg_print(_("体から放射能が発生した!", "Radiation flows from your body!"));
118         fire_ball(player_ptr, AttributeType::NUKE, 0, (lvl * 2), 3 + (lvl / 20));
119         return true;
120     case PlayerMutationType::VAMPIRISM:
121         vampirism(player_ptr);
122         return true;
123     case PlayerMutationType::SMELL_MET:
124         stop_mouth(player_ptr);
125         (void)detect_treasure(player_ptr, DETECT_RAD_DEFAULT);
126         return true;
127     case PlayerMutationType::SMELL_MON:
128         stop_mouth(player_ptr);
129         (void)detect_monsters_normal(player_ptr, DETECT_RAD_DEFAULT);
130         return true;
131     case PlayerMutationType::BLINK:
132         teleport_player(player_ptr, 10, TELEPORT_SPONTANEOUS);
133         return true;
134     case PlayerMutationType::EAT_ROCK:
135         return eat_rock(player_ptr);
136     case PlayerMutationType::SWAP_POS:
137         project_length = -1;
138         if (!get_aim_dir(player_ptr, &dir)) {
139             project_length = 0;
140             return false;
141         }
142
143         (void)teleport_swap(player_ptr, dir);
144         project_length = 0;
145         return true;
146     case PlayerMutationType::SHRIEK:
147         stop_mouth(player_ptr);
148         (void)fire_ball(player_ptr, AttributeType::SOUND, 0, 2 * lvl, 8);
149         (void)aggravate_monsters(player_ptr, 0);
150         return true;
151     case PlayerMutationType::ILLUMINE:
152         (void)lite_area(player_ptr, damroll(2, (lvl / 2)), (lvl / 10) + 1);
153         return true;
154     case PlayerMutationType::DET_CURSE:
155         for (int i = 0; i < INVEN_TOTAL; i++) {
156             auto *o_ptr = &player_ptr->inventory_list[i];
157             if (!o_ptr->is_valid() || !o_ptr->is_cursed()) {
158                 continue;
159             }
160
161             o_ptr->feeling = FEEL_CURSED;
162         }
163
164         return true;
165     case PlayerMutationType::BERSERK:
166         (void)berserk(player_ptr, randint1(25) + 25);
167         return true;
168     case PlayerMutationType::POLYMORPH:
169         if (!input_check(_("変身します。よろしいですか?", "You will polymorph your self. Are you sure? "))) {
170             return false;
171         }
172
173         do_poly_self(player_ptr);
174         return true;
175     case PlayerMutationType::MIDAS_TCH:
176         return alchemy(player_ptr);
177     case PlayerMutationType::GROW_MOLD:
178         for (DIRECTION i = 0; i < 8; i++) {
179             summon_specific(player_ptr, -1, player_ptr->y, player_ptr->x, lvl, SUMMON_MOLD, PM_FORCE_PET);
180         }
181
182         return true;
183     case PlayerMutationType::RESIST: {
184         int num = lvl / 10;
185         TIME_EFFECT dur = randint1(20) + 20;
186         if (randint0(5) < num) {
187             (void)set_oppose_acid(player_ptr, dur, false);
188             num--;
189         }
190
191         if (randint0(4) < num) {
192             (void)set_oppose_elec(player_ptr, dur, false);
193             num--;
194         }
195
196         if (randint0(3) < num) {
197             (void)set_oppose_fire(player_ptr, dur, false);
198             num--;
199         }
200
201         if (randint0(2) < num) {
202             (void)set_oppose_cold(player_ptr, dur, false);
203             num--;
204         }
205
206         if (num != 0) {
207             (void)set_oppose_pois(player_ptr, dur, false);
208             num--;
209         }
210
211         return true;
212     }
213     case PlayerMutationType::EARTHQUAKE:
214         (void)earthquake(player_ptr, player_ptr->y, player_ptr->x, 10, 0);
215         return true;
216     case PlayerMutationType::EAT_MAGIC:
217         return eat_magic(player_ptr, player_ptr->lev * 2);
218     case PlayerMutationType::WEIGH_MAG:
219         report_magics(player_ptr);
220         return true;
221     case PlayerMutationType::STERILITY:
222         msg_print(_("突然頭が痛くなった!", "You suddenly have a headache!"));
223         take_hit(player_ptr, DAMAGE_LOSELIFE, randint1(17) + 17, _("禁欲を強いた疲労", "the strain of forcing abstinence"));
224         floor.num_repro += MAX_REPRODUCTION;
225         return true;
226     case PlayerMutationType::HIT_AND_AWAY:
227         return hit_and_away(player_ptr);
228     case PlayerMutationType::DAZZLE:
229         stun_monsters(player_ptr, lvl * 4);
230         confuse_monsters(player_ptr, lvl * 4);
231         turn_monsters(player_ptr, lvl * 4);
232         return true;
233     case PlayerMutationType::LASER_EYE:
234         if (!get_aim_dir(player_ptr, &dir)) {
235             return false;
236         }
237
238         fire_beam(player_ptr, AttributeType::LITE, dir, 2 * lvl);
239         return true;
240     case PlayerMutationType::RECALL:
241         return recall_player(player_ptr, randint0(21) + 15);
242     case PlayerMutationType::BANISH: {
243         if (!get_direction(player_ptr, &dir)) {
244             return false;
245         }
246
247         const auto y = player_ptr->y + ddy[dir];
248         const auto x = player_ptr->x + ddx[dir];
249         const auto &grid = floor.grid_array[y][x];
250         if (!grid.has_monster()) {
251             msg_print(_("邪悪な存在を感じとれません!", "You sense no evil there!"));
252             return true;
253         }
254
255         auto &monster = floor.m_list[grid.m_idx];
256         const auto &monrace = monster.get_monrace();
257         auto can_banish = monrace.kind_flags.has(MonsterKindType::EVIL);
258         can_banish &= monrace.misc_flags.has_not(MonsterMiscType::QUESTOR);
259         can_banish &= monrace.kind_flags.has_not(MonsterKindType::UNIQUE);
260         can_banish &= !floor.inside_arena;
261         can_banish &= !floor.is_in_quest();
262         can_banish &= (monrace.level < randint1(player_ptr->lev + 50));
263         can_banish &= monster.mflag2.has_not(MonsterConstantFlagType::NOGENO);
264         if (can_banish) {
265             if (record_named_pet && monster.is_named_pet()) {
266                 const auto m_name = monster_desc(player_ptr, &monster, MD_INDEF_VISIBLE);
267                 exe_write_diary(player_ptr, DiaryKind::NAMED_PET, RECORD_NAMED_PET_GENOCIDE, m_name);
268             }
269
270             delete_monster_idx(player_ptr, grid.m_idx);
271             msg_print(_("その邪悪なモンスターは硫黄臭い煙とともに消え去った!", "The evil creature vanishes in a puff of sulfurous smoke!"));
272             return true;
273         }
274
275         msg_print(_("祈りは効果がなかった!", "Your invocation is ineffectual!"));
276         if (one_in_(13)) {
277             monster.mflag2.set(MonsterConstantFlagType::NOGENO);
278         }
279
280         return true;
281     }
282     case PlayerMutationType::COLD_TOUCH: {
283         if (!get_direction(player_ptr, &dir)) {
284             return false;
285         }
286
287         const auto y = player_ptr->y + ddy[dir];
288         const auto x = player_ptr->x + ddx[dir];
289         auto &grid = floor.grid_array[y][x];
290         if (!grid.has_monster()) {
291             msg_print(_("あなたは何もない場所で手を振った。", "You wave your hands in the air."));
292             return true;
293         }
294
295         fire_bolt(player_ptr, AttributeType::COLD, dir, 2 * lvl);
296         return true;
297     }
298     case PlayerMutationType::LAUNCHER:
299         return ThrowCommand(player_ptr).do_cmd_throw(2 + lvl / 40, false, -1);
300     default:
301         PlayerEnergy(player_ptr).reset_player_turn();
302         msg_format(_("能力 PlayerMutationType::%d は実装されていません。", "Power PlayerMutationType::%d not implemented. Oops."), enum2i(power));
303         return true;
304     }
305 }