OSDN Git Service

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