1 #include "player/player-damage.h"
2 #include "autopick/autopick-pref-processor.h"
3 #include "avatar/avatar.h"
4 #include "blue-magic/blue-magic-checker.h"
5 #include "cmd-io/cmd-process-screen.h"
6 #include "core/asking-player.h"
7 #include "core/disturbance.h"
8 #include "core/player-redraw-types.h"
9 #include "core/stuff-handler.h"
10 #include "core/window-redrawer.h"
11 #include "dungeon/quest.h"
12 #include "flavor/flavor-describer.h"
13 #include "flavor/object-flavor-types.h"
14 #include "floor/wild.h"
15 #include "game-option/birth-options.h"
16 #include "game-option/cheat-options.h"
17 #include "game-option/game-play-options.h"
18 #include "game-option/input-options.h"
19 #include "game-option/play-record-options.h"
20 #include "game-option/special-options.h"
21 #include "inventory/inventory-damage.h"
22 #include "inventory/inventory-slot-types.h"
23 #include "io/files-util.h"
24 #include "io/input-key-acceptor.h"
25 #include "io/report.h"
26 #include "io/write-diary.h"
27 #include "main/music-definitions-table.h"
28 #include "main/sound-definitions-table.h"
29 #include "main/sound-of-music.h"
30 #include "market/arena-info-table.h"
31 #include "mind/mind-mirror-master.h"
32 #include "monster-race/monster-race.h"
33 #include "monster-race/race-flags2.h"
34 #include "monster-race/race-flags3.h"
35 #include "monster/monster-describer.h"
36 #include "monster/monster-description-types.h"
37 #include "monster/monster-info.h"
38 #include "mutation/mutation-flag-types.h"
39 #include "object-enchant/tr-types.h"
40 #include "object-hook/hook-armor.h"
41 #include "object/item-tester-hooker.h"
42 #include "object/object-broken.h"
43 #include "object/object-flags.h"
44 #include "player-base/player-class.h"
45 #include "player-base/player-race.h"
46 #include "player-info/class-info.h"
47 #include "player-info/race-types.h"
48 #include "player-info/samurai-data-type.h"
49 #include "player/player-personality-types.h"
50 #include "player/player-status-flags.h"
51 #include "player/player-status-resist.h"
52 #include "player/player-status.h"
53 #include "player/race-info-table.h"
54 #include "player/special-defense-types.h"
55 #include "racial/racial-android.h"
56 #include "save/save.h"
57 #include "status/base-status.h"
58 #include "status/element-resistance.h"
59 #include "system/building-type-definition.h"
60 #include "system/dungeon-info.h"
61 #include "system/floor-type-definition.h"
62 #include "system/item-entity.h"
63 #include "system/monster-entity.h"
64 #include "system/monster-race-info.h"
65 #include "system/player-type-definition.h"
66 #include "system/redrawing-flags-updater.h"
67 #include "term/screen-processor.h"
68 #include "term/term-color-types.h"
69 #include "timed-effect/player-hallucination.h"
70 #include "timed-effect/player-paralysis.h"
71 #include "timed-effect/timed-effects.h"
72 #include "util/bit-flags-calculator.h"
73 #include "util/string-processor.h"
74 #include "view/display-messages.h"
75 #include "world/world.h"
79 using dam_func = int (*)(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura);
82 * @brief 酸攻撃による装備のAC劣化処理 /
83 * Acid has hit the player, attempt to affect some armor.
84 * @param 酸を浴びたキャラクタへの参照ポインタ
85 * @return 装備による軽減があったならTRUEを返す
87 * 免疫があったらそもそもこの関数は実行されない (確実に錆びない).
88 * Note that the "base armor" of an object never changes.
89 * If any armor is damaged (or resists), the player takes less damage.
91 static bool acid_minus_ac(PlayerType *player_ptr)
93 constexpr static auto candidates = {
103 const auto slot = rand_choice(candidates);
104 auto *o_ptr = &player_ptr->inventory_list[slot];
106 if ((o_ptr == nullptr) || !o_ptr->is_valid() || !o_ptr->is_protector()) {
110 const auto item_name = describe_flavor(player_ptr, o_ptr, OD_OMIT_PREFIX | OD_NAME_ONLY);
111 auto flags = object_flags(o_ptr);
112 if (o_ptr->ac + o_ptr->to_a <= 0) {
113 msg_format(_("%sは既にボロボロだ!", "Your %s is already fully corroded!"), item_name.data());
117 if (flags.has(TR_IGNORE_ACID)) {
118 msg_format(_("しかし%sには効果がなかった!", "Your %s is unaffected!"), item_name.data());
122 msg_format(_("%sが酸で腐食した!", "Your %s is corroded!"), item_name.data());
124 auto &rfu = RedrawingFlagsUpdater::get_instance();
125 rfu.set_flag(StatusRedrawingFlag::BONUS);
126 player_ptr->window_flags |= PW_EQUIPMENT | PW_PLAYER;
127 calc_android_exp(player_ptr);
132 * @brief 酸属性によるプレイヤー損害処理 /
133 * Hurt the player with Acid
134 * @param player_ptr 酸を浴びたキャラクタへの参照ポインタ
136 * @param kb_str ダメージ原因記述
137 * @param monspell 原因となったモンスター特殊攻撃ID
138 * @param aura オーラよるダメージが原因ならばTRUE
140 * @details 酸オーラは存在しないが関数ポインタのために引数だけは用意している
142 int acid_dam(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura)
144 int inv = (dam < 30) ? 1 : (dam < 60) ? 2
146 bool double_resist = is_oppose_acid(player_ptr);
147 dam = dam * calc_acid_damage_rate(player_ptr) / 100;
152 if (aura || !check_multishadow(player_ptr)) {
153 if ((!(double_resist || has_resist_acid(player_ptr))) && one_in_(CHANCE_ABILITY_SCORE_DECREASE)) {
154 (void)do_dec_stat(player_ptr, A_CHR);
157 if (acid_minus_ac(player_ptr)) {
162 int get_damage = take_hit(player_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str);
163 if (!aura && !(double_resist && has_resist_acid(player_ptr))) {
164 inventory_damage(player_ptr, BreakerAcid(), inv);
171 * @brief 電撃属性によるプレイヤー損害処理 /
172 * Hurt the player with electricity
173 * @param player_ptr 電撃を浴びたキャラクタへの参照ポインタ
175 * @param kb_str ダメージ原因記述
176 * @param monspell 原因となったモンスター特殊攻撃ID
177 * @param aura オーラよるダメージが原因ならばTRUE
180 int elec_dam(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura)
182 int inv = (dam < 30) ? 1 : (dam < 60) ? 2
184 bool double_resist = is_oppose_elec(player_ptr);
186 dam = dam * calc_elec_damage_rate(player_ptr) / 100;
192 if (aura || !check_multishadow(player_ptr)) {
193 if ((!(double_resist || has_resist_elec(player_ptr))) && one_in_(CHANCE_ABILITY_SCORE_DECREASE)) {
194 (void)do_dec_stat(player_ptr, A_DEX);
198 int get_damage = take_hit(player_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str);
199 if (!aura && !(double_resist && has_resist_elec(player_ptr))) {
200 inventory_damage(player_ptr, BreakerElec(), inv);
207 * @brief 火炎属性によるプレイヤー損害処理 /
208 * Hurt the player with Fire
209 * @param player_ptr 火炎を浴びたキャラクタへの参照ポインタ
211 * @param kb_str ダメージ原因記述
212 * @param monspell 原因となったモンスター特殊攻撃ID
213 * @param aura オーラよるダメージが原因ならばTRUE
216 int fire_dam(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura)
218 int inv = (dam < 30) ? 1 : (dam < 60) ? 2
220 bool double_resist = is_oppose_fire(player_ptr);
223 if (has_immune_fire(player_ptr) || (dam <= 0)) {
227 dam = dam * calc_fire_damage_rate(player_ptr) / 100;
228 if (aura || !check_multishadow(player_ptr)) {
229 if ((!(double_resist || has_resist_fire(player_ptr))) && one_in_(CHANCE_ABILITY_SCORE_DECREASE)) {
230 (void)do_dec_stat(player_ptr, A_STR);
234 int get_damage = take_hit(player_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str);
235 if (!aura && !(double_resist && has_resist_fire(player_ptr))) {
236 inventory_damage(player_ptr, BreakerFire(), inv);
243 * @brief 冷気属性によるプレイヤー損害処理 /
244 * Hurt the player with Cold
245 * @param player_ptr 冷気を浴びたキャラクタへの参照ポインタ
247 * @param kb_str ダメージ原因記述
248 * @param monspell 原因となったモンスター特殊攻撃ID
249 * @param aura オーラよるダメージが原因ならばTRUE
252 int cold_dam(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura)
254 int inv = (dam < 30) ? 1 : (dam < 60) ? 2
256 bool double_resist = is_oppose_cold(player_ptr);
257 if (has_immune_cold(player_ptr) || (dam <= 0)) {
261 dam = dam * calc_cold_damage_rate(player_ptr) / 100;
262 if (aura || !check_multishadow(player_ptr)) {
263 if ((!(double_resist || has_resist_cold(player_ptr))) && one_in_(CHANCE_ABILITY_SCORE_DECREASE)) {
264 (void)do_dec_stat(player_ptr, A_STR);
268 int get_damage = take_hit(player_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str);
269 if (!aura && !(double_resist && has_resist_cold(player_ptr))) {
270 inventory_damage(player_ptr, BreakerCold(), inv);
277 * Decreases players hit points and sets death flag if necessary
279 * Invulnerability needs to be changed into a "shield"
281 * Hack -- this function allows the user to save (or quit)
282 * the game when he dies, since the "You die." message is shown before
283 * setting the player to "dead".
285 int take_hit(PlayerType *player_ptr, int damage_type, int damage, std::string_view hit_from)
287 int old_chp = player_ptr->chp;
288 int warning = (player_ptr->mhp * hitpoint_warn / 10);
289 if (player_ptr->is_dead) {
293 if (player_ptr->sutemi) {
296 if (PlayerClass(player_ptr).samurai_stance_is(SamuraiStanceType::IAI)) {
297 damage += (damage + 4) / 5;
300 if (damage_type != DAMAGE_USELIFE) {
301 disturb(player_ptr, true, true);
303 player_ptr->now_damaged = true;
307 if ((damage_type != DAMAGE_USELIFE) && (damage_type != DAMAGE_LOSELIFE)) {
308 if (is_invuln(player_ptr) && (damage < 9000)) {
309 if (damage_type == DAMAGE_FORCE) {
310 msg_print(_("バリアが切り裂かれた!", "The attack cuts your shield of invulnerability open!"));
311 } else if (one_in_(PENETRATE_INVULNERABILITY)) {
312 msg_print(_("無敵のバリアを破って攻撃された!", "The attack penetrates your shield of invulnerability!"));
318 if (check_multishadow(player_ptr)) {
319 if (damage_type == DAMAGE_FORCE) {
320 msg_print(_("幻影もろとも体が切り裂かれた!", "The attack hits Shadow together with you!"));
321 } else if (damage_type == DAMAGE_ATTACK) {
322 msg_print(_("攻撃は幻影に命中し、あなたには届かなかった。", "The attack hits Shadow, but you are unharmed!"));
327 if (player_ptr->wraith_form) {
328 if (damage_type == DAMAGE_FORCE) {
329 msg_print(_("半物質の体が切り裂かれた!", "The attack cuts through your ethereal body!"));
332 if ((damage == 0) && one_in_(2)) {
338 if (PlayerClass(player_ptr).samurai_stance_is(SamuraiStanceType::MUSOU)) {
340 if ((damage == 0) && one_in_(2)) {
346 player_ptr->chp -= damage;
347 if (player_ptr->chp < -9999) {
348 player_ptr->chp = -9999;
350 if (damage_type == DAMAGE_GENO && player_ptr->chp < 0) {
351 damage += player_ptr->chp;
355 auto &rfu = RedrawingFlagsUpdater::get_instance();
356 rfu.set_flag(MainWindowRedrawingFlag::HP);
357 player_ptr->window_flags |= PW_PLAYER;
359 if (damage_type != DAMAGE_GENO && player_ptr->chp == 0) {
360 chg_virtue(player_ptr, Virtue::SACRIFICE, 1);
361 chg_virtue(player_ptr, Virtue::CHANCE, 2);
364 if (player_ptr->chp < 0 && !cheat_immortal) {
365 bool android = PlayerRace(player_ptr).equals(PlayerRaceType::ANDROID);
367 /* 死んだ時に強制終了して死を回避できなくしてみた by Habu */
368 if (!cheat_save && !save_player(player_ptr, SaveType::CLOSE_GAME)) {
369 msg_print(_("セーブ失敗!", "death save failed!"));
373 chg_virtue(player_ptr, Virtue::SACRIFICE, 10);
374 handle_stuff(player_ptr);
375 player_ptr->leaving = true;
376 if (!cheat_immortal) {
377 player_ptr->is_dead = true;
380 const auto &floor_ref = *player_ptr->current_floor_ptr;
381 if (floor_ref.inside_arena) {
382 concptr m_name = monraces_info[arena_info[player_ptr->arena_number].r_idx].name.data();
383 msg_format(_("あなたは%sの前に敗れ去った。", "You are beaten by %s."), m_name);
386 exe_write_diary(player_ptr, DIARY_ARENA, -1 - player_ptr->arena_number, m_name);
389 const auto q_idx = quest_number(player_ptr, floor_ref.dun_level);
390 const auto seppuku = hit_from == "Seppuku";
391 const auto winning_seppuku = w_ptr->total_winner && seppuku;
393 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_GAMEOVER);
396 screen_dump = make_screen_dump(player_ptr);
399 player_ptr->died_from = hit_from;
400 if (!winning_seppuku) {
401 player_ptr->died_from = _("切腹", "Seppuku");
404 auto effects = player_ptr->effects();
405 auto is_hallucinated = effects->hallucination()->is_hallucinated();
406 auto paralysis_state = "";
407 if (effects->paralysis()->is_paralyzed()) {
408 paralysis_state = player_ptr->free_act ? _("彫像状態で", " while being the statue") : _("麻痺状態で", " while paralyzed");
411 auto hallucintion_state = is_hallucinated ? _("幻覚に歪んだ", "hallucinatingly distorted ") : "";
413 player_ptr->died_from = format("%s%s%s", paralysis_state, hallucintion_state, hit_from.data());
415 player_ptr->died_from = format("%s%s%s", hallucintion_state, hit_from.data(), paralysis_state);
419 w_ptr->total_winner = false;
420 if (winning_seppuku) {
421 add_retired_class(player_ptr->pclass);
422 exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, _("勝利の後切腹した。", "committed seppuku after the winning."));
426 if (floor_ref.inside_arena) {
427 place = _("アリーナ", "in the Arena");
428 } else if (!floor_ref.is_in_dungeon()) {
429 place = _("地上", "on the surface");
430 } else if (inside_quest(q_idx) && (QuestType::is_fixed(q_idx) && !((q_idx == QuestId::OBERON) || (q_idx == QuestId::SERPENT)))) {
431 place = _("クエスト", "in a quest");
433 place = format(_("%d階", "on level %d"), static_cast<int>(floor_ref.dun_level));
437 std::string note = format("%sで%sに殺された。", place.data(), player_ptr->died_from.data());
439 std::string note = format("killed by %s %s.", player_ptr->died_from.data(), place.data());
441 exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, note.data());
444 exe_write_diary(player_ptr, DIARY_GAMESTART, 1, _("-------- ゲームオーバー --------", "-------- Game Over --------"));
445 exe_write_diary(player_ptr, DIARY_DESCRIPTION, 1, "\n\n\n\n");
447 if (get_check_strict(player_ptr, _("画面を保存しますか?", "Dump the screen? "), CHECK_NO_HISTORY)) {
448 do_cmd_save_screen(player_ptr);
452 if (player_ptr->last_message) {
453 string_free(player_ptr->last_message);
456 player_ptr->last_message = nullptr;
459 msg_format("あなたは%sました。", android ? "壊れ" : "死に");
461 msg_print(android ? "You are broken." : "You die.");
466 std::optional<std::string> opt_death_message;
467 if (winning_seppuku) {
468 opt_death_message = get_random_line(_("seppuku_j.txt", "seppuku.txt"), 0);
470 opt_death_message = get_random_line(_("death_j.txt", "death.txt"), 0);
473 auto &death_message = opt_death_message.value();
474 constexpr auto max_last_words = 1024;
475 char player_last_words[max_last_words]{};
476 angband_strcpy(player_last_words, death_message.data(), max_last_words);
479 while (!get_string(winning_seppuku ? "辞世の句: " : "断末魔の叫び: ", player_last_words, max_last_words)) {
483 while (!get_string("Last words: ", player_last_words, max_last_words)) {
487 } while (winning_seppuku && !get_check_strict(player_ptr, _("よろしいですか?", "Are you sure? "), CHECK_NO_HISTORY));
489 death_message = player_last_words;
490 if (death_message.empty()) {
492 death_message = format("あなたは%sました。", android ? "壊れ" : "死に");
494 death_message = android ? "You are broken." : "You die.";
497 player_ptr->last_message = string_make(death_message.data());
501 if (winning_seppuku) {
503 int w = game_term->wid;
504 int h = game_term->hgt;
505 int msg_pos_x[9] = { 5, 7, 9, 12, 14, 17, 19, 21, 23 };
506 int msg_pos_y[9] = { 3, 4, 5, 4, 5, 4, 5, 6, 4 };
510 for (i = 0; i < 40; i++) {
511 term_putstr(randint0(w / 2) * 2, randint0(h), 2, TERM_VIOLET, "υ");
514 auto str = death_message.data();
515 if (strncmp(str, "「", 2) == 0) {
519 auto *str2 = angband_strstr(str, "」");
520 if (str2 != nullptr) {
526 str2 = angband_strstr(str, " ");
527 if (str2 == nullptr) {
534 term_putstr_v(w * 3 / 4 - 2 - msg_pos_x[i] * 2, msg_pos_y[i], len, TERM_WHITE, str);
535 if (str2 == nullptr) {
546 term_putstr(w - 1, h - 1, 1, TERM_WHITE, " ");
549 screen_dump = make_screen_dump(player_ptr);
554 msg_print(death_message);
561 handle_stuff(player_ptr);
562 if (player_ptr->chp < warning) {
563 if (old_chp > warning) {
568 if (record_danger && (old_chp > warning)) {
569 if (player_ptr->effects()->hallucination()->is_hallucinated() && damage_type == DAMAGE_ATTACK) {
570 hit_from = _("何か", "something");
573 std::stringstream ss;
574 ss << _(hit_from, "was in a critical situation because of ");
575 ss << _("によってピンチに陥った。", hit_from);
577 exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, ss.str().data());
581 player_ptr->now_damaged = true;
584 msg_print(_("*** 警告:低ヒット・ポイント! ***", "*** LOW HITPOINT WARNING! ***"));
589 if (player_ptr->wild_mode && !player_ptr->leaving && (player_ptr->chp < std::max(warning, player_ptr->mhp / 5))) {
590 change_wild_mode(player_ptr, false);
597 * @brief 属性に応じた敵オーラによるプレイヤーのダメージ処理
598 * @param m_ptr オーラを持つモンスターの構造体参照ポインタ
599 * @param immune ダメージを回避できる免疫フラグ
600 * @param flags_offset オーラフラグ配列の参照オフセット
601 * @param r_flags_offset モンスターの耐性配列の参照オフセット
602 * @param aura_flag オーラフラグ配列
603 * @param dam_func ダメージ処理を行う関数の参照ポインタ
604 * @param message オーラダメージを受けた際のメッセージ
606 static void process_aura_damage(MonsterEntity *m_ptr, PlayerType *player_ptr, bool immune, MonsterAuraType aura_flag, dam_func dam_func, concptr message)
608 auto *r_ptr = &monraces_info[m_ptr->r_idx];
609 if (r_ptr->aura_flags.has_not(aura_flag) || immune) {
613 int aura_damage = damroll(1 + (r_ptr->level / 26), 1 + (r_ptr->level / 17));
615 (*dam_func)(player_ptr, aura_damage, monster_desc(player_ptr, m_ptr, MD_WRONGDOER_NAME).data(), true);
616 if (is_original_ap_and_seen(player_ptr, m_ptr)) {
617 r_ptr->r_aura_flags.set(aura_flag);
620 handle_stuff(player_ptr);
624 * @brief 敵オーラによるプレイヤーのダメージ処理
625 * @param m_ptr オーラを持つモンスターの構造体参照ポインタ
626 * @param player_ptr プレイヤーへの参照ポインタ
628 void touch_zap_player(MonsterEntity *m_ptr, PlayerType *player_ptr)
630 constexpr auto fire_mes = _("突然とても熱くなった!", "You are suddenly very hot!");
631 constexpr auto cold_mes = _("突然とても寒くなった!", "You are suddenly very cold!");
632 constexpr auto elec_mes = _("電撃をくらった!", "You get zapped!");
633 process_aura_damage(m_ptr, player_ptr, has_immune_fire(player_ptr) != 0, MonsterAuraType::FIRE, fire_dam, fire_mes);
634 process_aura_damage(m_ptr, player_ptr, has_immune_cold(player_ptr) != 0, MonsterAuraType::COLD, cold_dam, cold_mes);
635 process_aura_damage(m_ptr, player_ptr, has_immune_elec(player_ptr) != 0, MonsterAuraType::ELEC, elec_dam, elec_mes);