OSDN Git Service

[Refactor] monster_idxと0との比較を関数化する
[hengbandforosx/hengbandosx.git] / src / realm / realm-hex.cpp
1 /*!
2  * @brief 呪術の処理実装 / Hex code
3  * @date 2014/01/14
4  * @author
5  * 2014 Deskull rearranged comment for Doxygen.\n
6  */
7
8 #include "realm/realm-hex.h"
9 #include "cmd-action/cmd-spell.h"
10 #include "cmd-item/cmd-quaff.h"
11 #include "core/asking-player.h"
12 #include "effect/attribute-types.h"
13 #include "effect/effect-characteristics.h"
14 #include "effect/effect-processor.h"
15 #include "flavor/flavor-describer.h"
16 #include "flavor/object-flavor-types.h"
17 #include "floor/cave.h"
18 #include "floor/floor-object.h"
19 #include "floor/geometry.h"
20 #include "inventory/inventory-slot-types.h"
21 #include "io/input-key-requester.h"
22 #include "monster-race/monster-race.h"
23 #include "monster/monster-util.h"
24 #include "object-enchant/object-curse.h"
25 #include "object-enchant/tr-types.h"
26 #include "object-enchant/trc-types.h"
27 #include "object-hook/hook-armor.h"
28 #include "object/item-tester-hooker.h"
29 #include "object/item-use-flags.h"
30 #include "player/attack-defense-types.h"
31 #include "player/player-skill.h"
32 #include "player/player-status.h"
33 #include "spell-kind/magic-item-recharger.h"
34 #include "spell-kind/spells-launcher.h"
35 #include "spell-kind/spells-neighbor.h"
36 #include "spell-kind/spells-sight.h"
37 #include "spell-kind/spells-teleport.h"
38 #include "spell-realm/spells-hex.h"
39 #include "spell/spells-execution.h"
40 #include "spell/spells-status.h"
41 #include "spell/technic-info-table.h"
42 #include "status/action-setter.h"
43 #include "system/floor-type-definition.h"
44 #include "system/grid-type-definition.h"
45 #include "system/item-entity.h"
46 #include "system/player-type-definition.h"
47 #include "system/redrawing-flags-updater.h"
48 #include "target/grid-selector.h"
49 #include "target/target-getter.h"
50 #include "term/screen-processor.h"
51 #include "util/bit-flags-calculator.h"
52 #include "view/display-messages.h"
53 #include "world/world.h"
54 #ifdef JP
55 #else
56 #include "player-info/equipment-info.h"
57 #endif
58
59 /*!
60  * @brief 呪術領域魔法の各処理を行う
61  * @param spell 魔法ID
62  * @param mode 処理内容 (SpellProcessType::NAME / SPELL_DESC / SpellProcessType::INFO / SpellProcessType::CAST / SPELL_CONT / SpellProcessType::STOP)
63  * @return SpellProcessType::NAME / SPELL_DESC / SpellProcessType::INFO 時には文字列を返す。SpellProcessType::CAST / SPELL_CONT / SpellProcessType::STOP 時は std::nullopt を返す。
64  */
65 std::optional<std::string> do_hex_spell(PlayerType *player_ptr, spell_hex_type spell, SpellProcessType mode)
66 {
67     auto name = mode == SpellProcessType::NAME;
68     auto description = mode == SpellProcessType::DESCRIPTION;
69     auto info = mode == SpellProcessType::INFO;
70     auto cast = mode == SpellProcessType::CAST;
71     auto continuation = mode == SpellProcessType::CONTNUATION;
72     auto stop = mode == SpellProcessType::STOP;
73     auto should_continue = true;
74     int power;
75     switch (spell) {
76         /*** 1st book (0-7) ***/
77     case HEX_BLESS:
78         if (name) {
79             return _("邪なる祝福", "Evily blessing");
80         }
81         if (description) {
82             return _("祝福により攻撃精度と防御力が上がる。", "Attempts to increase +to_hit of a weapon and AC");
83         }
84         if (cast) {
85             if (!player_ptr->blessed) {
86                 msg_print(_("高潔な気分になった!", "You feel righteous!"));
87             }
88         }
89         if (stop) {
90             if (!player_ptr->blessed) {
91                 msg_print(_("高潔な気分が消え失せた。", "The prayer has expired."));
92             }
93         }
94         break;
95
96     case HEX_CURE_LIGHT:
97         if (name) {
98             return _("軽傷の治癒", "Cure light wounds");
99         }
100         if (description) {
101             return _("HPや傷を少し回復させる。", "Heals cuts and HP a little.");
102         }
103         if (info) {
104             return info_heal(1, 10, 0);
105         }
106         if (cast) {
107             msg_print(_("気分が良くなってくる。", "You feel a little better."));
108         }
109         if (cast || continuation) {
110             (void)cure_light_wounds(player_ptr, 1, 10);
111         }
112         break;
113
114     case HEX_DEMON_AURA:
115         if (name) {
116             return _("悪魔のオーラ", "Demonic aura");
117         }
118         if (description) {
119             return _("炎のオーラを身にまとい、回復速度が速くなる。", "Gives fire aura and regeneration.");
120         }
121         if (cast) {
122             msg_print(_("体が炎のオーラで覆われた。", "You are enveloped by a fiery aura!"));
123         }
124         if (stop) {
125             msg_print(_("炎のオーラが消え去った。", "The fiery aura disappeared."));
126         }
127         break;
128
129     case HEX_STINKING_MIST:
130         if (name) {
131             return _("悪臭霧", "Stinking mist");
132         }
133         if (description) {
134             return _("視界内のモンスターに微弱量の毒のダメージを与える。", "Deals a little poison damage to all monsters in your sight.");
135         }
136         power = player_ptr->lev / 2 + 5;
137         if (info) {
138             return info_damage(1, power, 0);
139         }
140         if (cast || continuation) {
141             project_all_los(player_ptr, AttributeType::POIS, randint1(power));
142         }
143         break;
144
145     case HEX_XTRA_MIGHT:
146         if (name) {
147             return _("腕力強化", "Extra might");
148         }
149         if (description) {
150             return _("術者の腕力を上昇させる。", "Attempts to increase your strength.");
151         }
152         if (cast) {
153             msg_print(_("何だか力が湧いて来る。", "You feel stronger."));
154         }
155         break;
156
157     case HEX_CURSE_WEAPON:
158         if (name) {
159             return _("武器呪縛", "Curse weapon");
160         }
161
162         if (description) {
163             return _("装備している武器を呪う。", "Curses your weapon.");
164         }
165
166         if (cast) {
167             constexpr auto q = _("どれを呪いますか?", "Which weapon do you curse?");
168             constexpr auto s = _("武器を装備していない。", "You're not wielding a weapon.");
169             short i_idx;
170             auto *o_ptr = choose_object(player_ptr, &i_idx, q, s, (USE_EQUIP), FuncItemTester(&ItemEntity::is_melee_weapon));
171             if (o_ptr == nullptr) {
172                 return "";
173             }
174
175             const auto item_name = describe_flavor(player_ptr, o_ptr, OD_NAME_ONLY);
176             if (!input_check(format(_("本当に %s を呪いますか?", "Do you curse %s, really?"), item_name.data()))) {
177                 return "";
178             }
179
180             if (!one_in_(3) && (o_ptr->is_fixed_or_random_artifact() || o_ptr->get_flags().has(TR_BLESSED))) {
181                 msg_format(_("%s は呪いを跳ね返した。", "%s resists the effect."), item_name.data());
182                 if (one_in_(3)) {
183                     if (o_ptr->to_d > 0) {
184                         o_ptr->to_d -= randint1(3) % 2;
185                         if (o_ptr->to_d < 0) {
186                             o_ptr->to_d = 0;
187                         }
188                     }
189                     if (o_ptr->to_h > 0) {
190                         o_ptr->to_h -= randint1(3) % 2;
191                         if (o_ptr->to_h < 0) {
192                             o_ptr->to_h = 0;
193                         }
194                     }
195                     if (o_ptr->to_a > 0) {
196                         o_ptr->to_a -= randint1(3) % 2;
197                         if (o_ptr->to_a < 0) {
198                             o_ptr->to_a = 0;
199                         }
200                     }
201                     msg_format(_("%s は劣化してしまった。", "Your %s was disenchanted!"), item_name.data());
202                 }
203             } else {
204                 int curse_rank = 0;
205                 msg_format(_("恐怖の暗黒オーラがあなたの%sを包み込んだ!", "A terrible black aura blasts your %s!"), item_name.data());
206                 o_ptr->curse_flags.set(CurseTraitType::CURSED);
207
208                 if (o_ptr->is_fixed_or_random_artifact() || o_ptr->is_ego()) {
209
210                     if (one_in_(3)) {
211                         o_ptr->curse_flags.set(CurseTraitType::HEAVY_CURSE);
212                     }
213                     if (one_in_(666)) {
214                         o_ptr->curse_flags.set(CurseTraitType::TY_CURSE);
215                         if (one_in_(666)) {
216                             o_ptr->curse_flags.set(CurseTraitType::PERMA_CURSE);
217                         }
218
219                         o_ptr->art_flags.set(TR_AGGRAVATE);
220                         o_ptr->art_flags.set(TR_VORPAL);
221                         o_ptr->art_flags.set(TR_VAMPIRIC);
222                         msg_print(_("血だ!血だ!血だ!", "Blood, Blood, Blood!"));
223                         curse_rank = 2;
224                     }
225                 }
226
227                 o_ptr->curse_flags.set(get_curse(curse_rank, o_ptr));
228             }
229
230             RedrawingFlagsUpdater::get_instance().set_flag(StatusRecalculatingFlag::BONUS);
231             should_continue = false;
232         }
233         break;
234
235     case HEX_DETECT_EVIL:
236         if (name) {
237             return _("邪悪感知", "Evil detection");
238         }
239         if (description) {
240             return _("周囲の邪悪なモンスターを感知する。", "Detects evil monsters.");
241         }
242         if (info) {
243             return info_range(MAX_PLAYER_SIGHT);
244         }
245         if (cast) {
246             msg_print(_("邪悪な生物の存在を感じ取ろうとした。", "You sense the presence of evil creatures."));
247         }
248         break;
249
250     case HEX_PATIENCE: {
251         if (name) {
252             return _("我慢", "Patience");
253         }
254
255         if (description) {
256             return _("数ターン攻撃を耐えた後、受けたダメージを地獄の業火として周囲に放出する。", "Bursts hell fire strongly after enduring damage for a few turns.");
257         }
258
259         SpellHex spell_hex(player_ptr);
260         power = std::min(200, spell_hex.get_revenge_power() * 2);
261         if (info) {
262             return info_damage(0, 0, power);
263         }
264
265         if (cast) {
266             int a = 3 - (player_ptr->pspeed - 100) / 10;
267             byte r = 3 + randint1(3) + std::max(0, std::min(3, a));
268
269             if (spell_hex.get_revenge_turn() > 0) {
270                 msg_print(_("すでに我慢をしている。", "You are already biding your time for vengeance."));
271                 return std::nullopt;
272             }
273
274             spell_hex.set_revenge_type(SpellHexRevengeType::PATIENCE);
275             spell_hex.set_revenge_turn(r, true);
276             spell_hex.set_revenge_power(0, true);
277             msg_print(_("じっと耐えることにした。", "You decide to endure damage for future retribution."));
278             should_continue = false;
279         }
280
281         if (continuation) {
282             POSITION rad = 2 + (power / 50);
283             spell_hex.set_revenge_turn(1, false);
284             if ((spell_hex.get_revenge_turn() == 0) || (power >= 200)) {
285                 msg_print(_("我慢が解かれた!", "My patience is at an end!"));
286                 if (power) {
287                     project(player_ptr, 0, rad, player_ptr->y, player_ptr->x, power, AttributeType::HELL_FIRE, (PROJECT_STOP | PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL));
288                 }
289
290                 if (w_ptr->wizard) {
291                     msg_format(_("%d点のダメージを返した。", "You return %d damage."), power);
292                 }
293
294                 spell_hex.set_revenge_type(SpellHexRevengeType::NONE);
295                 spell_hex.set_revenge_turn(0, true);
296                 spell_hex.set_revenge_power(0, true);
297             }
298         }
299         break;
300     }
301
302         /*** 2nd book (8-15) ***/
303     case HEX_ICE_ARMOR:
304         if (name) {
305             return _("氷の鎧", "Armor of ice");
306         }
307         if (description) {
308             return _("氷のオーラを身にまとい、防御力が上昇する。", "Surrounds you with an icy aura and gives a bonus to AC.");
309         }
310         if (cast) {
311             msg_print(_("体が氷の鎧で覆われた。", "You are enveloped by icy armor!"));
312         }
313         if (stop) {
314             msg_print(_("氷の鎧が消え去った。", "The icy armor disappeared."));
315         }
316         break;
317
318     case HEX_CURE_SERIOUS:
319         if (name) {
320             return _("重傷の治癒", "Cure serious wounds");
321         }
322         if (description) {
323             return _("体力や傷を多少回復させる。", "Heals cuts and HP.");
324         }
325         if (info) {
326             return info_heal(2, 10, 0);
327         }
328         if (cast) {
329             msg_print(_("気分が良くなってくる。", "You feel better."));
330         }
331         if (cast || continuation) {
332             (void)cure_serious_wounds(player_ptr, 2, 10);
333         }
334         break;
335
336     case HEX_INHALE: {
337         if (name) {
338             return _("薬品吸入", "Inhale potion");
339         }
340
341         if (description) {
342             return _("呪文詠唱を中止することなく、薬の効果を得ることができる。", "Quaffs a potion without canceling spell casting.");
343         }
344
345         SpellHex spell_hex(player_ptr);
346         if (cast) {
347             spell_hex.set_casting_flag(HEX_INHALE);
348             do_cmd_quaff_potion(player_ptr);
349             spell_hex.reset_casting_flag(HEX_INHALE);
350             should_continue = false;
351         }
352
353         break;
354     }
355     case HEX_VAMP_MIST:
356         if (name) {
357             return _("衰弱の霧", "Hypodynamic mist");
358         }
359         if (description) {
360             return _("視界内のモンスターに微弱量の衰弱属性のダメージを与える。", "Deals a little life-draining damage to all monsters in your sight.");
361         }
362         power = (player_ptr->lev / 2) + 5;
363         if (info) {
364             return info_damage(1, power, 0);
365         }
366         if (cast || continuation) {
367             project_all_los(player_ptr, AttributeType::HYPODYNAMIA, randint1(power));
368         }
369         break;
370
371     case HEX_RUNESWORD:
372         if (name) {
373             return _("魔剣化", "Swords to runeswords");
374         }
375         if (description) {
376             return _("武器の攻撃力を上げる。切れ味を得、呪いに応じて与えるダメージが上昇し、善良なモンスターに対するダメージが2倍になる。",
377                 "Gives vorpal ability to your weapon. Increases damage from your weapon acccording to curse of your weapon.");
378         }
379         if (cast) {
380 #ifdef JP
381             msg_print("あなたの武器が黒く輝いた。");
382 #else
383             if (!empty_hands(player_ptr, false)) {
384                 msg_print("Your weapons glow bright black.");
385             } else {
386                 msg_print("Your weapon glows bright black.");
387             }
388 #endif
389         }
390         if (stop) {
391 #ifdef JP
392             msg_print("武器の輝きが消え去った。");
393 #else
394             msg_format("Your weapon%s.", (empty_hands(player_ptr, false)) ? " no longer glows" : "s no longer glow");
395 #endif
396         }
397         break;
398
399     case HEX_CONFUSION:
400         if (name) {
401             return _("混乱の手", "Touch of confusion");
402         }
403         if (description) {
404             return _("攻撃した際モンスターを混乱させる。", "Confuses a monster when you attack.");
405         }
406         if (cast) {
407             msg_print(_("あなたの手が赤く輝き始めた。", "Your hands glow bright red."));
408         }
409         if (stop) {
410             msg_print(_("手の輝きがなくなった。", "Your hands no longer glow."));
411         }
412         break;
413
414     case HEX_BUILDING:
415         if (name) {
416             return _("肉体強化", "Building up");
417         }
418         if (description) {
419             return _(
420                 "術者の腕力、器用さ、耐久力を上昇させる。攻撃回数の上限を 1 増加させる。", "Attempts to increases your strength, dexterity and constitusion.");
421         }
422         if (cast) {
423             msg_print(_("身体が強くなった気がした。", "You feel your body is more developed now."));
424         }
425         break;
426
427     case HEX_ANTI_TELE:
428         if (name) {
429             return _("反テレポート結界", "Anti teleport barrier");
430         }
431         if (description) {
432             return _("視界内のモンスターのテレポートを阻害するバリアを張る。", "Obstructs all teleportations by monsters in your sight.");
433         }
434         power = player_ptr->lev * 3 / 2;
435         if (info) {
436             return info_power(power);
437         }
438         if (cast) {
439             msg_print(_("テレポートを防ぐ呪いをかけた。", "You feel anyone can not teleport except you."));
440         }
441         break;
442
443         /*** 3rd book (16-23) ***/
444     case HEX_SHOCK_CLOAK:
445         if (name) {
446             return _("衝撃のクローク", "Cloak of shock");
447         }
448         if (description) {
449             return _("電気のオーラを身にまとい、動きが速くなる。", "Gives lightning aura and a bonus to speed.");
450         }
451         if (cast) {
452             msg_print(_("体が稲妻のオーラで覆われた。", "You are enveloped by an electrical aura!"));
453         }
454         if (stop) {
455             msg_print(_("稲妻のオーラが消え去った。", "The electrical aura disappeared."));
456         }
457         break;
458
459     case HEX_CURE_CRITICAL:
460         if (name) {
461             return _("致命傷の治癒", "Cure critical wounds");
462         }
463         if (description) {
464             return _("体力や傷を回復させる。", "Heals cuts and HP greatly.");
465         }
466         if (info) {
467             return info_heal(4, 10, 0);
468         }
469         if (cast) {
470             msg_print(_("気分が良くなってくる。", "You feel much better."));
471         }
472         if (cast || continuation) {
473             (void)cure_critical_wounds(player_ptr, damroll(4, 10));
474         }
475         break;
476
477     case HEX_RECHARGE:
478         if (name) {
479             return _("呪力封入", "Recharging");
480         }
481         if (description) {
482             return _("魔法の道具に魔力を再充填する。", "Recharges a magic device.");
483         }
484         power = player_ptr->lev * 2;
485         if (info) {
486             return info_power(power);
487         }
488         if (cast) {
489             if (!recharge(player_ptr, power)) {
490                 return std::nullopt;
491             }
492             should_continue = false;
493         }
494         break;
495
496     case HEX_RAISE_DEAD:
497         if (name) {
498             return _("死者復活", "Animate Dead");
499         }
500         if (description) {
501             return _("死体を蘇らせてペットにする。", "Raises corpses and skeletons from dead.");
502         }
503         if (cast) {
504             msg_print(_("死者への呼びかけを始めた。", "You start to call the dead.!"));
505         }
506         if (cast || continuation) {
507             animate_dead(player_ptr, 0, player_ptr->y, player_ptr->x);
508         }
509         break;
510
511     case HEX_CURSE_ARMOUR:
512         if (name) {
513             return _("防具呪縛", "Curse armor");
514         }
515         if (description) {
516             return _("装備している防具に呪いをかける。", "Curse a piece of armour that you are wielding.");
517         }
518         if (cast) {
519             constexpr auto q = _("どれを呪いますか?", "Which piece of armour do you curse?");
520             constexpr auto s = _("防具を装備していない。", "You're not wearing any armor.");
521             short i_idx;
522             auto *o_ptr = choose_object(player_ptr, &i_idx, q, s, (USE_EQUIP), FuncItemTester(&ItemEntity::is_protector));
523             if (!o_ptr) {
524                 return "";
525             }
526
527             o_ptr = &player_ptr->inventory_list[i_idx];
528             const auto item_name = describe_flavor(player_ptr, o_ptr, OD_NAME_ONLY);
529             if (!input_check(format(_("本当に %s を呪いますか?", "Do you curse %s, really?"), item_name.data()))) {
530                 return "";
531             }
532
533             if (!one_in_(3) && (o_ptr->is_fixed_or_random_artifact() || o_ptr->get_flags().has(TR_BLESSED))) {
534                 msg_format(_("%s は呪いを跳ね返した。", "%s resists the effect."), item_name.data());
535                 if (one_in_(3)) {
536                     if (o_ptr->to_d > 0) {
537                         o_ptr->to_d -= randint1(3) % 2;
538                         if (o_ptr->to_d < 0) {
539                             o_ptr->to_d = 0;
540                         }
541                     }
542                     if (o_ptr->to_h > 0) {
543                         o_ptr->to_h -= randint1(3) % 2;
544                         if (o_ptr->to_h < 0) {
545                             o_ptr->to_h = 0;
546                         }
547                     }
548                     if (o_ptr->to_a > 0) {
549                         o_ptr->to_a -= randint1(3) % 2;
550                         if (o_ptr->to_a < 0) {
551                             o_ptr->to_a = 0;
552                         }
553                     }
554                     msg_format(_("%s は劣化してしまった。", "Your %s was disenchanted!"), item_name.data());
555                 }
556             } else {
557                 int curse_rank = 0;
558                 msg_format(_("恐怖の暗黒オーラがあなたの%sを包み込んだ!", "A terrible black aura blasts your %s!"), item_name.data());
559                 o_ptr->curse_flags.set(CurseTraitType::CURSED);
560
561                 if (o_ptr->is_fixed_or_random_artifact() || o_ptr->is_ego()) {
562
563                     if (one_in_(3)) {
564                         o_ptr->curse_flags.set(CurseTraitType::HEAVY_CURSE);
565                     }
566                     if (one_in_(666)) {
567                         o_ptr->curse_flags.set(CurseTraitType::TY_CURSE);
568                         if (one_in_(666)) {
569                             o_ptr->curse_flags.set(CurseTraitType::PERMA_CURSE);
570                         }
571
572                         o_ptr->art_flags.set(TR_AGGRAVATE);
573                         o_ptr->art_flags.set(TR_RES_POIS);
574                         o_ptr->art_flags.set(TR_RES_DARK);
575                         o_ptr->art_flags.set(TR_RES_NETHER);
576                         msg_print(_("血だ!血だ!血だ!", "Blood, Blood, Blood!"));
577                         curse_rank = 2;
578                     }
579                 }
580
581                 o_ptr->curse_flags.set(get_curse(curse_rank, o_ptr));
582             }
583
584             RedrawingFlagsUpdater::get_instance().set_flag(StatusRecalculatingFlag::BONUS);
585             should_continue = false;
586         }
587         break;
588
589     case HEX_SHADOW_CLOAK:
590         if (name) {
591             return _("影のクローク", "Cloak of shadow");
592         }
593         if (description) {
594             return _("影のオーラを身にまとい、敵に影のダメージを与える。", "Gives aura of shadow.");
595         }
596         if (cast) {
597             auto *o_ptr = &player_ptr->inventory_list[INVEN_OUTER];
598
599             if (!o_ptr->is_valid()) {
600                 msg_print(_("クロークを身につけていない!", "You are not wearing a cloak."));
601                 return std::nullopt;
602             } else if (!o_ptr->is_cursed()) {
603                 msg_print(_("クロークは呪われていない!", "Your cloak is not cursed."));
604                 return std::nullopt;
605             } else {
606                 msg_print(_("影のオーラを身にまとった。", "You are enveloped by a shadowy aura!"));
607             }
608         }
609         if (continuation) {
610             auto *o_ptr = &player_ptr->inventory_list[INVEN_OUTER];
611
612             if ((!o_ptr->is_valid()) || (!o_ptr->is_cursed())) {
613                 exe_spell(player_ptr, REALM_HEX, spell, SpellProcessType::STOP);
614                 SpellHex spell_hex(player_ptr);
615                 spell_hex.reset_casting_flag(spell);
616                 if (!spell_hex.is_spelling_any()) {
617                     set_action(player_ptr, ACTION_NONE);
618                 }
619             }
620         }
621         if (stop) {
622             msg_print(_("影のオーラが消え去った。", "The shadowy aura disappeared."));
623         }
624         break;
625
626     case HEX_PAIN_TO_MANA:
627         if (name) {
628             return _("苦痛を魔力に", "Pain to mana");
629         }
630         if (description) {
631             return _("視界内のモンスターに精神ダメージ与え、魔力を吸い取る。", "Deals psychic damage to all monsters in sight and drains some mana.");
632         }
633         power = player_ptr->lev * 3 / 2;
634         if (info) {
635             return info_damage(1, power, 0);
636         }
637         if (cast || continuation) {
638             project_all_los(player_ptr, AttributeType::PSI_DRAIN, randint1(power));
639         }
640         break;
641
642     case HEX_EYE_FOR_EYE:
643         if (name) {
644             return _("目には目を", "Eye for an eye");
645         }
646         if (description) {
647             return _("打撃や魔法で受けたダメージを、攻撃元のモンスターにも与える。", "Returns same damage which you got to the monster which damaged you.");
648         }
649         if (cast) {
650             msg_print(_("復讐したい欲望にかられた。", "You feel very vengeful."));
651         }
652         break;
653
654         /*** 4th book (24-31) ***/
655     case HEX_ANTI_MULTI:
656         if (name) {
657             return _("反増殖結界", "Anti multiply barrier");
658         }
659         if (description) {
660             return _("その階の増殖するモンスターの増殖を阻止する。", "Obstructs all multiplying by monsters on entire floor.");
661         }
662         if (cast) {
663             msg_print(_("増殖を阻止する呪いをかけた。", "You feel anyone can not multiply."));
664         }
665         break;
666
667     case HEX_RESTORE:
668         if (name) {
669             return _("全復活", "Restoration");
670         }
671         if (description) {
672             return _("経験値を徐々に復活し、減少した能力値を回復させる。", "Restores experience and status.");
673         }
674         if (cast) {
675             msg_print(_("体が元の活力を取り戻し始めた。", "You feel your lost status starting to return."));
676         }
677         if (cast || continuation) {
678             bool flag = false;
679             int d = (player_ptr->max_exp - player_ptr->exp);
680             int r = (player_ptr->exp / 20);
681             int i;
682
683             if (d > 0) {
684                 if (d < r) {
685                     player_ptr->exp = player_ptr->max_exp;
686                 } else {
687                     player_ptr->exp += r;
688                 }
689
690                 /* Check the experience */
691                 check_experience(player_ptr);
692
693                 flag = true;
694             }
695
696             auto &rfu = RedrawingFlagsUpdater::get_instance();
697             for (i = A_STR; i < A_MAX; i++) {
698                 if (player_ptr->stat_cur[i] < player_ptr->stat_max[i]) {
699                     if (player_ptr->stat_cur[i] < 18) {
700                         player_ptr->stat_cur[i]++;
701                     } else {
702                         player_ptr->stat_cur[i] += 10;
703                     }
704
705                     if (player_ptr->stat_cur[i] > player_ptr->stat_max[i]) {
706                         player_ptr->stat_cur[i] = player_ptr->stat_max[i];
707                     }
708
709                     rfu.set_flag(StatusRecalculatingFlag::BONUS);
710                     flag = true;
711                 }
712             }
713
714             if (!flag) {
715                 const auto spell_name = exe_spell(player_ptr, REALM_HEX, HEX_RESTORE, SpellProcessType::NAME);
716                 msg_format(_("%sの呪文の詠唱をやめた。", "Finish casting '%s^'."), spell_name->data());
717                 SpellHex spell_hex(player_ptr);
718                 spell_hex.reset_casting_flag(HEX_RESTORE);
719                 if (!spell_hex.is_spelling_any()) {
720                     set_action(player_ptr, ACTION_NONE);
721                 }
722
723                 static constexpr auto flags = {
724                     StatusRecalculatingFlag::BONUS,
725                     StatusRecalculatingFlag::HP,
726                     StatusRecalculatingFlag::MP,
727                     StatusRecalculatingFlag::SPELLS,
728                 };
729                 rfu.set_flags(flags);
730                 rfu.set_flag(MainWindowRedrawingFlag::EXTRA);
731                 return "";
732             }
733         }
734         break;
735
736     case HEX_DRAIN_CURSE:
737         if (name) {
738             return _("呪力吸収", "Drain curse power");
739         }
740         if (description) {
741             return _("呪われた装備品の呪いを吸収して魔力を回復する。", "Drains curse on your equipment and heals SP a little.");
742         }
743         if (cast) {
744             constexpr auto q = _("どの装備品から吸収しますか?", "Which cursed equipment do you drain mana from?");
745             constexpr auto s = _("呪われたアイテムを装備していない。", "You have no cursed equipment.");
746             short i_idx;
747             auto *o_ptr = choose_object(player_ptr, &i_idx, q, s, (USE_EQUIP), FuncItemTester(&ItemEntity::is_cursed));
748             if (!o_ptr) {
749                 return "";
750             }
751
752             player_ptr->csp += (player_ptr->lev / 5) + randint1(player_ptr->lev / 5);
753             if (o_ptr->get_flags().has(TR_TY_CURSE) || o_ptr->curse_flags.has(CurseTraitType::TY_CURSE)) {
754                 player_ptr->csp += randint1(5);
755             }
756             if (player_ptr->csp > player_ptr->msp) {
757                 player_ptr->csp = player_ptr->msp;
758             }
759
760             if (o_ptr->curse_flags.has(CurseTraitType::PERMA_CURSE)) {
761                 /* Nothing */
762             } else if (o_ptr->curse_flags.has(CurseTraitType::HEAVY_CURSE)) {
763                 if (one_in_(7)) {
764                     msg_print(_("呪いを全て吸い取った。", "A heavy curse vanished."));
765                     o_ptr->curse_flags.clear();
766                 }
767             } else if (o_ptr->curse_flags.has(CurseTraitType::CURSED) && one_in_(3)) {
768                 msg_print(_("呪いを全て吸い取った。", "A curse vanished."));
769                 o_ptr->curse_flags.clear();
770             }
771
772             should_continue = false;
773         }
774         break;
775
776     case HEX_VAMP_BLADE:
777         if (name) {
778             return _("吸血の刃", "Swords to vampires");
779         }
780         if (description) {
781             return _("吸血属性で攻撃する。", "Gives vampiric ability to your weapon.");
782         }
783         if (cast) {
784 #ifdef JP
785             msg_print("あなたの武器が血を欲している。");
786 #else
787             if (!empty_hands(player_ptr, false)) {
788                 msg_print("Your weapons want more blood now.");
789             } else {
790                 msg_print("Your weapon wants more blood now.");
791             }
792 #endif
793         }
794         if (stop) {
795 #ifdef JP
796             msg_print("武器の渇望が消え去った。");
797 #else
798             msg_format("Your weapon%s less thirsty now.", (empty_hands(player_ptr, false)) ? " is" : "s are");
799 #endif
800         }
801         break;
802
803     case HEX_STUN_MONSTERS:
804         if (name) {
805             return _("朦朧の言葉", "Word of stun");
806         }
807         if (description) {
808             return _("視界内のモンスターを朦朧とさせる。", "Stuns all monsters in your sight.");
809         }
810         power = player_ptr->lev * 4;
811         if (info) {
812             return info_power(power);
813         }
814         if (cast || continuation) {
815             stun_monsters(player_ptr, power);
816         }
817         break;
818
819     case HEX_SHADOW_MOVE:
820         if (name) {
821             return _("影移動", "Moving into shadow");
822         }
823         if (description) {
824             return _("モンスターの隣のマスに瞬間移動する。", "Teleports you close to a monster.");
825         }
826         if (cast) {
827             int i, dir;
828             POSITION y, x;
829             bool flag;
830
831             for (i = 0; i < 3; i++) {
832                 if (!tgt_pt(player_ptr, &x, &y)) {
833                     return "";
834                 }
835
836                 flag = false;
837
838                 const auto *floor_ptr = player_ptr->current_floor_ptr;
839                 for (dir = 0; dir < 8; dir++) {
840                     int dy = y + ddy_ddd[dir];
841                     int dx = x + ddx_ddd[dir];
842                     if (dir == 5) {
843                         continue;
844                     }
845                     if (is_monster(floor_ptr->grid_array[dy][dx].m_idx)) {
846                         flag = true;
847                     }
848                 }
849
850                 const auto dist = distance(y, x, player_ptr->y, player_ptr->x);
851                 if (!is_cave_empty_bold(player_ptr, y, x) || floor_ptr->grid_array[y][x].is_icky() || (dist > player_ptr->lev + 2)) {
852                     msg_print(_("そこには移動できない。", "Can not teleport to there."));
853                     continue;
854                 }
855                 break;
856             }
857
858             if (flag && randint0(player_ptr->lev * player_ptr->lev / 2)) {
859                 teleport_player_to(player_ptr, y, x, TELEPORT_SPONTANEOUS);
860             } else {
861                 msg_print(_("おっと!", "Oops!"));
862                 teleport_player(player_ptr, 30, TELEPORT_SPONTANEOUS);
863             }
864
865             should_continue = false;
866         }
867         break;
868
869     case HEX_ANTI_MAGIC:
870         if (name) {
871             return _("反魔法結界", "Anti magic barrier");
872         }
873         if (description) {
874             return _("視界内のモンスターの魔法を阻害するバリアを張る。", "Obstructs all magic spells of monsters in your sight.");
875         }
876         power = player_ptr->lev * 3 / 2;
877         if (info) {
878             return info_power(power);
879         }
880         if (cast) {
881             msg_print(_("魔法を防ぐ呪いをかけた。", "You feel anyone can not cast spells except you."));
882         }
883         break;
884
885     case HEX_REVENGE: {
886         if (name) {
887             return _("復讐の宣告", "Revenge sentence");
888         }
889
890         if (description) {
891             return _("数ターン後にそれまで受けたダメージに応じた威力の地獄の劫火の弾を放つ。", "Fires a ball of hell fire to try avenging damage from a few turns.");
892         }
893
894         SpellHex spell_hex(player_ptr);
895         power = spell_hex.get_revenge_power();
896         if (info) {
897             return info_damage(0, 0, power);
898         }
899
900         if (cast) {
901             byte r;
902             int a = 3 - (player_ptr->pspeed - 100) / 10;
903             r = 1 + randint1(2) + std::max(0, std::min(3, a));
904
905             if (spell_hex.get_revenge_turn() > 0) {
906                 msg_print(_("すでに復讐は宣告済みだ。", "You've already declared your revenge."));
907                 return std::nullopt;
908             }
909
910             spell_hex.set_revenge_type(SpellHexRevengeType::REVENGE);
911             spell_hex.set_revenge_turn(r, true);
912             msg_format(_("あなたは復讐を宣告した。あと %d ターン。", "You declare your revenge. %d turns left."), r);
913             should_continue = false;
914         }
915
916         if (continuation) {
917             spell_hex.set_revenge_turn(1, false);
918             if (spell_hex.get_revenge_turn() == 0) {
919                 DIRECTION dir;
920
921                 if (power) {
922                     command_dir = 0;
923
924                     do {
925                         msg_print(_("復讐の時だ!", "Time for revenge!"));
926                     } while (!get_aim_dir(player_ptr, &dir));
927
928                     fire_ball(player_ptr, AttributeType::HELL_FIRE, dir, power, 1);
929
930                     if (w_ptr->wizard) {
931                         msg_format(_("%d点のダメージを返した。", "You return %d damage."), power);
932                     }
933                 } else {
934                     msg_print(_("復讐する気が失せた。", "You are not in the mood for revenge."));
935                 }
936
937                 spell_hex.set_revenge_power(0, true);
938             }
939         }
940
941         break;
942     }
943     case HEX_MAX:
944         break;
945     }
946
947     if (cast && should_continue) {
948         SpellHex spell_hex(player_ptr);
949         spell_hex.set_casting_flag(spell);
950         if (player_ptr->action != ACTION_SPELL) {
951             set_action(player_ptr, ACTION_SPELL);
952         }
953     }
954
955     if (!info) {
956         auto &rfu = RedrawingFlagsUpdater::get_instance();
957         static constexpr auto flags_srf = {
958             StatusRecalculatingFlag::BONUS,
959             StatusRecalculatingFlag::HP,
960             StatusRecalculatingFlag::MP,
961             StatusRecalculatingFlag::SPELLS,
962         };
963         rfu.set_flags(flags_srf);
964         static constexpr auto flags_mwrf = {
965             MainWindowRedrawingFlag::EXTRA,
966             MainWindowRedrawingFlag::HP,
967             MainWindowRedrawingFlag::MP,
968         };
969         rfu.set_flags(flags_mwrf);
970     }
971
972     return "";
973 }