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/stuff-handler.h"
9 #include "core/window-redrawer.h"
10 #include "dungeon/quest.h"
11 #include "flavor/flavor-describer.h"
12 #include "flavor/object-flavor-types.h"
13 #include "floor/wild.h"
14 #include "game-option/birth-options.h"
15 #include "game-option/cheat-options.h"
16 #include "game-option/game-play-options.h"
17 #include "game-option/input-options.h"
18 #include "game-option/play-record-options.h"
19 #include "game-option/special-options.h"
20 #include "inventory/inventory-damage.h"
21 #include "inventory/inventory-slot-types.h"
22 #include "io/files-util.h"
23 #include "io/input-key-acceptor.h"
24 #include "io/report.h"
25 #include "io/write-diary.h"
26 #include "main/music-definitions-table.h"
27 #include "main/sound-definitions-table.h"
28 #include "main/sound-of-music.h"
29 #include "market/arena-info-table.h"
30 #include "mind/mind-mirror-master.h"
31 #include "monster-race/monster-race.h"
32 #include "monster-race/race-flags2.h"
33 #include "monster-race/race-flags3.h"
34 #include "monster/monster-describer.h"
35 #include "monster/monster-description-types.h"
36 #include "monster/monster-info.h"
37 #include "mutation/mutation-flag-types.h"
38 #include "object-enchant/tr-types.h"
39 #include "object-hook/hook-armor.h"
40 #include "object/item-tester-hooker.h"
41 #include "object/object-broken.h"
42 #include "object/object-flags.h"
43 #include "player-base/player-class.h"
44 #include "player-base/player-race.h"
45 #include "player-info/class-info.h"
46 #include "player-info/race-types.h"
47 #include "player-info/samurai-data-type.h"
48 #include "player/player-personality-types.h"
49 #include "player/player-status-flags.h"
50 #include "player/player-status-resist.h"
51 #include "player/player-status.h"
52 #include "player/race-info-table.h"
53 #include "player/special-defense-types.h"
54 #include "racial/racial-android.h"
55 #include "save/save.h"
56 #include "status/base-status.h"
57 #include "status/element-resistance.h"
58 #include "system/building-type-definition.h"
59 #include "system/dungeon-info.h"
60 #include "system/floor-type-definition.h"
61 #include "system/item-entity.h"
62 #include "system/monster-entity.h"
63 #include "system/monster-race-info.h"
64 #include "system/player-type-definition.h"
65 #include "system/redrawing-flags-updater.h"
66 #include "term/screen-processor.h"
67 #include "term/term-color-types.h"
68 #include "timed-effect/player-hallucination.h"
69 #include "timed-effect/player-paralysis.h"
70 #include "timed-effect/timed-effects.h"
71 #include "util/bit-flags-calculator.h"
72 #include "util/string-processor.h"
73 #include "view/display-messages.h"
74 #include "world/world.h"
78 using dam_func = int (*)(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura);
81 * @brief 酸攻撃による装備のAC劣化処理 /
82 * Acid has hit the player, attempt to affect some armor.
83 * @param 酸を浴びたキャラクタへの参照ポインタ
84 * @return 装備による軽減があったならTRUEを返す
86 * 免疫があったらそもそもこの関数は実行されない (確実に錆びない).
87 * Note that the "base armor" of an object never changes.
88 * If any armor is damaged (or resists), the player takes less damage.
90 static bool acid_minus_ac(PlayerType *player_ptr)
92 constexpr static auto candidates = {
102 const auto slot = rand_choice(candidates);
103 auto *o_ptr = &player_ptr->inventory_list[slot];
105 if ((o_ptr == nullptr) || !o_ptr->is_valid() || !o_ptr->is_protector()) {
109 const auto item_name = describe_flavor(player_ptr, o_ptr, OD_OMIT_PREFIX | OD_NAME_ONLY);
110 auto flags = object_flags(o_ptr);
111 if (o_ptr->ac + o_ptr->to_a <= 0) {
112 msg_format(_("%sは既にボロボロだ!", "Your %s is already fully corroded!"), item_name.data());
116 if (flags.has(TR_IGNORE_ACID)) {
117 msg_format(_("しかし%sには効果がなかった!", "Your %s is unaffected!"), item_name.data());
121 msg_format(_("%sが酸で腐食した!", "Your %s is corroded!"), item_name.data());
123 auto &rfu = RedrawingFlagsUpdater::get_instance();
124 rfu.set_flag(StatusRedrawingFlag::BONUS);
125 player_ptr->window_flags |= PW_EQUIPMENT | PW_PLAYER;
126 calc_android_exp(player_ptr);
131 * @brief 酸属性によるプレイヤー損害処理 /
132 * Hurt the player with Acid
133 * @param player_ptr 酸を浴びたキャラクタへの参照ポインタ
135 * @param kb_str ダメージ原因記述
136 * @param monspell 原因となったモンスター特殊攻撃ID
137 * @param aura オーラよるダメージが原因ならばTRUE
139 * @details 酸オーラは存在しないが関数ポインタのために引数だけは用意している
141 int acid_dam(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura)
143 int inv = (dam < 30) ? 1 : (dam < 60) ? 2
145 bool double_resist = is_oppose_acid(player_ptr);
146 dam = dam * calc_acid_damage_rate(player_ptr) / 100;
151 if (aura || !check_multishadow(player_ptr)) {
152 if ((!(double_resist || has_resist_acid(player_ptr))) && one_in_(CHANCE_ABILITY_SCORE_DECREASE)) {
153 (void)do_dec_stat(player_ptr, A_CHR);
156 if (acid_minus_ac(player_ptr)) {
161 int get_damage = take_hit(player_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str);
162 if (!aura && !(double_resist && has_resist_acid(player_ptr))) {
163 inventory_damage(player_ptr, BreakerAcid(), inv);
170 * @brief 電撃属性によるプレイヤー損害処理 /
171 * Hurt the player with electricity
172 * @param player_ptr 電撃を浴びたキャラクタへの参照ポインタ
174 * @param kb_str ダメージ原因記述
175 * @param monspell 原因となったモンスター特殊攻撃ID
176 * @param aura オーラよるダメージが原因ならばTRUE
179 int elec_dam(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura)
181 int inv = (dam < 30) ? 1 : (dam < 60) ? 2
183 bool double_resist = is_oppose_elec(player_ptr);
185 dam = dam * calc_elec_damage_rate(player_ptr) / 100;
191 if (aura || !check_multishadow(player_ptr)) {
192 if ((!(double_resist || has_resist_elec(player_ptr))) && one_in_(CHANCE_ABILITY_SCORE_DECREASE)) {
193 (void)do_dec_stat(player_ptr, A_DEX);
197 int get_damage = take_hit(player_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str);
198 if (!aura && !(double_resist && has_resist_elec(player_ptr))) {
199 inventory_damage(player_ptr, BreakerElec(), inv);
206 * @brief 火炎属性によるプレイヤー損害処理 /
207 * Hurt the player with Fire
208 * @param player_ptr 火炎を浴びたキャラクタへの参照ポインタ
210 * @param kb_str ダメージ原因記述
211 * @param monspell 原因となったモンスター特殊攻撃ID
212 * @param aura オーラよるダメージが原因ならばTRUE
215 int fire_dam(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura)
217 int inv = (dam < 30) ? 1 : (dam < 60) ? 2
219 bool double_resist = is_oppose_fire(player_ptr);
222 if (has_immune_fire(player_ptr) || (dam <= 0)) {
226 dam = dam * calc_fire_damage_rate(player_ptr) / 100;
227 if (aura || !check_multishadow(player_ptr)) {
228 if ((!(double_resist || has_resist_fire(player_ptr))) && one_in_(CHANCE_ABILITY_SCORE_DECREASE)) {
229 (void)do_dec_stat(player_ptr, A_STR);
233 int get_damage = take_hit(player_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str);
234 if (!aura && !(double_resist && has_resist_fire(player_ptr))) {
235 inventory_damage(player_ptr, BreakerFire(), inv);
242 * @brief 冷気属性によるプレイヤー損害処理 /
243 * Hurt the player with Cold
244 * @param player_ptr 冷気を浴びたキャラクタへの参照ポインタ
246 * @param kb_str ダメージ原因記述
247 * @param monspell 原因となったモンスター特殊攻撃ID
248 * @param aura オーラよるダメージが原因ならばTRUE
251 int cold_dam(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura)
253 int inv = (dam < 30) ? 1 : (dam < 60) ? 2
255 bool double_resist = is_oppose_cold(player_ptr);
256 if (has_immune_cold(player_ptr) || (dam <= 0)) {
260 dam = dam * calc_cold_damage_rate(player_ptr) / 100;
261 if (aura || !check_multishadow(player_ptr)) {
262 if ((!(double_resist || has_resist_cold(player_ptr))) && one_in_(CHANCE_ABILITY_SCORE_DECREASE)) {
263 (void)do_dec_stat(player_ptr, A_STR);
267 int get_damage = take_hit(player_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str);
268 if (!aura && !(double_resist && has_resist_cold(player_ptr))) {
269 inventory_damage(player_ptr, BreakerCold(), inv);
276 * Decreases players hit points and sets death flag if necessary
278 * Invulnerability needs to be changed into a "shield"
280 * Hack -- this function allows the user to save (or quit)
281 * the game when he dies, since the "You die." message is shown before
282 * setting the player to "dead".
284 int take_hit(PlayerType *player_ptr, int damage_type, int damage, std::string_view hit_from)
286 int old_chp = player_ptr->chp;
287 int warning = (player_ptr->mhp * hitpoint_warn / 10);
288 if (player_ptr->is_dead) {
292 if (player_ptr->sutemi) {
295 if (PlayerClass(player_ptr).samurai_stance_is(SamuraiStanceType::IAI)) {
296 damage += (damage + 4) / 5;
299 if (damage_type != DAMAGE_USELIFE) {
300 disturb(player_ptr, true, true);
302 player_ptr->now_damaged = true;
306 if ((damage_type != DAMAGE_USELIFE) && (damage_type != DAMAGE_LOSELIFE)) {
307 if (is_invuln(player_ptr) && (damage < 9000)) {
308 if (damage_type == DAMAGE_FORCE) {
309 msg_print(_("バリアが切り裂かれた!", "The attack cuts your shield of invulnerability open!"));
310 } else if (one_in_(PENETRATE_INVULNERABILITY)) {
311 msg_print(_("無敵のバリアを破って攻撃された!", "The attack penetrates your shield of invulnerability!"));
317 if (check_multishadow(player_ptr)) {
318 if (damage_type == DAMAGE_FORCE) {
319 msg_print(_("幻影もろとも体が切り裂かれた!", "The attack hits Shadow together with you!"));
320 } else if (damage_type == DAMAGE_ATTACK) {
321 msg_print(_("攻撃は幻影に命中し、あなたには届かなかった。", "The attack hits Shadow, but you are unharmed!"));
326 if (player_ptr->wraith_form) {
327 if (damage_type == DAMAGE_FORCE) {
328 msg_print(_("半物質の体が切り裂かれた!", "The attack cuts through your ethereal body!"));
331 if ((damage == 0) && one_in_(2)) {
337 if (PlayerClass(player_ptr).samurai_stance_is(SamuraiStanceType::MUSOU)) {
339 if ((damage == 0) && one_in_(2)) {
345 player_ptr->chp -= damage;
346 if (player_ptr->chp < -9999) {
347 player_ptr->chp = -9999;
349 if (damage_type == DAMAGE_GENO && player_ptr->chp < 0) {
350 damage += player_ptr->chp;
354 auto &rfu = RedrawingFlagsUpdater::get_instance();
355 rfu.set_flag(MainWindowRedrawingFlag::HP);
356 player_ptr->window_flags |= PW_PLAYER;
358 if (damage_type != DAMAGE_GENO && player_ptr->chp == 0) {
359 chg_virtue(player_ptr, Virtue::SACRIFICE, 1);
360 chg_virtue(player_ptr, Virtue::CHANCE, 2);
363 if (player_ptr->chp < 0 && !cheat_immortal) {
364 bool android = PlayerRace(player_ptr).equals(PlayerRaceType::ANDROID);
366 /* 死んだ時に強制終了して死を回避できなくしてみた by Habu */
367 if (!cheat_save && !save_player(player_ptr, SaveType::CLOSE_GAME)) {
368 msg_print(_("セーブ失敗!", "death save failed!"));
372 chg_virtue(player_ptr, Virtue::SACRIFICE, 10);
373 handle_stuff(player_ptr);
374 player_ptr->leaving = true;
375 if (!cheat_immortal) {
376 player_ptr->is_dead = true;
379 const auto &floor_ref = *player_ptr->current_floor_ptr;
380 if (floor_ref.inside_arena) {
381 concptr m_name = monraces_info[arena_info[player_ptr->arena_number].r_idx].name.data();
382 msg_format(_("あなたは%sの前に敗れ去った。", "You are beaten by %s."), m_name);
385 exe_write_diary(player_ptr, DIARY_ARENA, -1 - player_ptr->arena_number, m_name);
388 const auto q_idx = quest_number(player_ptr, floor_ref.dun_level);
389 const auto seppuku = hit_from == "Seppuku";
390 const auto winning_seppuku = w_ptr->total_winner && seppuku;
392 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_GAMEOVER);
395 screen_dump = make_screen_dump(player_ptr);
398 player_ptr->died_from = hit_from;
399 if (!winning_seppuku) {
400 player_ptr->died_from = _("切腹", "Seppuku");
403 auto effects = player_ptr->effects();
404 auto is_hallucinated = effects->hallucination()->is_hallucinated();
405 auto paralysis_state = "";
406 if (effects->paralysis()->is_paralyzed()) {
407 paralysis_state = player_ptr->free_act ? _("彫像状態で", " while being the statue") : _("麻痺状態で", " while paralyzed");
410 auto hallucintion_state = is_hallucinated ? _("幻覚に歪んだ", "hallucinatingly distorted ") : "";
412 player_ptr->died_from = format("%s%s%s", paralysis_state, hallucintion_state, hit_from.data());
414 player_ptr->died_from = format("%s%s%s", hallucintion_state, hit_from.data(), paralysis_state);
418 w_ptr->total_winner = false;
419 if (winning_seppuku) {
420 add_retired_class(player_ptr->pclass);
421 exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, _("勝利の後切腹した。", "committed seppuku after the winning."));
425 if (floor_ref.inside_arena) {
426 place = _("アリーナ", "in the Arena");
427 } else if (!floor_ref.is_in_dungeon()) {
428 place = _("地上", "on the surface");
429 } else if (inside_quest(q_idx) && (QuestType::is_fixed(q_idx) && !((q_idx == QuestId::OBERON) || (q_idx == QuestId::SERPENT)))) {
430 place = _("クエスト", "in a quest");
432 place = format(_("%d階", "on level %d"), static_cast<int>(floor_ref.dun_level));
436 std::string note = format("%sで%sに殺された。", place.data(), player_ptr->died_from.data());
438 std::string note = format("killed by %s %s.", player_ptr->died_from.data(), place.data());
440 exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, note.data());
443 exe_write_diary(player_ptr, DIARY_GAMESTART, 1, _("-------- ゲームオーバー --------", "-------- Game Over --------"));
444 exe_write_diary(player_ptr, DIARY_DESCRIPTION, 1, "\n\n\n\n");
446 if (get_check_strict(player_ptr, _("画面を保存しますか?", "Dump the screen? "), CHECK_NO_HISTORY)) {
447 do_cmd_save_screen(player_ptr);
451 if (player_ptr->last_message) {
452 string_free(player_ptr->last_message);
455 player_ptr->last_message = nullptr;
458 msg_format("あなたは%sました。", android ? "壊れ" : "死に");
460 msg_print(android ? "You are broken." : "You die.");
465 std::optional<std::string> opt_death_message;
466 if (winning_seppuku) {
467 opt_death_message = get_random_line(_("seppuku_j.txt", "seppuku.txt"), 0);
469 opt_death_message = get_random_line(_("death_j.txt", "death.txt"), 0);
472 auto &death_message = opt_death_message.value();
473 constexpr auto max_last_words = 1024;
474 char player_last_words[max_last_words]{};
475 angband_strcpy(player_last_words, death_message.data(), max_last_words);
478 while (!get_string(winning_seppuku ? "辞世の句: " : "断末魔の叫び: ", player_last_words, max_last_words)) {
482 while (!get_string("Last words: ", player_last_words, max_last_words)) {
486 } while (winning_seppuku && !get_check_strict(player_ptr, _("よろしいですか?", "Are you sure? "), CHECK_NO_HISTORY));
488 death_message = player_last_words;
489 if (death_message.empty()) {
491 death_message = format("あなたは%sました。", android ? "壊れ" : "死に");
493 death_message = android ? "You are broken." : "You die.";
496 player_ptr->last_message = string_make(death_message.data());
500 if (winning_seppuku) {
502 int w = game_term->wid;
503 int h = game_term->hgt;
504 int msg_pos_x[9] = { 5, 7, 9, 12, 14, 17, 19, 21, 23 };
505 int msg_pos_y[9] = { 3, 4, 5, 4, 5, 4, 5, 6, 4 };
509 for (i = 0; i < 40; i++) {
510 term_putstr(randint0(w / 2) * 2, randint0(h), 2, TERM_VIOLET, "υ");
513 auto str = death_message.data();
514 if (strncmp(str, "「", 2) == 0) {
518 auto *str2 = angband_strstr(str, "」");
519 if (str2 != nullptr) {
525 str2 = angband_strstr(str, " ");
526 if (str2 == nullptr) {
533 term_putstr_v(w * 3 / 4 - 2 - msg_pos_x[i] * 2, msg_pos_y[i], len, TERM_WHITE, str);
534 if (str2 == nullptr) {
545 term_putstr(w - 1, h - 1, 1, TERM_WHITE, " ");
548 screen_dump = make_screen_dump(player_ptr);
553 msg_print(death_message);
560 handle_stuff(player_ptr);
561 if (player_ptr->chp < warning) {
562 if (old_chp > warning) {
567 if (record_danger && (old_chp > warning)) {
568 if (player_ptr->effects()->hallucination()->is_hallucinated() && damage_type == DAMAGE_ATTACK) {
569 hit_from = _("何か", "something");
572 std::stringstream ss;
573 ss << _(hit_from, "was in a critical situation because of ");
574 ss << _("によってピンチに陥った。", hit_from);
576 exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, ss.str().data());
580 player_ptr->now_damaged = true;
583 msg_print(_("*** 警告:低ヒット・ポイント! ***", "*** LOW HITPOINT WARNING! ***"));
588 if (player_ptr->wild_mode && !player_ptr->leaving && (player_ptr->chp < std::max(warning, player_ptr->mhp / 5))) {
589 change_wild_mode(player_ptr, false);
596 * @brief 属性に応じた敵オーラによるプレイヤーのダメージ処理
597 * @param m_ptr オーラを持つモンスターの構造体参照ポインタ
598 * @param immune ダメージを回避できる免疫フラグ
599 * @param flags_offset オーラフラグ配列の参照オフセット
600 * @param r_flags_offset モンスターの耐性配列の参照オフセット
601 * @param aura_flag オーラフラグ配列
602 * @param dam_func ダメージ処理を行う関数の参照ポインタ
603 * @param message オーラダメージを受けた際のメッセージ
605 static void process_aura_damage(MonsterEntity *m_ptr, PlayerType *player_ptr, bool immune, MonsterAuraType aura_flag, dam_func dam_func, concptr message)
607 auto *r_ptr = &monraces_info[m_ptr->r_idx];
608 if (r_ptr->aura_flags.has_not(aura_flag) || immune) {
612 int aura_damage = damroll(1 + (r_ptr->level / 26), 1 + (r_ptr->level / 17));
614 (*dam_func)(player_ptr, aura_damage, monster_desc(player_ptr, m_ptr, MD_WRONGDOER_NAME).data(), true);
615 if (is_original_ap_and_seen(player_ptr, m_ptr)) {
616 r_ptr->r_aura_flags.set(aura_flag);
619 handle_stuff(player_ptr);
623 * @brief 敵オーラによるプレイヤーのダメージ処理
624 * @param m_ptr オーラを持つモンスターの構造体参照ポインタ
625 * @param player_ptr プレイヤーへの参照ポインタ
627 void touch_zap_player(MonsterEntity *m_ptr, PlayerType *player_ptr)
629 constexpr auto fire_mes = _("突然とても熱くなった!", "You are suddenly very hot!");
630 constexpr auto cold_mes = _("突然とても寒くなった!", "You are suddenly very cold!");
631 constexpr auto elec_mes = _("電撃をくらった!", "You get zapped!");
632 process_aura_damage(m_ptr, player_ptr, has_immune_fire(player_ptr) != 0, MonsterAuraType::FIRE, fire_dam, fire_mes);
633 process_aura_damage(m_ptr, player_ptr, has_immune_cold(player_ptr) != 0, MonsterAuraType::COLD, cold_dam, cold_mes);
634 process_aura_damage(m_ptr, player_ptr, has_immune_elec(player_ptr) != 0, MonsterAuraType::ELEC, elec_dam, elec_mes);