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-entry.h"
30 #include "mind/mind-mirror-master.h"
31 #include "monster/monster-describer.h"
32 #include "monster/monster-description-types.h"
33 #include "monster/monster-info.h"
34 #include "mutation/mutation-flag-types.h"
35 #include "object-enchant/tr-types.h"
36 #include "object-hook/hook-armor.h"
37 #include "object/item-tester-hooker.h"
38 #include "object/object-broken.h"
39 #include "player-base/player-class.h"
40 #include "player-base/player-race.h"
41 #include "player-info/class-info.h"
42 #include "player-info/race-types.h"
43 #include "player-info/samurai-data-type.h"
44 #include "player/player-personality-types.h"
45 #include "player/player-status-flags.h"
46 #include "player/player-status-resist.h"
47 #include "player/player-status.h"
48 #include "player/race-info-table.h"
49 #include "player/special-defense-types.h"
50 #include "racial/racial-android.h"
51 #include "save/save.h"
52 #include "status/base-status.h"
53 #include "status/element-resistance.h"
54 #include "system/building-type-definition.h"
55 #include "system/dungeon-info.h"
56 #include "system/floor-type-definition.h"
57 #include "system/item-entity.h"
58 #include "system/monster-entity.h"
59 #include "system/monster-race-info.h"
60 #include "system/player-type-definition.h"
61 #include "system/redrawing-flags-updater.h"
62 #include "term/screen-processor.h"
63 #include "term/term-color-types.h"
64 #include "timed-effect/timed-effects.h"
65 #include "util/bit-flags-calculator.h"
66 #include "util/string-processor.h"
67 #include "view/display-messages.h"
68 #include "world/world.h"
72 using dam_func = int (*)(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura);
75 * @brief 酸攻撃による装備のAC劣化処理 /
76 * Acid has hit the player, attempt to affect some armor.
77 * @param 酸を浴びたキャラクタへの参照ポインタ
78 * @return 装備による軽減があったならTRUEを返す
80 * 免疫があったらそもそもこの関数は実行されない (確実に錆びない).
81 * Note that the "base armor" of an object never changes.
82 * If any armor is damaged (or resists), the player takes less damage.
84 static bool acid_minus_ac(PlayerType *player_ptr)
86 constexpr static auto candidates = {
96 const auto slot = rand_choice(candidates);
97 auto *o_ptr = &player_ptr->inventory_list[slot];
99 if ((o_ptr == nullptr) || !o_ptr->is_valid() || !o_ptr->is_protector()) {
103 const auto item_name = describe_flavor(player_ptr, o_ptr, OD_OMIT_PREFIX | OD_NAME_ONLY);
104 const auto item_flags = o_ptr->get_flags();
105 if (o_ptr->ac + o_ptr->to_a <= 0) {
106 msg_format(_("%sは既にボロボロだ!", "Your %s is already fully corroded!"), item_name.data());
110 if (item_flags.has(TR_IGNORE_ACID)) {
111 msg_format(_("しかし%sには効果がなかった!", "Your %s is unaffected!"), item_name.data());
115 msg_format(_("%sが酸で腐食した!", "Your %s is corroded!"), item_name.data());
117 auto &rfu = RedrawingFlagsUpdater::get_instance();
118 rfu.set_flag(StatusRecalculatingFlag::BONUS);
119 static constexpr auto flags_swrf = {
120 SubWindowRedrawingFlag::EQUIPMENT,
121 SubWindowRedrawingFlag::PLAYER,
123 rfu.set_flags(flags_swrf);
124 calc_android_exp(player_ptr);
129 * @brief 酸属性によるプレイヤー損害処理 /
130 * Hurt the player with Acid
131 * @param player_ptr 酸を浴びたキャラクタへの参照ポインタ
133 * @param kb_str ダメージ原因記述
134 * @param monspell 原因となったモンスター特殊攻撃ID
135 * @param aura オーラよるダメージが原因ならばTRUE
137 * @details 酸オーラは存在しないが関数ポインタのために引数だけは用意している
139 int acid_dam(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura)
141 int inv = (dam < 30) ? 1 : (dam < 60) ? 2
143 bool double_resist = is_oppose_acid(player_ptr);
144 dam = dam * calc_acid_damage_rate(player_ptr) / 100;
149 if (aura || !check_multishadow(player_ptr)) {
150 if ((!(double_resist || has_resist_acid(player_ptr))) && one_in_(CHANCE_ABILITY_SCORE_DECREASE)) {
151 (void)do_dec_stat(player_ptr, A_CHR);
154 if (acid_minus_ac(player_ptr)) {
159 int get_damage = take_hit(player_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str);
160 if (!aura && !(double_resist && has_resist_acid(player_ptr))) {
161 inventory_damage(player_ptr, BreakerAcid(), inv);
168 * @brief 電撃属性によるプレイヤー損害処理 /
169 * Hurt the player with electricity
170 * @param player_ptr 電撃を浴びたキャラクタへの参照ポインタ
172 * @param kb_str ダメージ原因記述
173 * @param monspell 原因となったモンスター特殊攻撃ID
174 * @param aura オーラよるダメージが原因ならばTRUE
177 int elec_dam(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura)
179 int inv = (dam < 30) ? 1 : (dam < 60) ? 2
181 bool double_resist = is_oppose_elec(player_ptr);
183 dam = dam * calc_elec_damage_rate(player_ptr) / 100;
189 if (aura || !check_multishadow(player_ptr)) {
190 if ((!(double_resist || has_resist_elec(player_ptr))) && one_in_(CHANCE_ABILITY_SCORE_DECREASE)) {
191 (void)do_dec_stat(player_ptr, A_DEX);
195 int get_damage = take_hit(player_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str);
196 if (!aura && !(double_resist && has_resist_elec(player_ptr))) {
197 inventory_damage(player_ptr, BreakerElec(), inv);
204 * @brief 火炎属性によるプレイヤー損害処理 /
205 * Hurt the player with Fire
206 * @param player_ptr 火炎を浴びたキャラクタへの参照ポインタ
208 * @param kb_str ダメージ原因記述
209 * @param monspell 原因となったモンスター特殊攻撃ID
210 * @param aura オーラよるダメージが原因ならばTRUE
213 int fire_dam(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura)
215 int inv = (dam < 30) ? 1 : (dam < 60) ? 2
217 bool double_resist = is_oppose_fire(player_ptr);
220 if (has_immune_fire(player_ptr) || (dam <= 0)) {
224 dam = dam * calc_fire_damage_rate(player_ptr) / 100;
225 if (aura || !check_multishadow(player_ptr)) {
226 if ((!(double_resist || has_resist_fire(player_ptr))) && one_in_(CHANCE_ABILITY_SCORE_DECREASE)) {
227 (void)do_dec_stat(player_ptr, A_STR);
231 int get_damage = take_hit(player_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str);
232 if (!aura && !(double_resist && has_resist_fire(player_ptr))) {
233 inventory_damage(player_ptr, BreakerFire(), inv);
240 * @brief 冷気属性によるプレイヤー損害処理 /
241 * Hurt the player with Cold
242 * @param player_ptr 冷気を浴びたキャラクタへの参照ポインタ
244 * @param kb_str ダメージ原因記述
245 * @param monspell 原因となったモンスター特殊攻撃ID
246 * @param aura オーラよるダメージが原因ならばTRUE
249 int cold_dam(PlayerType *player_ptr, int dam, std::string_view kb_str, bool aura)
251 int inv = (dam < 30) ? 1 : (dam < 60) ? 2
253 bool double_resist = is_oppose_cold(player_ptr);
254 if (has_immune_cold(player_ptr) || (dam <= 0)) {
258 dam = dam * calc_cold_damage_rate(player_ptr) / 100;
259 if (aura || !check_multishadow(player_ptr)) {
260 if ((!(double_resist || has_resist_cold(player_ptr))) && one_in_(CHANCE_ABILITY_SCORE_DECREASE)) {
261 (void)do_dec_stat(player_ptr, A_STR);
265 int get_damage = take_hit(player_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str);
266 if (!aura && !(double_resist && has_resist_cold(player_ptr))) {
267 inventory_damage(player_ptr, BreakerCold(), inv);
274 * Decreases players hit points and sets death flag if necessary
276 * Invulnerability needs to be changed into a "shield"
278 * Hack -- this function allows the user to save (or quit)
279 * the game when he dies, since the "You die." message is shown before
280 * setting the player to "dead".
282 int take_hit(PlayerType *player_ptr, int damage_type, int damage, std::string_view hit_from)
284 int old_chp = player_ptr->chp;
285 int warning = (player_ptr->mhp * hitpoint_warn / 10);
286 if (player_ptr->is_dead) {
290 if (player_ptr->sutemi) {
293 if (PlayerClass(player_ptr).samurai_stance_is(SamuraiStanceType::IAI)) {
294 damage += (damage + 4) / 5;
297 if (damage_type != DAMAGE_USELIFE) {
298 disturb(player_ptr, true, true);
300 player_ptr->now_damaged = true;
304 if ((damage_type != DAMAGE_USELIFE) && (damage_type != DAMAGE_LOSELIFE)) {
305 if (is_invuln(player_ptr) && (damage < 9000)) {
306 if (damage_type == DAMAGE_FORCE) {
307 msg_print(_("バリアが切り裂かれた!", "The attack cuts your shield of invulnerability open!"));
308 } else if (one_in_(PENETRATE_INVULNERABILITY)) {
309 msg_print(_("無敵のバリアを破って攻撃された!", "The attack penetrates your shield of invulnerability!"));
315 if (check_multishadow(player_ptr)) {
316 if (damage_type == DAMAGE_FORCE) {
317 msg_print(_("幻影もろとも体が切り裂かれた!", "The attack hits Shadow together with you!"));
318 } else if (damage_type == DAMAGE_ATTACK) {
319 msg_print(_("攻撃は幻影に命中し、あなたには届かなかった。", "The attack hits Shadow, but you are unharmed!"));
324 if (player_ptr->wraith_form) {
325 if (damage_type == DAMAGE_FORCE) {
326 msg_print(_("半物質の体が切り裂かれた!", "The attack cuts through your ethereal body!"));
329 if ((damage == 0) && one_in_(2)) {
335 if (PlayerClass(player_ptr).samurai_stance_is(SamuraiStanceType::MUSOU)) {
337 if ((damage == 0) && one_in_(2)) {
343 player_ptr->chp -= damage;
344 if (player_ptr->chp < -9999) {
345 player_ptr->chp = -9999;
347 if (damage_type == DAMAGE_GENO && player_ptr->chp < 0) {
348 damage += player_ptr->chp;
352 auto &rfu = RedrawingFlagsUpdater::get_instance();
353 rfu.set_flag(MainWindowRedrawingFlag::HP);
354 rfu.set_flag(SubWindowRedrawingFlag::PLAYER);
356 if (damage_type != DAMAGE_GENO && player_ptr->chp == 0) {
357 chg_virtue(player_ptr, Virtue::SACRIFICE, 1);
358 chg_virtue(player_ptr, Virtue::CHANCE, 2);
361 const auto &floor = *player_ptr->current_floor_ptr;
362 auto &world = AngbandWorld::get_instance();
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 if (floor.inside_arena) {
380 auto &entries = ArenaEntryList::get_instance();
381 entries.set_defeated_entry();
382 const auto &m_name = entries.get_monrace().name;
383 msg_format(_("あなたは%sの前に敗れ去った。", "You are beaten by %s."), m_name.data());
386 exe_write_diary(floor, DiaryKind::ARENA, 0, m_name);
389 const auto q_idx = floor.get_quest_id();
390 const auto seppuku = hit_from == "Seppuku";
391 const auto winning_seppuku = world.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 const auto effects = player_ptr->effects();
405 const 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 world.total_winner = false;
420 if (winning_seppuku) {
421 world.add_retired_class(player_ptr->pclass);
422 exe_write_diary(floor, DiaryKind::DESCRIPTION, 0, _("勝利の後切腹した。", "committed seppuku after the winning."));
426 if (floor.inside_arena) {
427 place = _("アリーナ", "in the Arena");
428 } else if (!floor.is_in_underground()) {
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.dun_level));
437 const auto note = format("%sで%sに殺された。", place.data(), player_ptr->died_from.data());
439 const auto note = format("killed by %s %s.", player_ptr->died_from.data(), place.data());
441 exe_write_diary(floor, DiaryKind::DESCRIPTION, 0, note);
444 exe_write_diary(floor, DiaryKind::GAMESTART, 1, _("-------- ゲームオーバー --------", "-------- Game Over --------"));
445 exe_write_diary(floor, DiaryKind::DESCRIPTION, 1, "\n\n\n\n");
447 if (input_check_strict(player_ptr, _("画面を保存しますか?", "Dump the screen? "), UserCheck::NO_HISTORY)) {
448 do_cmd_save_screen(player_ptr);
452 player_ptr->last_message = "";
455 msg_format("あなたは%sました。", android ? "壊れ" : "死に");
457 msg_print(android ? "You are broken." : "You die.");
462 std::optional<std::string> death_message_opt;
463 if (winning_seppuku) {
464 death_message_opt = get_random_line(_("seppuku_j.txt", "seppuku.txt"), 0);
466 death_message_opt = get_random_line(_("death_j.txt", "death.txt"), 0);
469 auto &death_message = *death_message_opt;
470 constexpr auto max_last_words = 1024;
471 const auto prompt = winning_seppuku ? _("辞世の句: ", "Haiku: ") : _("断末魔の叫び: ", "Last words: ");
473 const auto input_last_words = input_string(prompt, max_last_words, death_message);
474 if (!input_last_words) {
478 if (input_check_strict(player_ptr, _("よろしいですか?", "Are you sure? "), UserCheck::NO_HISTORY)) {
479 death_message = *input_last_words;
484 if (death_message.empty()) {
486 death_message = format("あなたは%sました。", android ? "壊れ" : "死に");
488 death_message = android ? "You are broken." : "You die.";
491 player_ptr->last_message = death_message;
495 if (winning_seppuku) {
497 int w = game_term->wid;
498 int h = game_term->hgt;
499 int msg_pos_x[9] = { 5, 7, 9, 12, 14, 17, 19, 21, 23 };
500 int msg_pos_y[9] = { 3, 4, 5, 4, 5, 4, 5, 6, 4 };
504 for (i = 0; i < 40; i++) {
505 term_putstr(randint0(w / 2) * 2, randint0(h), 2, TERM_VIOLET, "υ");
508 auto str = death_message.data();
509 if (strncmp(str, "「", 2) == 0) {
513 auto *str2 = angband_strstr(str, "」");
514 if (str2 != nullptr) {
520 str2 = angband_strstr(str, " ");
521 if (str2 == nullptr) {
528 term_putstr_v(w * 3 / 4 - 2 - msg_pos_x[i] * 2, msg_pos_y[i], len, TERM_WHITE, str);
529 if (str2 == nullptr) {
540 term_putstr(w - 1, h - 1, 1, TERM_WHITE, " ");
543 screen_dump = make_screen_dump(player_ptr);
548 msg_print(death_message);
555 handle_stuff(player_ptr);
556 if (player_ptr->chp < warning) {
557 if (old_chp > warning) {
562 if (record_danger && (old_chp > warning)) {
563 if (player_ptr->effects()->hallucination().is_hallucinated() && damage_type == DAMAGE_ATTACK) {
564 hit_from = _("何か", "something");
567 std::stringstream ss;
568 ss << _(hit_from, "was in a critical situation because of ");
569 ss << _("によってピンチに陥った。", hit_from);
571 exe_write_diary(floor, DiaryKind::DESCRIPTION, 0, ss.str());
575 player_ptr->now_damaged = true;
578 msg_print(_("*** 警告:低ヒット・ポイント! ***", "*** LOW HITPOINT WARNING! ***"));
583 if (world.is_wild_mode() && !player_ptr->leaving && (player_ptr->chp < std::max(warning, player_ptr->mhp / 5))) {
584 change_wild_mode(player_ptr, false);
591 * @brief 属性に応じた敵オーラによるプレイヤーのダメージ処理
592 * @param m_ptr オーラを持つモンスターの構造体参照ポインタ
593 * @param immune ダメージを回避できる免疫フラグ
594 * @param flags_offset オーラフラグ配列の参照オフセット
595 * @param r_flags_offset モンスターの耐性配列の参照オフセット
596 * @param aura_flag オーラフラグ配列
597 * @param dam_func ダメージ処理を行う関数の参照ポインタ
598 * @param message オーラダメージを受けた際のメッセージ
600 static void process_aura_damage(MonsterEntity *m_ptr, PlayerType *player_ptr, bool immune, MonsterAuraType aura_flag, dam_func dam_func, concptr message)
602 auto *r_ptr = &m_ptr->get_monrace();
603 if (r_ptr->aura_flags.has_not(aura_flag) || immune) {
607 int aura_damage = Dice::roll(1 + (r_ptr->level / 26), 1 + (r_ptr->level / 17));
609 (*dam_func)(player_ptr, aura_damage, monster_desc(player_ptr, m_ptr, MD_WRONGDOER_NAME).data(), true);
610 if (is_original_ap_and_seen(player_ptr, m_ptr)) {
611 r_ptr->r_aura_flags.set(aura_flag);
614 handle_stuff(player_ptr);
618 * @brief 敵オーラによるプレイヤーのダメージ処理
619 * @param m_ptr オーラを持つモンスターの構造体参照ポインタ
620 * @param player_ptr プレイヤーへの参照ポインタ
622 void touch_zap_player(MonsterEntity *m_ptr, PlayerType *player_ptr)
624 constexpr auto fire_mes = _("突然とても熱くなった!", "You are suddenly very hot!");
625 constexpr auto cold_mes = _("突然とても寒くなった!", "You are suddenly very cold!");
626 constexpr auto elec_mes = _("電撃をくらった!", "You get zapped!");
627 process_aura_damage(m_ptr, player_ptr, has_immune_fire(player_ptr) != 0, MonsterAuraType::FIRE, fire_dam, fire_mes);
628 process_aura_damage(m_ptr, player_ptr, has_immune_cold(player_ptr) != 0, MonsterAuraType::COLD, cold_dam, cold_mes);
629 process_aura_damage(m_ptr, player_ptr, has_immune_elec(player_ptr) != 0, MonsterAuraType::ELEC, elec_dam, elec_mes);