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/player-update-types.h"
10 #include "core/stuff-handler.h"
11 #include "core/window-redrawer.h"
12 #include "dungeon/quest.h"
13 #include "flavor/flavor-describer.h"
14 #include "flavor/object-flavor-types.h"
15 #include "floor/wild.h"
16 #include "game-option/birth-options.h"
17 #include "game-option/cheat-options.h"
18 #include "game-option/game-play-options.h"
19 #include "game-option/input-options.h"
20 #include "game-option/play-record-options.h"
21 #include "game-option/special-options.h"
22 #include "inventory/inventory-damage.h"
23 #include "inventory/inventory-slot-types.h"
24 #include "io/files-util.h"
25 #include "io/input-key-acceptor.h"
26 #include "io/report.h"
27 #include "io/write-diary.h"
28 #include "main/music-definitions-table.h"
29 #include "main/sound-definitions-table.h"
30 #include "main/sound-of-music.h"
31 #include "market/arena-info-table.h"
32 #include "mind/mind-mirror-master.h"
33 #include "monster-race/monster-race.h"
34 #include "monster-race/race-flags2.h"
35 #include "monster-race/race-flags3.h"
36 #include "monster/monster-describer.h"
37 #include "monster/monster-description-types.h"
38 #include "monster/monster-info.h"
39 #include "mutation/mutation-flag-types.h"
40 #include "object-enchant/tr-types.h"
41 #include "object-hook/hook-armor.h"
42 #include "object/item-tester-hooker.h"
43 #include "object/object-broken.h"
44 #include "object/object-flags.h"
45 #include "player-base/player-class.h"
46 #include "player-base/player-race.h"
47 #include "player-info/class-info.h"
48 #include "player-info/race-types.h"
49 #include "player-info/samurai-data-type.h"
50 #include "player/player-personality-types.h"
51 #include "player/player-status-flags.h"
52 #include "player/player-status-resist.h"
53 #include "player/player-status.h"
54 #include "player/race-info-table.h"
55 #include "player/special-defense-types.h"
56 #include "racial/racial-android.h"
57 #include "save/save.h"
58 #include "status/base-status.h"
59 #include "status/element-resistance.h"
60 #include "system/building-type-definition.h"
61 #include "system/dungeon-info.h"
62 #include "system/floor-type-definition.h"
63 #include "system/item-entity.h"
64 #include "system/monster-entity.h"
65 #include "system/monster-race-info.h"
66 #include "system/player-type-definition.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"
77 using dam_func = int (*)(PlayerType *player_ptr, int dam, concptr kb_str, bool aura);
80 * @brief 酸攻撃による装備のAC劣化処理 /
81 * Acid has hit the player, attempt to affect some armor.
82 * @param 酸を浴びたキャラクタへの参照ポインタ
83 * @return 装備による軽減があったならTRUEを返す
85 * 免疫があったらそもそもこの関数は実行されない (確実に錆びない).
86 * Note that the "base armor" of an object never changes.
87 * If any armor is damaged (or resists), the player takes less damage.
89 static bool acid_minus_ac(PlayerType *player_ptr)
91 ItemEntity *o_ptr = nullptr;
92 switch (randint1(7)) {
94 o_ptr = &player_ptr->inventory_list[INVEN_MAIN_HAND];
97 o_ptr = &player_ptr->inventory_list[INVEN_SUB_HAND];
100 o_ptr = &player_ptr->inventory_list[INVEN_BODY];
103 o_ptr = &player_ptr->inventory_list[INVEN_OUTER];
106 o_ptr = &player_ptr->inventory_list[INVEN_ARMS];
109 o_ptr = &player_ptr->inventory_list[INVEN_HEAD];
112 o_ptr = &player_ptr->inventory_list[INVEN_FEET];
116 if ((o_ptr == nullptr) || (o_ptr->bi_id == 0) || !o_ptr->is_protector()) {
120 GAME_TEXT o_name[MAX_NLEN];
121 describe_flavor(player_ptr, o_name, o_ptr, OD_OMIT_PREFIX | OD_NAME_ONLY);
122 auto flgs = object_flags(o_ptr);
123 if (o_ptr->ac + o_ptr->to_a <= 0) {
124 msg_format(_("%sは既にボロボロだ!", "Your %s is already fully corroded!"), o_name);
128 if (flgs.has(TR_IGNORE_ACID)) {
129 msg_format(_("しかし%sには効果がなかった!", "Your %s is unaffected!"), o_name);
133 msg_format(_("%sが酸で腐食した!", "Your %s is corroded!"), o_name);
135 player_ptr->update |= PU_BONUS;
136 player_ptr->window_flags |= PW_EQUIP | PW_PLAYER;
137 calc_android_exp(player_ptr);
142 * @brief 酸属性によるプレイヤー損害処理 /
143 * Hurt the player with Acid
144 * @param player_ptr 酸を浴びたキャラクタへの参照ポインタ
146 * @param kb_str ダメージ原因記述
147 * @param monspell 原因となったモンスター特殊攻撃ID
148 * @param aura オーラよるダメージが原因ならばTRUE
150 * @details 酸オーラは存在しないが関数ポインタのために引数だけは用意している
152 int acid_dam(PlayerType *player_ptr, int dam, concptr kb_str, bool aura)
154 int inv = (dam < 30) ? 1 : (dam < 60) ? 2
156 bool double_resist = is_oppose_acid(player_ptr);
157 dam = dam * calc_acid_damage_rate(player_ptr) / 100;
162 if (aura || !check_multishadow(player_ptr)) {
163 if ((!(double_resist || has_resist_acid(player_ptr))) && one_in_(CHANCE_ABILITY_SCORE_DECREASE)) {
164 (void)do_dec_stat(player_ptr, A_CHR);
167 if (acid_minus_ac(player_ptr)) {
172 int get_damage = take_hit(player_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str);
173 if (!aura && !(double_resist && has_resist_acid(player_ptr))) {
174 inventory_damage(player_ptr, BreakerAcid(), inv);
181 * @brief 電撃属性によるプレイヤー損害処理 /
182 * Hurt the player with electricity
183 * @param player_ptr 電撃を浴びたキャラクタへの参照ポインタ
185 * @param kb_str ダメージ原因記述
186 * @param monspell 原因となったモンスター特殊攻撃ID
187 * @param aura オーラよるダメージが原因ならばTRUE
190 int elec_dam(PlayerType *player_ptr, int dam, concptr kb_str, bool aura)
192 int inv = (dam < 30) ? 1 : (dam < 60) ? 2
194 bool double_resist = is_oppose_elec(player_ptr);
196 dam = dam * calc_elec_damage_rate(player_ptr) / 100;
202 if (aura || !check_multishadow(player_ptr)) {
203 if ((!(double_resist || has_resist_elec(player_ptr))) && one_in_(CHANCE_ABILITY_SCORE_DECREASE)) {
204 (void)do_dec_stat(player_ptr, A_DEX);
208 int get_damage = take_hit(player_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str);
209 if (!aura && !(double_resist && has_resist_elec(player_ptr))) {
210 inventory_damage(player_ptr, BreakerElec(), inv);
217 * @brief 火炎属性によるプレイヤー損害処理 /
218 * Hurt the player with Fire
219 * @param player_ptr 火炎を浴びたキャラクタへの参照ポインタ
221 * @param kb_str ダメージ原因記述
222 * @param monspell 原因となったモンスター特殊攻撃ID
223 * @param aura オーラよるダメージが原因ならばTRUE
226 int fire_dam(PlayerType *player_ptr, int dam, concptr kb_str, bool aura)
228 int inv = (dam < 30) ? 1 : (dam < 60) ? 2
230 bool double_resist = is_oppose_fire(player_ptr);
233 if (has_immune_fire(player_ptr) || (dam <= 0)) {
237 dam = dam * calc_fire_damage_rate(player_ptr) / 100;
238 if (aura || !check_multishadow(player_ptr)) {
239 if ((!(double_resist || has_resist_fire(player_ptr))) && one_in_(CHANCE_ABILITY_SCORE_DECREASE)) {
240 (void)do_dec_stat(player_ptr, A_STR);
244 int get_damage = take_hit(player_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str);
245 if (!aura && !(double_resist && has_resist_fire(player_ptr))) {
246 inventory_damage(player_ptr, BreakerFire(), inv);
253 * @brief 冷気属性によるプレイヤー損害処理 /
254 * Hurt the player with Cold
255 * @param player_ptr 冷気を浴びたキャラクタへの参照ポインタ
257 * @param kb_str ダメージ原因記述
258 * @param monspell 原因となったモンスター特殊攻撃ID
259 * @param aura オーラよるダメージが原因ならばTRUE
262 int cold_dam(PlayerType *player_ptr, int dam, concptr kb_str, bool aura)
264 int inv = (dam < 30) ? 1 : (dam < 60) ? 2
266 bool double_resist = is_oppose_cold(player_ptr);
267 if (has_immune_cold(player_ptr) || (dam <= 0)) {
271 dam = dam * calc_cold_damage_rate(player_ptr) / 100;
272 if (aura || !check_multishadow(player_ptr)) {
273 if ((!(double_resist || has_resist_cold(player_ptr))) && one_in_(CHANCE_ABILITY_SCORE_DECREASE)) {
274 (void)do_dec_stat(player_ptr, A_STR);
278 int get_damage = take_hit(player_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str);
279 if (!aura && !(double_resist && has_resist_cold(player_ptr))) {
280 inventory_damage(player_ptr, BreakerCold(), inv);
287 * Decreases players hit points and sets death flag if necessary
289 * Invulnerability needs to be changed into a "shield"
291 * Hack -- this function allows the user to save (or quit)
292 * the game when he dies, since the "You die." message is shown before
293 * setting the player to "dead".
295 int take_hit(PlayerType *player_ptr, int damage_type, int damage, concptr hit_from)
297 int old_chp = player_ptr->chp;
299 char death_message[1024];
301 int warning = (player_ptr->mhp * hitpoint_warn / 10);
302 if (player_ptr->is_dead) {
306 if (player_ptr->sutemi) {
309 if (PlayerClass(player_ptr).samurai_stance_is(SamuraiStanceType::IAI)) {
310 damage += (damage + 4) / 5;
313 if (damage_type != DAMAGE_USELIFE) {
314 disturb(player_ptr, true, true);
316 player_ptr->now_damaged = true;
320 if ((damage_type != DAMAGE_USELIFE) && (damage_type != DAMAGE_LOSELIFE)) {
321 if (is_invuln(player_ptr) && (damage < 9000)) {
322 if (damage_type == DAMAGE_FORCE) {
323 msg_print(_("バリアが切り裂かれた!", "The attack cuts your shield of invulnerability open!"));
324 } else if (one_in_(PENETRATE_INVULNERABILITY)) {
325 msg_print(_("無敵のバリアを破って攻撃された!", "The attack penetrates your shield of invulnerability!"));
331 if (check_multishadow(player_ptr)) {
332 if (damage_type == DAMAGE_FORCE) {
333 msg_print(_("幻影もろとも体が切り裂かれた!", "The attack hits Shadow together with you!"));
334 } else if (damage_type == DAMAGE_ATTACK) {
335 msg_print(_("攻撃は幻影に命中し、あなたには届かなかった。", "The attack hits Shadow, but you are unharmed!"));
340 if (player_ptr->wraith_form) {
341 if (damage_type == DAMAGE_FORCE) {
342 msg_print(_("半物質の体が切り裂かれた!", "The attack cuts through your ethereal body!"));
345 if ((damage == 0) && one_in_(2)) {
351 if (PlayerClass(player_ptr).samurai_stance_is(SamuraiStanceType::MUSOU)) {
353 if ((damage == 0) && one_in_(2)) {
359 player_ptr->chp -= damage;
360 if (player_ptr->chp < -9999) {
361 player_ptr->chp = -9999;
363 if (damage_type == DAMAGE_GENO && player_ptr->chp < 0) {
364 damage += player_ptr->chp;
368 player_ptr->redraw |= PR_HP;
369 player_ptr->window_flags |= PW_PLAYER;
371 if (damage_type != DAMAGE_GENO && player_ptr->chp == 0) {
372 chg_virtue(player_ptr, V_SACRIFICE, 1);
373 chg_virtue(player_ptr, V_CHANCE, 2);
376 if (player_ptr->chp < 0 && !cheat_immortal) {
377 bool android = PlayerRace(player_ptr).equals(PlayerRaceType::ANDROID);
379 /* 死んだ時に強制終了して死を回避できなくしてみた by Habu */
380 if (!cheat_save && !save_player(player_ptr, SaveType::CLOSE_GAME)) {
381 msg_print(_("セーブ失敗!", "death save failed!"));
385 chg_virtue(player_ptr, V_SACRIFICE, 10);
386 handle_stuff(player_ptr);
387 player_ptr->leaving = true;
388 if (!cheat_immortal) {
389 player_ptr->is_dead = true;
392 const auto &floor_ref = *player_ptr->current_floor_ptr;
393 if (floor_ref.inside_arena) {
394 concptr m_name = monraces_info[arena_info[player_ptr->arena_number].r_idx].name.data();
395 msg_format(_("あなたは%sの前に敗れ去った。", "You are beaten by %s."), m_name);
398 exe_write_diary(player_ptr, DIARY_ARENA, -1 - player_ptr->arena_number, m_name);
401 auto q_idx = quest_number(player_ptr, floor_ref.dun_level);
402 bool seppuku = streq(hit_from, "Seppuku");
403 bool winning_seppuku = w_ptr->total_winner && seppuku;
405 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_GAMEOVER);
408 screen_dump = make_screen_dump(player_ptr);
411 player_ptr->died_from = hit_from;
412 if (!winning_seppuku) {
413 player_ptr->died_from = _("切腹", "Seppuku");
416 auto effects = player_ptr->effects();
417 auto is_hallucinated = effects->hallucination()->is_hallucinated();
418 auto paralysis_state = "";
419 if (effects->paralysis()->is_paralyzed()) {
420 paralysis_state = player_ptr->free_act ? _("彫像状態で", " while being the statue") : _("麻痺状態で", " while paralyzed");
423 auto hallucintion_state = is_hallucinated ? _("幻覚に歪んだ", "hallucinatingly distorted ") : "";
425 player_ptr->died_from = format("%s%s%s", paralysis_state, hallucintion_state, hit_from);
427 player_ptr->died_from = format("%s%s%s", hallucintion_state, hit_from, paralysis_state);
431 w_ptr->total_winner = false;
432 if (winning_seppuku) {
433 add_retired_class(player_ptr->pclass);
434 exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, _("勝利の後切腹した。", "committed seppuku after the winning."));
438 if (floor_ref.inside_arena) {
439 place = _("アリーナ", "in the Arena");
440 } else if (!floor_ref.is_in_dungeon()) {
441 place = _("地上", "on the surface");
442 } else if (inside_quest(q_idx) && (quest_type::is_fixed(q_idx) && !((q_idx == QuestId::OBERON) || (q_idx == QuestId::SERPENT)))) {
443 place = _("クエスト", "in a quest");
445 place = format(_("%d階", "on level %d"), static_cast<int>(floor_ref.dun_level));
449 std::string note = format("%sで%sに殺された。", place.data(), player_ptr->died_from.data());
451 std::string note = format("killed by %s %s.", player_ptr->died_from.data(), place.data());
453 exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, note.data());
456 exe_write_diary(player_ptr, DIARY_GAMESTART, 1, _("-------- ゲームオーバー --------", "-------- Game Over --------"));
457 exe_write_diary(player_ptr, DIARY_DESCRIPTION, 1, "\n\n\n\n");
459 if (get_check_strict(player_ptr, _("画面を保存しますか?", "Dump the screen? "), CHECK_NO_HISTORY)) {
460 do_cmd_save_screen(player_ptr);
464 if (player_ptr->last_message) {
465 string_free(player_ptr->last_message);
468 player_ptr->last_message = nullptr;
471 msg_format("あなたは%sました。", android ? "壊れ" : "死に");
473 msg_print(android ? "You are broken." : "You die.");
478 if (winning_seppuku) {
479 get_rnd_line(_("seppuku_j.txt", "seppuku.txt"), 0, death_message);
481 get_rnd_line(_("death_j.txt", "death.txt"), 0, death_message);
486 while (!get_string(winning_seppuku ? "辞世の句: " : "断末魔の叫び: ", death_message, sizeof(death_message))) {
490 while (!get_string("Last words: ", death_message, 1024)) {
494 } while (winning_seppuku && !get_check_strict(player_ptr, _("よろしいですか?", "Are you sure? "), CHECK_NO_HISTORY));
496 if (death_message[0] == '\0') {
498 strcpy(death_message, format("あなたは%sました。", android ? "壊れ" : "死に"));
500 strcpy(death_message, android ? "You are broken." : "You die.");
503 player_ptr->last_message = string_make(death_message);
507 if (winning_seppuku) {
509 int w = game_term->wid;
510 int h = game_term->hgt;
511 int msg_pos_x[9] = { 5, 7, 9, 12, 14, 17, 19, 21, 23 };
512 int msg_pos_y[9] = { 3, 4, 5, 4, 5, 4, 5, 6, 4 };
519 for (i = 0; i < 40; i++) {
520 term_putstr(randint0(w / 2) * 2, randint0(h), 2, TERM_VIOLET, "υ");
524 if (strncmp(str, "「", 2) == 0) {
528 str2 = angband_strstr(str, "」");
529 if (str2 != nullptr) {
535 str2 = angband_strstr(str, " ");
536 if (str2 == nullptr) {
543 term_putstr_v(w * 3 / 4 - 2 - msg_pos_x[i] * 2, msg_pos_y[i], len, TERM_WHITE, str);
544 if (str2 == nullptr) {
555 term_putstr(w - 1, h - 1, 1, TERM_WHITE, " ");
558 screen_dump = make_screen_dump(player_ptr);
563 msg_print(death_message);
570 handle_stuff(player_ptr);
571 if (player_ptr->chp < warning) {
572 if (old_chp > warning) {
577 if (record_danger && (old_chp > warning)) {
578 if (player_ptr->effects()->hallucination()->is_hallucinated() && damage_type == DAMAGE_ATTACK) {
579 hit_from = _("何か", "something");
582 exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, std::string(_(hit_from, "was in a critical situation because of ")).append(_("によってピンチに陥った。", hit_from)).append(_("", ".")).data());
586 player_ptr->now_damaged = true;
589 msg_print(_("*** 警告:低ヒット・ポイント! ***", "*** LOW HITPOINT WARNING! ***"));
594 if (player_ptr->wild_mode && !player_ptr->leaving && (player_ptr->chp < std::max(warning, player_ptr->mhp / 5))) {
595 change_wild_mode(player_ptr, false);
602 * @brief 属性に応じた敵オーラによるプレイヤーのダメージ処理
603 * @param m_ptr オーラを持つモンスターの構造体参照ポインタ
604 * @param immune ダメージを回避できる免疫フラグ
605 * @param flags_offset オーラフラグ配列の参照オフセット
606 * @param r_flags_offset モンスターの耐性配列の参照オフセット
607 * @param aura_flag オーラフラグ配列
608 * @param dam_func ダメージ処理を行う関数の参照ポインタ
609 * @param message オーラダメージを受けた際のメッセージ
611 static void process_aura_damage(MonsterEntity *m_ptr, PlayerType *player_ptr, bool immune, MonsterAuraType aura_flag, dam_func dam_func, concptr message)
613 auto *r_ptr = &monraces_info[m_ptr->r_idx];
614 if (r_ptr->aura_flags.has_not(aura_flag) || immune) {
618 GAME_TEXT mon_name[MAX_NLEN];
619 int aura_damage = damroll(1 + (r_ptr->level / 26), 1 + (r_ptr->level / 17));
620 monster_desc(player_ptr, mon_name, m_ptr, MD_WRONGDOER_NAME);
622 (*dam_func)(player_ptr, aura_damage, mon_name, true);
623 if (is_original_ap_and_seen(player_ptr, m_ptr)) {
624 r_ptr->r_aura_flags.set(aura_flag);
627 handle_stuff(player_ptr);
631 * @brief 敵オーラによるプレイヤーのダメージ処理
632 * @param m_ptr オーラを持つモンスターの構造体参照ポインタ
633 * @param player_ptr プレイヤーへの参照ポインタ
635 void touch_zap_player(MonsterEntity *m_ptr, PlayerType *player_ptr)
637 process_aura_damage(m_ptr, player_ptr, has_immune_fire(player_ptr) != 0, MonsterAuraType::FIRE, fire_dam, _("突然とても熱くなった!", "You are suddenly very hot!"));
638 process_aura_damage(m_ptr, player_ptr, has_immune_cold(player_ptr) != 0, MonsterAuraType::COLD, cold_dam, _("突然とても寒くなった!", "You are suddenly very cold!"));
639 process_aura_damage(m_ptr, player_ptr, has_immune_elec(player_ptr) != 0, MonsterAuraType::ELEC, elec_dam, _("電撃をくらった!", "You get zapped!"));