OSDN Git Service

Merge pull request #2013 from sikabane-works/release/3.0.0Alpha51
[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 "mind/mind-blue-mage.h"
16 #include "monster-floor/monster-generator.h"
17 #include "monster-floor/monster-summon.h"
18 #include "monster-floor/place-monster-types.h"
19 #include "monster-race/race-ability-flags.h"
20 #include "monster-race/monster-race.h"
21 #include "mutation/mutation-processor.h"
22 #include "object-enchant/object-smith.h"
23 #include "player-base/player-class.h"
24 #include "player-info/bluemage-data-type.h"
25 #include "player-info/smith-data-type.h"
26 #include "spell-kind/spells-launcher.h"
27 #include "spell-kind/spells-random.h"
28 #include "spell-kind/spells-teleport.h"
29 #include "spell-realm/spells-chaos.h"
30 #include "spell/spells-status.h"
31 #include "spell/summon-types.h"
32 #include "system/floor-type-definition.h"
33 #include "system/player-type-definition.h"
34 #include "system/monster-race-definition.h"
35 #include "target/grid-selector.h"
36 #include "target/target-checker.h"
37 #include "target/target-getter.h"
38 #include "util/enum-converter.h"
39 #include "util/flag-group.h"
40 #include "view/display-messages.h"
41
42 #include <vector>
43
44 debug_spell_command debug_spell_commands_list[SPELL_MAX] = {
45     { 2, "vanish dungeon", { .spell2 = { vanish_dungeon } } },
46     { 3, "true healing", { .spell3 = { true_healing } } },
47     { 2, "drop weapons", { .spell2 = { drop_weapons } } },
48     { 4, "ty curse", { .spell4 = { activate_ty_curse } } },
49     { 5, "pattern teleport", { .spell5 = { pattern_teleport } } },
50 };
51
52 /*!
53  * @brief コマンド入力により任意にスペル効果を起こす / Wizard spells
54  * @return 実際にテレポートを行ったらTRUEを返す
55  */
56 bool wiz_debug_spell(PlayerType *player_ptr)
57 {
58     char tmp_val[50] = "\0";
59     int tmp_int;
60
61     if (!get_string("SPELL: ", tmp_val, 32))
62         return false;
63
64     for (int i = 0; i < SPELL_MAX; i++) {
65         if (strcmp(tmp_val, debug_spell_commands_list[i].command_name) != 0)
66             continue;
67
68         switch (debug_spell_commands_list[i].type) {
69         case 2:
70             (*(debug_spell_commands_list[i].command_function.spell2.spell_function))(player_ptr);
71             return true;
72             break;
73         case 3:
74             tmp_val[0] = '\0';
75             if (!get_string("POWER:", tmp_val, 32))
76                 return false;
77             tmp_int = atoi(tmp_val);
78             (*(debug_spell_commands_list[i].command_function.spell3.spell_function))(player_ptr, tmp_int);
79             return true;
80             break;
81         case 4:
82             (*(debug_spell_commands_list[i].command_function.spell4.spell_function))(player_ptr, true, &tmp_int);
83             return true;
84             break;
85         case 5:
86             (*(debug_spell_commands_list[i].command_function.spell5.spell_function))(player_ptr);
87             return true;
88             break;
89         default:
90             break;
91         }
92     }
93
94     msg_format("Command not found.");
95     return false;
96 }
97
98 /*!
99  * @brief 必ず成功するウィザードモード用次元の扉処理 / Wizard Dimension Door
100  * @param player_ptr プレイヤーへの参照ポインタ
101  */
102 void wiz_dimension_door(PlayerType *player_ptr)
103 {
104     POSITION x = 0, y = 0;
105     if (!tgt_pt(player_ptr, &x, &y))
106         return;
107
108     teleport_player_to(player_ptr, y, x, TELEPORT_NONMAGICAL);
109 }
110
111 /*!
112  * @brief ウィザードモード用モンスターの群れ生成 / Summon a horde of monsters
113  * @param player_ptr プレイヤーへの参照ポインタ
114  */
115 void wiz_summon_horde(PlayerType *player_ptr)
116 {
117     POSITION wy = player_ptr->y, wx = player_ptr->x;
118     int attempts = 1000;
119
120     while (--attempts) {
121         scatter(player_ptr, &wy, &wx, player_ptr->y, player_ptr->x, 3, PROJECT_NONE);
122         if (is_cave_empty_bold(player_ptr, wy, wx))
123             break;
124     }
125
126     (void)alloc_horde(player_ptr, wy, wx, summon_specific);
127 }
128
129 /*!
130  * @brief ウィザードモード用処理としてターゲット中の相手をテレポートバックする / Hack -- Teleport to the target
131  */
132 void wiz_teleport_back(PlayerType *player_ptr)
133 {
134     if (!target_who)
135         return;
136
137     teleport_player_to(player_ptr, target_row, target_col, TELEPORT_NONMAGICAL);
138 }
139
140 /*!
141  * @brief 青魔導師の魔法を全て習得済みにする /
142  * debug command for blue mage
143  */
144 void wiz_learn_blue_magic_all(PlayerType *player_ptr)
145 {
146     auto bluemage_data = PlayerClass(player_ptr).get_specific_data<bluemage_data_type>();
147     if (!bluemage_data) {
148         return;
149     }
150
151     for (auto type : BLUE_MAGIC_TYPE_LIST) {
152         EnumClassFlagGroup<MonsterAbilityType> ability_flags;
153         set_rf_masks(ability_flags, type);
154         bluemage_data->learnt_blue_magics.set(ability_flags);
155     }
156 }
157
158 /*!
159  * @brief 鍛冶師の全てのエッセンスを最大所持量にする
160  */
161 void wiz_fillup_all_smith_essences(PlayerType *player_ptr)
162 {
163     auto smith_data = PlayerClass(player_ptr).get_specific_data<smith_data_type>();
164     if (!smith_data) {
165         return;
166     }
167
168     for (auto essence : Smith::get_essence_list()) {
169         smith_data->essences[essence] = Smith::ESSENCE_AMOUNT_MAX;
170     }
171 }
172
173 /*!
174  * @brief 現在のフロアに合ったモンスターをランダムに召喚する /
175  * Summon some creatures
176  * @param player_ptr プレイヤーへの参照ポインタ
177  * @param num 生成処理回数
178  */
179 void wiz_summon_random_enemy(PlayerType *player_ptr, int num)
180 {
181     for (int i = 0; i < num; i++)
182         (void)summon_specific(player_ptr, 0, player_ptr->y, player_ptr->x, player_ptr->current_floor_ptr->dun_level, SUMMON_NONE, PM_ALLOW_GROUP | PM_ALLOW_UNIQUE);
183 }
184
185 /*!
186  * @brief モンスターを種族IDを指定して自然生成と同じように召喚する /
187  * Summon a creature of the specified type
188  * @param r_idx モンスター種族ID(回数指定コマンド'0'で指定した回数がIDになる)
189  * @details
190  * This function is rather dangerous
191  */
192 void wiz_summon_specific_enemy(PlayerType *player_ptr, MONRACE_IDX r_idx)
193 {
194     if (r_idx <= 0) {
195         int val = 1;
196         if(!get_value("MonsterID", 1, r_info.size() - 1, &val)) {
197             return;
198         }
199         r_idx = static_cast<MONRACE_IDX>(val);
200     }
201     (void)summon_named_creature(player_ptr, 0, player_ptr->y, player_ptr->x, r_idx, PM_ALLOW_SLEEP | PM_ALLOW_GROUP);
202 }
203
204 /*!
205  * @brief モンスターを種族IDを指定してペット召喚する /
206  * Summon a creature of the specified type
207  * @param r_idx モンスター種族ID(回数指定コマンド'0'で指定した回数がIDになる)
208  * @details
209  * This function is rather dangerous
210  */
211 void wiz_summon_pet(PlayerType *player_ptr, MONRACE_IDX r_idx)
212 {
213     if (r_idx <= 0) {
214         int val = 1;
215         if (!get_value("MonsterID", 1, r_info.size() - 1, &val)) {
216             return;
217         }
218         r_idx = static_cast<MONRACE_IDX>(val);
219     }
220     (void)summon_named_creature(player_ptr, 0, player_ptr->y, player_ptr->x, r_idx, PM_ALLOW_SLEEP | PM_ALLOW_GROUP | PM_FORCE_PET);
221 }
222
223 /*!
224  * @brief ターゲットを指定して指定ダメージ・指定属性・半径0のボールを放つ
225  * @param dam ダメージ量
226  * @param effect_idx 属性ID
227  * @details デフォルトは100万・GF_ARROW(射撃)。RES_ALL持ちも一撃で殺せる。
228  */
229 void wiz_kill_enemy(PlayerType *player_ptr, HIT_POINT dam, AttributeType effect_idx)
230 {
231     if (dam <= 0) {
232         char tmp[80] = "";
233         sprintf(tmp, "Damage (1-999999): ");
234         char tmp_val[10] = "1000";
235         if (!get_string(tmp, tmp_val, 6))
236             return;
237
238         dam = (HIT_POINT)atoi(tmp_val);
239     }
240     int max = (int)AttributeType::MAX;
241     int idx = (int)effect_idx;
242
243     if (idx <= 0) {
244         char tmp[80] = "";
245         sprintf(tmp, "Effect ID (1-%d): ", max - 1);
246         char tmp_val[10] = "";
247         if (!get_string(tmp, tmp_val, 3))
248             return;
249
250         effect_idx = (AttributeType)atoi(tmp_val);
251     }
252
253     if (idx <= 0 || idx >= max) {
254         msg_format(_("番号は1から%dの間で指定して下さい。", "ID must be between 1 to %d."), max - 1);
255         return;
256     }
257
258     DIRECTION dir;
259
260     if (!get_aim_dir(player_ptr, &dir))
261         return;
262
263     fire_ball(player_ptr, effect_idx, dir, dam, 0);
264 }
265
266 /*!
267  * @brief 自分に指定ダメージ・指定属性・半径0のボールを放つ
268  * @param dam ダメージ量
269  * @param effect_idx 属性ID
270  */
271 void wiz_kill_me(PlayerType *player_ptr, HIT_POINT dam, AttributeType effect_idx)
272 {
273     if (dam <= 0) {
274         char tmp[80] = "";
275         sprintf(tmp, "Damage (1-999999): ");
276         char tmp_val[10] = "1000";
277         if (!get_string(tmp, tmp_val, 6))
278             return;
279
280         dam = (HIT_POINT)atoi(tmp_val);
281     }
282     int max = (int)AttributeType::MAX;
283     int idx = (int)effect_idx;
284
285     if (idx <= 0) {
286         char tmp[80] = "";
287         sprintf(tmp, "Effect ID (1-%d): ", max - 1);
288         char tmp_val[10] = "1";
289         if (!get_string(tmp, tmp_val, 3))
290             return;
291
292         effect_idx = (AttributeType)atoi(tmp_val);
293     }
294
295     if (idx <= 0 || idx >= max) {
296         msg_format(_("番号は1から%dの間で指定して下さい。", "ID must be between 1 to %d."), max - 1);
297         return;
298     }
299
300     project(player_ptr, -1, 0, player_ptr->y, player_ptr->x, dam, effect_idx, PROJECT_KILL | PROJECT_PLAYER);
301 }