OSDN Git Service

746c222bba354a75896b33e90990c035b56460b6
[hengbandforosx/hengbandosx.git] / src / mutation / mutation-processor.cpp
1 #include "mutation/mutation-processor.h"
2 #include "core/asking-player.h"
3 #include "core/disturbance.h"
4 #include "core/player-redraw-types.h"
5 #include "dungeon/dungeon.h"
6 #include "effect/attribute-types.h"
7 #include "floor/geometry.h"
8 #include "grid/grid.h"
9 #include "hpmp/hp-mp-processor.h"
10 #include "inventory/inventory-object.h"
11 #include "inventory/inventory-slot-types.h"
12 #include "io/input-key-requester.h"
13 #include "main/sound-of-music.h"
14 #include "monster-floor/monster-summon.h"
15 #include "monster-floor/place-monster-types.h"
16 #include "monster-race/monster-race.h"
17 #include "monster/monster-status.h"
18 #include "mutation/mutation-flag-types.h"
19 #include "mutation/mutation-investor-remover.h"
20 #include "object/lite-processor.h"
21 #include "object/tval-types.h"
22 #include "player-info/equipment-info.h"
23 #include "player/digestion-processor.h"
24 #include "player/player-damage.h"
25 #include "player/player-status-flags.h"
26 #include "spell-kind/spells-floor.h"
27 #include "spell-kind/spells-launcher.h"
28 #include "spell-kind/spells-lite.h"
29 #include "spell-kind/spells-sight.h"
30 #include "spell-kind/spells-teleport.h"
31 #include "spell-kind/spells-world.h"
32 #include "spell-realm/spells-hex.h"
33 #include "spell-realm/spells-song.h"
34 #include "spell/summon-types.h"
35 #include "status/bad-status-setter.h"
36 #include "status/base-status.h"
37 #include "status/body-improvement.h"
38 #include "status/buff-setter.h"
39 #include "status/shape-changer.h"
40 #include "status/sight-setter.h"
41 #include "store/store-owners.h"
42 #include "store/store-util.h"
43 #include "store/store.h"
44 #include "system/floor-type-definition.h"
45 #include "system/grid-type-definition.h"
46 #include "system/monster-race-definition.h"
47 #include "system/monster-type-definition.h"
48 #include "system/object-type-definition.h"
49 #include "system/player-type-definition.h"
50 #include "target/target-checker.h"
51 #include "target/target-setter.h"
52 #include "target/target-types.h"
53 #include "term/screen-processor.h"
54 #include "view/display-messages.h"
55
56 static bool get_hack_dir(PlayerType *player_ptr, DIRECTION *dp)
57 {
58     *dp = 0;
59     char command;
60     DIRECTION dir = 0;
61     while (!dir) {
62         concptr p = target_okay(player_ptr)
63                         ? _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ")
64                         : _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
65         if (!get_com(p, &command, true))
66             break;
67
68         if (use_menu && (command == '\r'))
69             command = 't';
70
71         switch (command) {
72         case 'T':
73         case 't':
74         case '.':
75         case '5':
76         case '0':
77             dir = 5;
78             break;
79         case '*':
80         case ' ':
81         case '\r':
82             if (target_set(player_ptr, TARGET_KILL))
83                 dir = 5;
84
85             break;
86         default:
87             dir = get_keymap_dir(command);
88             break;
89         }
90
91         if ((dir == 5) && !target_okay(player_ptr))
92             dir = 0;
93
94         if (!dir)
95             bell();
96     }
97
98     if (!dir)
99         return false;
100
101     command_dir = dir;
102     if (player_ptr->confused)
103         dir = ddd[randint0(8)];
104
105     if (command_dir != dir)
106         msg_print(_("あなたは混乱している。", "You are confused."));
107
108     *dp = dir;
109     return true;
110 }
111
112 /*!
113  * @brief 10ゲームターンが進行するごとに突然変異の発動判定を行う処理
114  * / Handle mutation effects once every 10 game turns
115  */
116 void process_world_aux_mutation(PlayerType *player_ptr)
117 {
118     if (player_ptr->muta.none() || player_ptr->phase_out || player_ptr->wild_mode) {
119         return;
120     }
121
122     BadStatusSetter bss(player_ptr);
123     if (player_ptr->muta.has(PlayerMutationType::BERS_RAGE) && one_in_(3000)) {
124         disturb(player_ptr, false, true);
125         msg_print(_("ウガァァア!", "RAAAAGHH!"));
126         msg_print(_("激怒の発作に襲われた!", "You feel a fit of rage coming over you!"));
127         (void)set_shero(player_ptr, 10 + randint1(player_ptr->lev), false);
128         (void)bss.afraidness(0);
129     }
130
131     if (player_ptr->muta.has(PlayerMutationType::COWARDICE) && (randint1(3000) == 13)) {
132         if (!has_resist_fear(player_ptr)) {
133             disturb(player_ptr, false, true);
134             msg_print(_("とても暗い... とても恐い!", "It's so dark... so scary!"));
135             (void)bss.mod_afraidness(13 + randint1(26));
136         }
137     }
138
139     if (player_ptr->muta.has(PlayerMutationType::RTELEPORT) && (randint1(5000) == 88)) {
140         if (!has_resist_nexus(player_ptr) && player_ptr->muta.has_not(PlayerMutationType::VTELEPORT) && !player_ptr->anti_tele) {
141             disturb(player_ptr, false, true);
142             msg_print(_("あなたの位置は突然ひじょうに不確定になった...", "Your position suddenly seems very uncertain..."));
143             msg_print(nullptr);
144             teleport_player(player_ptr, 40, TELEPORT_PASSIVE);
145         }
146     }
147
148     if (player_ptr->muta.has(PlayerMutationType::ALCOHOL) && (randint1(6400) == 321)) {
149         if (!has_resist_conf(player_ptr) && !has_resist_chaos(player_ptr)) {
150             disturb(player_ptr, false, true);
151             player_ptr->redraw |= PR_EXTRA;
152             msg_print(_("いひきがもーろーとひてきたきがふる...ヒック!", "You feel a SSSCHtupor cOmINg over yOu... *HIC*!"));
153         }
154
155         if (!has_resist_conf(player_ptr)) {
156             (void)bss.mod_confusion(randint0(20) + 15);
157         }
158
159         if (!has_resist_chaos(player_ptr)) {
160             if (one_in_(20)) {
161                 msg_print(nullptr);
162                 if (one_in_(3))
163                     lose_all_info(player_ptr);
164                 else
165                     wiz_dark(player_ptr);
166                 (void)teleport_player_aux(player_ptr, 100, false, i2enum<teleport_flags>(TELEPORT_NONMAGICAL | TELEPORT_PASSIVE));
167                 wiz_dark(player_ptr);
168                 msg_print(_("あなたは見知らぬ場所で目が醒めた...頭が痛い。", "You wake up somewhere with a sore head..."));
169                 msg_print(_("何も覚えていない。どうやってここに来たかも分からない!", "You can't remember a thing or how you got here!"));
170             } else {
171                 if (one_in_(3)) {
172                     msg_print(_("き~れいなちょおちょらとんれいる~", "Thishcischs GooDSChtuff!"));
173                     (void)bss.mod_hallucination(randint0(150) + 150);
174                 }
175             }
176         }
177     }
178
179     if (player_ptr->muta.has(PlayerMutationType::HALLU) && (randint1(6400) == 42)) {
180         if (!has_resist_chaos(player_ptr)) {
181             disturb(player_ptr, false, true);
182             player_ptr->redraw |= PR_EXTRA;
183             (void)bss.mod_hallucination(randint0(50) + 20);
184         }
185     }
186
187     if (player_ptr->muta.has(PlayerMutationType::FLATULENT) && (randint1(3000) == 13)) {
188         disturb(player_ptr, false, true);
189         msg_print(_("ブゥーーッ!おっと。", "BRRAAAP! Oops."));
190         msg_print(nullptr);
191         fire_ball(player_ptr, AttributeType::POIS, 0, player_ptr->lev, 3);
192     }
193
194     if (player_ptr->muta.has(PlayerMutationType::PROD_MANA) && !player_ptr->anti_magic && one_in_(9000)) {
195         int dire = 0;
196         disturb(player_ptr, false, true);
197         msg_print(_("魔法のエネルギーが突然あなたの中に流れ込んできた!エネルギーを解放しなければならない!",
198             "Magical energy flows through you! You must release it!"));
199
200         flush();
201         msg_print(nullptr);
202         (void)get_hack_dir(player_ptr, &dire);
203         fire_ball(player_ptr, AttributeType::MANA, dire, player_ptr->lev * 2, 3);
204     }
205
206     if (player_ptr->muta.has(PlayerMutationType::ATT_DEMON) && !player_ptr->anti_magic && (randint1(6666) == 666)) {
207         bool pet = one_in_(6);
208         BIT_FLAGS mode = PM_ALLOW_GROUP;
209
210         if (pet)
211             mode |= PM_FORCE_PET;
212         else
213             mode |= (PM_ALLOW_UNIQUE | PM_NO_PET);
214
215         if (summon_specific(player_ptr, (pet ? -1 : 0), player_ptr->y, player_ptr->x, player_ptr->current_floor_ptr->dun_level, SUMMON_DEMON, mode)) {
216             msg_print(_("あなたはデーモンを引き寄せた!", "You have attracted a demon!"));
217             disturb(player_ptr, false, true);
218         }
219     }
220
221     if (player_ptr->muta.has(PlayerMutationType::SPEED_FLUX) && one_in_(6000)) {
222         disturb(player_ptr, false, true);
223         if (one_in_(2)) {
224             msg_print(_("精力的でなくなった気がする。", "You feel less energetic."));
225             if (player_ptr->fast > 0) {
226                 set_fast(player_ptr, 0, true);
227             } else {
228                 (void)bss.slowness(randint1(30) + 10, false);
229             }
230         } else {
231             msg_print(_("精力的になった気がする。", "You feel more energetic."));
232             if (player_ptr->slow > 0) {
233                 (void)bss.slowness(0, true);
234             } else {
235                 set_fast(player_ptr, randint1(30) + 10, false);
236             }
237         }
238
239         msg_print(nullptr);
240     }
241
242     if (player_ptr->muta.has(PlayerMutationType::BANISH_ALL) && one_in_(9000)) {
243         disturb(player_ptr, false, true);
244         msg_print(_("突然ほとんど孤独になった気がする。", "You suddenly feel almost lonely."));
245
246         banish_monsters(player_ptr, 100);
247         if (!is_in_dungeon(player_ptr) && player_ptr->town_num) {
248             StoreSaleType sst;
249             do {
250                 sst = i2enum<StoreSaleType>(randint0(MAX_STORES));
251             } while ((sst == StoreSaleType::HOME) || (sst == StoreSaleType::MUSEUM));
252
253             msg_print(_("店の主人が丘に向かって走っている!", "You see one of the shopkeepers running for the hills!"));
254             store_shuffle(player_ptr, sst);
255         }
256         msg_print(nullptr);
257     }
258
259     if (player_ptr->muta.has(PlayerMutationType::EAT_LIGHT) && one_in_(3000)) {
260         ObjectType *o_ptr;
261
262         msg_print(_("影につつまれた。", "A shadow passes over you."));
263         msg_print(nullptr);
264
265         if ((player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x].info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW) {
266             hp_player(player_ptr, 10);
267         }
268
269         o_ptr = &player_ptr->inventory_list[INVEN_LITE];
270
271         if (o_ptr->tval == ItemKindType::LITE) {
272             if (!o_ptr->is_fixed_artifact() && (o_ptr->fuel > 0)) {
273                 hp_player(player_ptr, o_ptr->fuel / 20);
274                 o_ptr->fuel /= 2;
275                 msg_print(_("光源からエネルギーを吸収した!", "You absorb energy from your light!"));
276                 notice_lite_change(player_ptr, o_ptr);
277             }
278         }
279
280         /*
281          * Unlite the area (radius 10) around player and
282          * do 50 points damage to every affected monster
283          */
284         unlite_area(player_ptr, 50, 10);
285     }
286
287     if (player_ptr->muta.has(PlayerMutationType::ATT_ANIMAL) && !player_ptr->anti_magic && one_in_(7000)) {
288         bool pet = one_in_(3);
289         BIT_FLAGS mode = PM_ALLOW_GROUP;
290
291         if (pet)
292             mode |= PM_FORCE_PET;
293         else
294             mode |= (PM_ALLOW_UNIQUE | PM_NO_PET);
295
296         if (summon_specific(player_ptr, (pet ? -1 : 0), player_ptr->y, player_ptr->x, player_ptr->current_floor_ptr->dun_level, SUMMON_ANIMAL, mode)) {
297             msg_print(_("動物を引き寄せた!", "You have attracted an animal!"));
298             disturb(player_ptr, false, true);
299         }
300     }
301
302     if (player_ptr->muta.has(PlayerMutationType::RAW_CHAOS) && !player_ptr->anti_magic && one_in_(8000)) {
303         disturb(player_ptr, false, true);
304         msg_print(_("周りの空間が歪んでいる気がする!", "You feel the world warping around you!"));
305         msg_print(nullptr);
306         fire_ball(player_ptr, AttributeType::CHAOS, 0, player_ptr->lev, 8);
307     }
308
309     if (player_ptr->muta.has(PlayerMutationType::NORMALITY) && one_in_(5000)) {
310         if (!lose_mutation(player_ptr, 0))
311             msg_print(_("奇妙なくらい普通になった気がする。", "You feel oddly normal."));
312     }
313
314     if (player_ptr->muta.has(PlayerMutationType::WRAITH) && !player_ptr->anti_magic && one_in_(3000)) {
315         disturb(player_ptr, false, true);
316         msg_print(_("非物質化した!", "You feel insubstantial!"));
317         msg_print(nullptr);
318         set_wraith_form(player_ptr, randint1(player_ptr->lev / 2) + (player_ptr->lev / 2), false);
319     }
320
321     if (player_ptr->muta.has(PlayerMutationType::POLY_WOUND) && one_in_(3000))
322         do_poly_wounds(player_ptr);
323
324     if (player_ptr->muta.has(PlayerMutationType::WASTING) && one_in_(3000)) {
325         int which_stat = randint0(A_MAX);
326         int sustained = false;
327
328         switch (which_stat) {
329         case A_STR:
330             if (has_sustain_str(player_ptr))
331                 sustained = true;
332             break;
333         case A_INT:
334             if (has_sustain_int(player_ptr))
335                 sustained = true;
336             break;
337         case A_WIS:
338             if (has_sustain_wis(player_ptr))
339                 sustained = true;
340             break;
341         case A_DEX:
342             if (has_sustain_dex(player_ptr))
343                 sustained = true;
344             break;
345         case A_CON:
346             if (has_sustain_con(player_ptr))
347                 sustained = true;
348             break;
349         case A_CHR:
350             if (has_sustain_chr(player_ptr))
351                 sustained = true;
352             break;
353         default:
354             msg_print(_("不正な状態!", "Invalid stat chosen!"));
355             sustained = true;
356         }
357
358         if (!sustained) {
359             disturb(player_ptr, false, true);
360             msg_print(_("自分が衰弱していくのが分かる!", "You can feel yourself wasting away!"));
361             msg_print(nullptr);
362             (void)dec_stat(player_ptr, which_stat, randint1(6) + 6, one_in_(3));
363         }
364     }
365
366     if (player_ptr->muta.has(PlayerMutationType::ATT_DRAGON) && !player_ptr->anti_magic && one_in_(3000)) {
367         bool pet = one_in_(5);
368         BIT_FLAGS mode = PM_ALLOW_GROUP;
369         if (pet)
370             mode |= PM_FORCE_PET;
371         else
372             mode |= (PM_ALLOW_UNIQUE | PM_NO_PET);
373
374         if (summon_specific(player_ptr, (pet ? -1 : 0), player_ptr->y, player_ptr->x, player_ptr->current_floor_ptr->dun_level, SUMMON_DRAGON, mode)) {
375             msg_print(_("ドラゴンを引き寄せた!", "You have attracted a dragon!"));
376             disturb(player_ptr, false, true);
377         }
378     }
379
380     if (player_ptr->muta.has(PlayerMutationType::WEIRD_MIND) && !player_ptr->anti_magic && one_in_(3000)) {
381         if (player_ptr->tim_esp > 0) {
382             msg_print(_("精神にもやがかかった!", "Your mind feels cloudy!"));
383             set_tim_esp(player_ptr, 0, true);
384         } else {
385             msg_print(_("精神が広がった!", "Your mind expands!"));
386             set_tim_esp(player_ptr, player_ptr->lev, false);
387         }
388     }
389
390     if (player_ptr->muta.has(PlayerMutationType::NAUSEA) && !player_ptr->slow_digest && one_in_(9000)) {
391         disturb(player_ptr, false, true);
392         msg_print(_("胃が痙攣し、食事を失った!", "Your stomach roils, and you lose your lunch!"));
393         msg_print(nullptr);
394         set_food(player_ptr, PY_FOOD_WEAK);
395         if (music_singing_any(player_ptr))
396             stop_singing(player_ptr);
397
398         SpellHex spell_hex(player_ptr);
399         if (spell_hex.is_spelling_any()) {
400             (void)spell_hex.stop_all_spells();
401         }
402     }
403
404     if (player_ptr->muta.has(PlayerMutationType::WALK_SHAD) && !player_ptr->anti_magic && one_in_(12000) && !player_ptr->current_floor_ptr->inside_arena)
405         reserve_alter_reality(player_ptr, randint0(21) + 15);
406
407     if (player_ptr->muta.has(PlayerMutationType::WARNING) && one_in_(1000)) {
408         int danger_amount = 0;
409         for (MONSTER_IDX monster = 0; monster < player_ptr->current_floor_ptr->m_max; monster++) {
410             auto *m_ptr = &player_ptr->current_floor_ptr->m_list[monster];
411             auto *r_ptr = &r_info[m_ptr->r_idx];
412             if (!monster_is_valid(m_ptr))
413                 continue;
414
415             if (r_ptr->level >= player_ptr->lev) {
416                 danger_amount += r_ptr->level - player_ptr->lev + 1;
417             }
418         }
419
420         if (danger_amount > 100)
421             msg_print(_("非常に恐ろしい気がする!", "You feel utterly terrified!"));
422         else if (danger_amount > 50)
423             msg_print(_("恐ろしい気がする!", "You feel terrified!"));
424         else if (danger_amount > 20)
425             msg_print(_("非常に心配な気がする!", "You feel very worried!"));
426         else if (danger_amount > 10)
427             msg_print(_("心配な気がする!", "You feel paranoid!"));
428         else if (danger_amount > 5)
429             msg_print(_("ほとんど安全な気がする。", "You feel almost safe."));
430         else
431             msg_print(_("寂しい気がする。", "You feel lonely."));
432     }
433
434     if (player_ptr->muta.has(PlayerMutationType::INVULN) && !player_ptr->anti_magic && one_in_(5000)) {
435         disturb(player_ptr, false, true);
436         msg_print(_("無敵な気がする!", "You feel invincible!"));
437         msg_print(nullptr);
438         (void)set_invuln(player_ptr, randint1(8) + 8, false);
439     }
440
441     if (player_ptr->muta.has(PlayerMutationType::SP_TO_HP) && one_in_(2000)) {
442         MANA_POINT wounds = (MANA_POINT)(player_ptr->mhp - player_ptr->chp);
443         if (wounds > 0) {
444             HIT_POINT healing = player_ptr->csp;
445             if (healing > wounds)
446                 healing = wounds;
447
448             hp_player(player_ptr, healing);
449             player_ptr->csp -= healing;
450             player_ptr->redraw |= (PR_HP | PR_MANA);
451         }
452     }
453
454     if (player_ptr->muta.has(PlayerMutationType::HP_TO_SP) && !player_ptr->anti_magic && one_in_(4000)) {
455         HIT_POINT wounds = (HIT_POINT)(player_ptr->msp - player_ptr->csp);
456         if (wounds > 0) {
457             HIT_POINT healing = player_ptr->chp;
458             if (healing > wounds)
459                 healing = wounds;
460
461             player_ptr->csp += healing;
462             player_ptr->redraw |= (PR_HP | PR_MANA);
463             take_hit(player_ptr, DAMAGE_LOSELIFE, healing, _("頭に昇った血", "blood rushing to the head"));
464         }
465     }
466
467     if (player_ptr->muta.has(PlayerMutationType::DISARM) && one_in_(10000)) {
468         disturb(player_ptr, false, true);
469         msg_print(_("足がもつれて転んだ!", "You trip over your own feet!"));
470         take_hit(player_ptr, DAMAGE_NOESCAPE, randint1(player_ptr->wt / 6), _("転倒", "tripping"));
471         drop_weapons(player_ptr);
472     }
473 }
474
475 bool drop_weapons(PlayerType *player_ptr)
476 {
477     INVENTORY_IDX slot = 0;
478     ObjectType *o_ptr = nullptr;
479
480     if (player_ptr->wild_mode)
481         return false;
482
483     msg_print(nullptr);
484     if (has_melee_weapon(player_ptr, INVEN_MAIN_HAND)) {
485         slot = INVEN_MAIN_HAND;
486         o_ptr = &player_ptr->inventory_list[INVEN_MAIN_HAND];
487
488         if (has_melee_weapon(player_ptr, INVEN_SUB_HAND) && one_in_(2)) {
489             o_ptr = &player_ptr->inventory_list[INVEN_SUB_HAND];
490             slot = INVEN_SUB_HAND;
491         }
492     } else if (has_melee_weapon(player_ptr, INVEN_SUB_HAND)) {
493         o_ptr = &player_ptr->inventory_list[INVEN_SUB_HAND];
494         slot = INVEN_SUB_HAND;
495     }
496
497     if ((slot == 0) || o_ptr->is_cursed())
498         return false;
499
500     msg_print(_("武器を落としてしまった!", "You drop your weapon!"));
501     drop_from_inventory(player_ptr, slot, 1);
502     return true;
503 }