OSDN Git Service

7ec001f64f5800ae7f0914d4e72fc6d32ccb7413
[hengbandforosx/hengbandosx.git] / src / wizard / wizard-spells.cpp
1 /*!
2  * @brief ウィザードモード専用のスペル処理
3  * @date 2020/06/27
4  * @author Hourier
5  */
6
7 #include "wizard/wizard-spells.h"
8 #include "blue-magic/blue-magic-checker.h"
9 #include "core/asking-player.h"
10 #include "effect/effect-characteristics.h"
11 #include "effect/effect-processor.h"
12 #include "floor/cave.h"
13 #include "floor/floor-util.h"
14 #include "floor/pattern-walk.h"
15 #include "io/gf-descriptions.h"
16 #include "mind/mind-blue-mage.h"
17 #include "monster-floor/monster-generator.h"
18 #include "monster-floor/monster-summon.h"
19 #include "monster-floor/place-monster-types.h"
20 #include "monster-race/monster-race.h"
21 #include "monster-race/race-ability-flags.h"
22 #include "monster-race/race-indice-types.h"
23 #include "mutation/mutation-processor.h"
24 #include "object-activation/activation-others.h"
25 #include "player-base/player-class.h"
26 #include "player-info/bluemage-data-type.h"
27 #include "player-info/smith-data-type.h"
28 #include "smith/object-smith.h"
29 #include "spell-kind/spells-launcher.h"
30 #include "spell-kind/spells-random.h"
31 #include "spell-kind/spells-teleport.h"
32 #include "spell-realm/spells-chaos.h"
33 #include "spell/spells-status.h"
34 #include "spell/summon-types.h"
35 #include "system/floor-type-definition.h"
36 #include "system/monster-race-info.h"
37 #include "system/player-type-definition.h"
38 #include "target/grid-selector.h"
39 #include "target/target-checker.h"
40 #include "target/target-getter.h"
41 #include "term/screen-processor.h"
42 #include "util/enum-converter.h"
43 #include "util/flag-group.h"
44 #include "view/display-messages.h"
45 #include "wizard/wizard-messages.h"
46 #include <string_view>
47 #include <vector>
48
49 static const std::vector<debug_spell_command> debug_spell_commands_list = {
50     { 2, "vanish dungeon", { .spell2 = { vanish_dungeon } } },
51     { 2, "unique detection", { .spell2 = { activate_unique_detection } } },
52     { 3, "true healing", { .spell3 = { true_healing } } },
53     { 2, "drop weapons", { .spell2 = { drop_weapons } } },
54     { 4, "ty curse", { .spell4 = { activate_ty_curse } } },
55     { 5, "pattern teleport", { .spell5 = { pattern_teleport } } },
56 };
57
58 /*!
59  * @brief コマンド入力により任意にスペル効果を起こす / Wizard spells
60  * @param player_ptr プレイヤーへの参照ポインタ
61  */
62 void wiz_debug_spell(PlayerType *player_ptr)
63 {
64     const auto spell = input_string("SPELL: ", 50);
65     if (!spell) {
66         return;
67     }
68
69     for (const auto &d : debug_spell_commands_list) {
70         if (*spell != d.command_name) {
71             continue;
72         }
73
74         switch (d.type) {
75         case 2:
76             (d.command_function.spell2.spell_function)(player_ptr);
77             return;
78         case 3: {
79             const auto power = input_integer("POWER", -MAX_INT, MAX_INT);
80             if (!power) {
81                 return;
82             }
83
84             (d.command_function.spell3.spell_function)(player_ptr, *power);
85             return;
86         }
87         case 4: {
88             auto count = 0;
89             (d.command_function.spell4.spell_function)(player_ptr, true, &count);
90             return;
91         }
92         case 5:
93             (d.command_function.spell5.spell_function)(player_ptr);
94             return;
95         default:
96             msg_format("Command not found.");
97             return;
98         }
99     }
100 }
101
102 /*!
103  * @brief 必ず成功するウィザードモード用次元の扉処理 / Wizard Dimension Door
104  * @param player_ptr プレイヤーへの参照ポインタ
105  */
106 void wiz_dimension_door(PlayerType *player_ptr)
107 {
108     POSITION x = 0, y = 0;
109     if (!tgt_pt(player_ptr, &x, &y)) {
110         return;
111     }
112
113     teleport_player_to(player_ptr, y, x, TELEPORT_NONMAGICAL);
114 }
115
116 /*!
117  * @brief ウィザードモード用モンスターの群れ生成 / Summon a horde of monsters
118  * @param player_ptr プレイヤーへの参照ポインタ
119  */
120 void wiz_summon_horde(PlayerType *player_ptr)
121 {
122     POSITION wy = player_ptr->y, wx = player_ptr->x;
123     int attempts = 1000;
124
125     while (--attempts) {
126         scatter(player_ptr, &wy, &wx, player_ptr->y, player_ptr->x, 3, PROJECT_NONE);
127         if (is_cave_empty_bold(player_ptr, wy, wx)) {
128             break;
129         }
130     }
131
132     (void)alloc_horde(player_ptr, wy, wx, summon_specific);
133 }
134
135 /*!
136  * @brief ウィザードモード用処理としてターゲット中の相手をテレポートバックする / Hack -- Teleport to the target
137  */
138 void wiz_teleport_back(PlayerType *player_ptr)
139 {
140     if (!target_who) {
141         return;
142     }
143
144     teleport_player_to(player_ptr, target_row, target_col, TELEPORT_NONMAGICAL);
145 }
146
147 /*!
148  * @brief 青魔導師の魔法を全て習得済みにする /
149  * debug command for blue mage
150  */
151 void wiz_learn_blue_magic_all(PlayerType *player_ptr)
152 {
153     auto bluemage_data = PlayerClass(player_ptr).get_specific_data<bluemage_data_type>();
154     if (!bluemage_data) {
155         return;
156     }
157
158     for (auto type : BLUE_MAGIC_TYPE_LIST) {
159         EnumClassFlagGroup<MonsterAbilityType> ability_flags;
160         set_rf_masks(ability_flags, type);
161         bluemage_data->learnt_blue_magics.set(ability_flags);
162     }
163 }
164
165 /*!
166  * @brief 鍛冶師の全てのエッセンスを最大所持量にする
167  */
168 void wiz_fillup_all_smith_essences(PlayerType *player_ptr)
169 {
170     auto smith_data = PlayerClass(player_ptr).get_specific_data<smith_data_type>();
171     if (!smith_data) {
172         return;
173     }
174
175     for (auto essence : Smith::get_essence_list()) {
176         smith_data->essences[essence] = Smith::ESSENCE_AMOUNT_MAX;
177     }
178 }
179
180 /*!
181  * @brief 現在のフロアに合ったモンスターをランダムに生成する
182  * @param player_ptr プレイヤーへの参照ポインタ
183  * @param num 生成処理回数
184  * @details 半径5マス以内に生成する。生成場所がなかったらキャンセル。
185  */
186 void wiz_generate_random_monster(PlayerType *player_ptr, int num)
187 {
188     constexpr auto flags = PM_ALLOW_SLEEP | PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_QUEST;
189     for (auto i = 0; i < num; i++) {
190         if (!alloc_monster(player_ptr, 0, flags, summon_specific, 5)) {
191             msg_print_wizard(player_ptr, 1, "Monster isn't generated correctly...");
192             return;
193         }
194     }
195 }
196
197 /*!
198  * @brief 現在のフロアに合ったモンスターをランダムに召喚する
199  * @param player_ptr プレイヤーへの参照ポインタ
200  * @param num 生成処理回数
201  * @details 現在のレベル+5F からランダムに選定する。生成場所がなかったらキャンセル。
202  */
203 void wiz_summon_random_monster(PlayerType *player_ptr, int num)
204 {
205     const auto level = player_ptr->current_floor_ptr->dun_level;
206     constexpr auto flags = PM_ALLOW_GROUP | PM_ALLOW_UNIQUE;
207     const auto y = player_ptr->y;
208     const auto x = player_ptr->x;
209     for (auto i = 0; i < num; i++) {
210         if (!summon_specific(player_ptr, 0, y, x, level, SUMMON_NONE, flags)) {
211             msg_print_wizard(player_ptr, 1, "Monster isn't summoned correctly...");
212             return;
213         }
214     }
215 }
216
217 /*!
218  * @brief モンスターを種族IDを指定して自然生成と同じように召喚する /
219  * Summon a creature of the specified type
220  * @param r_idx モンスター種族ID(回数指定コマンド'0'で指定した回数がIDになる)
221  * @details
222  * This function is rather dangerous
223  */
224 void wiz_summon_specific_monster(PlayerType *player_ptr, MonsterRaceId r_idx)
225 {
226     if (!MonsterRace(r_idx).is_valid()) {
227         const auto new_monrace_id = input_numerics("MonsterID", 1, monraces_info.size() - 1, MonsterRaceId::FILTHY_URCHIN);
228         if (!new_monrace_id) {
229             return;
230         }
231
232         r_idx = *new_monrace_id;
233     }
234
235     (void)summon_named_creature(player_ptr, 0, player_ptr->y, player_ptr->x, r_idx, PM_ALLOW_SLEEP | PM_ALLOW_GROUP);
236 }
237
238 /*!
239  * @brief モンスターを種族IDを指定してペット召喚する /
240  * Summon a creature of the specified type
241  * @param r_idx モンスター種族ID(回数指定コマンド'0'で指定した回数がIDになる)
242  * @details
243  * This function is rather dangerous
244  */
245 void wiz_summon_pet(PlayerType *player_ptr, MonsterRaceId r_idx)
246 {
247     if (!MonsterRace(r_idx).is_valid()) {
248         const auto new_monrace_id = input_numerics("MonsterID", 1, monraces_info.size() - 1, MonsterRaceId::FILTHY_URCHIN);
249         if (!new_monrace_id) {
250             return;
251         }
252
253         r_idx = *new_monrace_id;
254     }
255
256     (void)summon_named_creature(player_ptr, 0, player_ptr->y, player_ptr->x, r_idx, PM_ALLOW_SLEEP | PM_ALLOW_GROUP | PM_FORCE_PET);
257 }
258
259 /*!
260  * @brief モンスターを種族IDを指定してクローン召喚(口寄せ)する /
261  * Summon a creature of the specified type
262  * @param r_idx モンスター種族ID(回数指定コマンド'0'で指定した回数がIDになる)
263  */
264 void wiz_summon_clone(PlayerType *player_ptr, MonsterRaceId r_idx)
265 {
266     if (!MonsterRace(r_idx).is_valid()) {
267         const auto new_monrace_id = input_numerics("MonsterID", 1, monraces_info.size() - 1, MonsterRaceId::FILTHY_URCHIN);
268         if (!new_monrace_id) {
269             return;
270         }
271
272         r_idx = *new_monrace_id;
273     }
274
275     (void)summon_named_creature(player_ptr, 0, player_ptr->y, player_ptr->x, r_idx, PM_ALLOW_SLEEP | PM_ALLOW_GROUP | PM_CLONE);
276 }
277
278 /*!
279  * @brief ターゲットを指定して指定ダメージ・指定属性・半径0のボールを放つ
280  * @param dam ダメージ量
281  * @param effect_idx 属性ID
282  * @param self 自分に与えるか否か
283  * @details デフォルトは100万・GF_ARROW(射撃)。RES_ALL持ちも一撃で殺せる。
284  */
285 void wiz_kill_target(PlayerType *player_ptr, int initial_dam, AttributeType effect_idx, const bool self)
286 {
287     auto dam = initial_dam;
288     if (dam <= 0) {
289         const auto input_dam = input_integer("Damage", 1, 1000000, 1000000);
290         if (!input_dam) {
291             return;
292         }
293
294         dam = *input_dam;
295     }
296
297     constexpr auto max = enum2i(AttributeType::MAX);
298     auto idx = effect_idx;
299     if (effect_idx == AttributeType::NONE) {
300         screen_save();
301         for (auto i = 1; i <= 23; i++) {
302             prt("", i, 0);
303         }
304
305         for (auto i = 0U; i < std::size(gf_descriptions); ++i) {
306             const auto &gf_description = gf_descriptions[i];
307             auto name = std::string_view(gf_description.name).substr(3); // 先頭の"GF_"を取り除く
308             auto num = enum2i(gf_description.num);
309             put_str(format("%03d:%-.10s^", num, name.data()), 1 + i / 5, 1 + (i % 5) * 16);
310         }
311
312         const auto input_effect_id = input_numerics("EffectID", 1, max - 1, idx);
313         if (!input_effect_id) {
314             screen_load();
315             return;
316         }
317
318         idx = *input_effect_id;
319         screen_load();
320     }
321
322     if (self) {
323         project(player_ptr, -1, 0, player_ptr->y, player_ptr->x, dam, idx, PROJECT_KILL | PROJECT_PLAYER);
324         return;
325     }
326
327     DIRECTION dir;
328     if (!get_aim_dir(player_ptr, &dir)) {
329         return;
330     }
331     fire_ball(player_ptr, idx, dir, dam, 0);
332 }