8 #include "realm-song.h"
11 #include "object-flavor.h"
12 #include "object-hook.h"
13 #include "object-broken.h"
14 #include "player-move.h"
15 #include "player-damage.h"
16 #include "player-personality.h"
17 #include "player-status.h"
18 #include "player-effects.h"
19 #include "player-class.h"
20 #include "monster-spell.h"
22 #include "view-mainwindow.h"
32 * @brief アイテムが指定確率で破損するかどうかを判定する /
33 * Destroys a type of item on a given percent chance
34 * @param typ 破損判定関数ポインタ
38 * Note that missiles are no longer necessarily all destroyed
39 * Destruction taken from "melee.c" code for "stealing".
40 * New-style wands and rods handled correctly. -LM-
41 * Returns number of items destroyed.
43 int inven_damage(inven_func typ, int perc)
48 GAME_TEXT o_name[MAX_NLEN];
50 if (CHECK_MULTISHADOW(p_ptr)) return 0;
52 if (p_ptr->inside_arena) return 0;
54 /* Count the casualties */
57 /* Scan through the slots backwards */
58 for (i = 0; i < INVEN_PACK; i++)
60 o_ptr = &p_ptr->inventory_list[i];
61 if (!o_ptr->k_idx) continue;
63 /* Hack -- for now, skip artifacts */
64 if (object_is_artifact(o_ptr)) continue;
66 /* Give this item slot a shot at death */
69 /* Count the casualties */
70 for (amt = j = 0; j < o_ptr->number; ++j)
72 if (randint0(100) < perc) amt++;
75 /* Some casualities */
78 object_desc(o_name, o_ptr, OD_OMIT_PREFIX);
80 msg_format(_("%s(%c)が%s壊れてしまった!", "%sour %s (%c) %s destroyed!"),
82 o_name, index_to_label(i), ((o_ptr->number > 1) ?
83 ((amt == o_ptr->number) ? "全部" : (amt > 1 ? "何個か" : "一個")) : ""));
85 ((o_ptr->number > 1) ? ((amt == o_ptr->number) ? "All of y" :
86 (amt > 1 ? "Some of y" : "One of y")) : "Y"), o_name, index_to_label(i), ((amt > 1) ? "were" : "was"));
90 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (p_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
91 msg_print("やりやがったな!");
92 else if ((p_ptr->pseikaku == SEIKAKU_CHARGEMAN))
94 if (randint0(2) == 0) msg_print(_("ジュラル星人め!", ""));
95 else msg_print(_("弱い者いじめは止めるんだ!", ""));
99 /* Potions smash open */
100 if (object_is_potion(o_ptr))
102 (void)potion_smash_effect(0, p_ptr->y, p_ptr->x, o_ptr->k_idx);
105 /* Reduce the charges of rods/wands */
106 reduce_charges(o_ptr, amt);
108 /* Destroy "amt" items */
109 inven_item_increase(i, -amt);
110 inven_item_optimize(i);
112 /* Count the casualties */
118 /* Return the casualty count */
124 * @brief 酸攻撃による装備のAC劣化処理 /
125 * Acid has hit the player, attempt to affect some armor.
126 * @return 装備による軽減があったならTRUEを返す
128 * Note that the "base armor" of an object never changes.
129 * If any armor is damaged (or resists), the player takes less damage.
131 static bool acid_minus_ac(player_type *creature_ptr)
133 object_type *o_ptr = NULL;
134 BIT_FLAGS flgs[TR_FLAG_SIZE];
135 GAME_TEXT o_name[MAX_NLEN];
137 /* Pick a (possibly empty) creature_ptr->inventory_list slot */
140 case 1: o_ptr = &creature_ptr->inventory_list[INVEN_RARM]; break;
141 case 2: o_ptr = &creature_ptr->inventory_list[INVEN_LARM]; break;
142 case 3: o_ptr = &creature_ptr->inventory_list[INVEN_BODY]; break;
143 case 4: o_ptr = &creature_ptr->inventory_list[INVEN_OUTER]; break;
144 case 5: o_ptr = &creature_ptr->inventory_list[INVEN_HANDS]; break;
145 case 6: o_ptr = &creature_ptr->inventory_list[INVEN_HEAD]; break;
146 case 7: o_ptr = &creature_ptr->inventory_list[INVEN_FEET]; break;
149 if (!o_ptr->k_idx) return (FALSE);
150 if (!object_is_armour(o_ptr)) return (FALSE);
152 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
153 object_flags(o_ptr, flgs);
154 /* No damage left to be done */
155 if (o_ptr->ac + o_ptr->to_a <= 0)
157 msg_format(_("%sは既にボロボロだ!", "Your %s is already crumble!"), o_name);
162 if (have_flag(flgs, TR_IGNORE_ACID))
164 msg_format(_("しかし%sには効果がなかった!", "Your %s is unaffected!"), o_name);
168 msg_format(_("%sが酸で腐食した!", "Your %s is corroded!"), o_name);
170 /* Damage the item */
173 /* Calculate bonuses */
174 creature_ptr->update |= (PU_BONUS);
175 creature_ptr->window |= (PW_EQUIP | PW_PLAYER);
177 calc_android_exp(creature_ptr);
179 /* Item was damaged */
185 * @brief 酸属性によるプレイヤー損害処理 /
186 * Hurt the player with Acid
188 * @param kb_str ダメージ原因記述
189 * @param monspell 原因となったモンスター特殊攻撃ID
190 * @param aura オーラよるダメージが原因ならばTRUE
193 HIT_POINT acid_dam(HIT_POINT dam, concptr kb_str, int monspell, bool aura)
195 HIT_POINT get_damage;
196 int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
197 bool double_resist = IS_OPPOSE_ACID();
200 if (p_ptr->immune_acid || (dam <= 0))
202 learn_spell(monspell);
206 /* Vulnerability (Ouch!) */
207 if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
208 if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
210 /* Resist the damage */
211 if (p_ptr->resist_acid) dam = (dam + 2) / 3;
212 if (double_resist) dam = (dam + 2) / 3;
214 if (aura || !CHECK_MULTISHADOW(p_ptr))
216 if ((!(double_resist || p_ptr->resist_acid)) &&
217 one_in_(HURT_CHANCE))
218 (void)do_dec_stat(p_ptr, A_CHR);
220 /* If any armor gets hit, defend the player */
221 if (acid_minus_ac(p_ptr)) dam = (dam + 1) / 2;
224 get_damage = take_hit(p_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str, monspell);
226 /* Inventory damage */
227 if (!aura && !(double_resist && p_ptr->resist_acid))
228 inven_damage(set_acid_destroy, inv);
234 * @brief 電撃属性によるプレイヤー損害処理 /
235 * Hurt the player with electricity
237 * @param kb_str ダメージ原因記述
238 * @param monspell 原因となったモンスター特殊攻撃ID
239 * @param aura オーラよるダメージが原因ならばTRUE
242 HIT_POINT elec_dam(HIT_POINT dam, concptr kb_str, int monspell, bool aura)
244 HIT_POINT get_damage;
245 int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
246 bool double_resist = IS_OPPOSE_ELEC();
249 if (p_ptr->immune_elec || (dam <= 0))
251 learn_spell(monspell);
255 /* Vulnerability (Ouch!) */
256 if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
257 if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
258 if (PRACE_IS_(p_ptr, RACE_ANDROID)) dam += dam / 3;
260 /* Resist the damage */
261 if (p_ptr->resist_elec) dam = (dam + 2) / 3;
262 if (double_resist) dam = (dam + 2) / 3;
264 if (aura || !CHECK_MULTISHADOW(p_ptr))
266 if ((!(double_resist || p_ptr->resist_elec)) &&
267 one_in_(HURT_CHANCE))
268 (void)do_dec_stat(p_ptr, A_DEX);
271 get_damage = take_hit(p_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str, monspell);
273 /* Inventory damage */
274 if (!aura && !(double_resist && p_ptr->resist_elec))
275 inven_damage(set_elec_destroy, inv);
282 * @brief 火炎属性によるプレイヤー損害処理 /
283 * Hurt the player with Fire
285 * @param kb_str ダメージ原因記述
286 * @param monspell 原因となったモンスター特殊攻撃ID
287 * @param aura オーラよるダメージが原因ならばTRUE
290 HIT_POINT fire_dam(HIT_POINT dam, concptr kb_str, int monspell, bool aura)
292 HIT_POINT get_damage;
293 int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
294 bool double_resist = IS_OPPOSE_FIRE();
297 if (p_ptr->immune_fire || (dam <= 0))
299 learn_spell(monspell);
303 /* Vulnerability (Ouch!) */
304 if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
305 if (PRACE_IS_(p_ptr, RACE_ENT)) dam += dam / 3;
306 if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
308 /* Resist the damage */
309 if (p_ptr->resist_fire) dam = (dam + 2) / 3;
310 if (double_resist) dam = (dam + 2) / 3;
312 if (aura || !CHECK_MULTISHADOW(p_ptr))
314 if ((!(double_resist || p_ptr->resist_fire)) &&
315 one_in_(HURT_CHANCE))
316 (void)do_dec_stat(p_ptr, A_STR);
319 get_damage = take_hit(p_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str, monspell);
321 /* Inventory damage */
322 if (!aura && !(double_resist && p_ptr->resist_fire))
323 inven_damage(set_fire_destroy, inv);
330 * @brief 冷気属性によるプレイヤー損害処理 /
331 * Hurt the player with Cold
333 * @param kb_str ダメージ原因記述
334 * @param monspell 原因となったモンスター特殊攻撃ID
335 * @param aura オーラよるダメージが原因ならばTRUE
338 HIT_POINT cold_dam(HIT_POINT dam, concptr kb_str, int monspell, bool aura)
340 HIT_POINT get_damage;
341 int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
342 bool double_resist = IS_OPPOSE_COLD();
345 if (p_ptr->immune_cold || (dam <= 0))
347 learn_spell(monspell);
351 /* Vulnerability (Ouch!) */
352 if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
353 if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
355 /* Resist the damage */
356 if (p_ptr->resist_cold) dam = (dam + 2) / 3;
357 if (double_resist) dam = (dam + 2) / 3;
359 if (aura || !CHECK_MULTISHADOW(p_ptr))
361 if ((!(double_resist || p_ptr->resist_cold)) &&
362 one_in_(HURT_CHANCE))
363 (void)do_dec_stat(p_ptr, A_STR);
366 get_damage = take_hit(p_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str, monspell);
368 /* Inventory damage */
369 if (!aura && !(double_resist && p_ptr->resist_cold))
370 inven_damage(set_cold_destroy, inv);
377 * Decreases players hit points and sets death flag if necessary
379 * Invulnerability needs to be changed into a "shield"
381 * Hack -- this function allows the user to save (or quit)
382 * the game when he dies, since the "You die." message is shown before
383 * setting the player to "dead".
386 int take_hit(player_type *creature_ptr, int damage_type, HIT_POINT damage, concptr hit_from, int monspell)
388 int old_chp = creature_ptr->chp;
390 char death_message[1024];
393 int warning = (creature_ptr->mhp * hitpoint_warn / 10);
394 if (creature_ptr->is_dead) return 0;
396 if (creature_ptr->sutemi) damage *= 2;
397 if (creature_ptr->special_defense & KATA_IAI) damage += (damage + 4) / 5;
399 if (easy_band) damage = (damage + 1) / 2;
401 if (damage_type != DAMAGE_USELIFE)
406 creature_ptr->now_damaged = TRUE;
410 if (monspell >= 0) learn_spell(monspell);
412 /* Mega-Hack -- Apply "invulnerability" */
413 if ((damage_type != DAMAGE_USELIFE) && (damage_type != DAMAGE_LOSELIFE))
415 if (IS_INVULN() && (damage < 9000))
417 if (damage_type == DAMAGE_FORCE)
419 msg_print(_("バリアが切り裂かれた!", "The attack cuts your shield of invulnerability open!"));
421 else if (one_in_(PENETRATE_INVULNERABILITY))
423 msg_print(_("無敵のバリアを破って攻撃された!", "The attack penetrates your shield of invulnerability!"));
431 if (CHECK_MULTISHADOW(p_ptr))
433 if (damage_type == DAMAGE_FORCE)
435 msg_print(_("幻影もろとも体が切り裂かれた!", "The attack hits Shadow together with you!"));
437 else if (damage_type == DAMAGE_ATTACK)
439 msg_print(_("攻撃は幻影に命中し、あなたには届かなかった。", "The attack hits Shadow, you are unharmed!"));
444 if (creature_ptr->wraith_form)
446 if (damage_type == DAMAGE_FORCE)
448 msg_print(_("半物質の体が切り裂かれた!", "The attack cuts through your ethereal body!"));
453 if ((damage == 0) && one_in_(2)) damage = 1;
457 if (creature_ptr->special_defense & KATA_MUSOU)
460 if ((damage == 0) && one_in_(2)) damage = 1;
462 } /* not if LOSELIFE USELIFE */
464 /* Hurt the player */
465 creature_ptr->chp -= damage;
466 if (damage_type == DAMAGE_GENO && creature_ptr->chp < 0)
468 damage += creature_ptr->chp;
469 creature_ptr->chp = 0;
472 /* Display the hitpoints */
473 creature_ptr->redraw |= (PR_HP);
475 creature_ptr->window |= (PW_PLAYER);
477 if (damage_type != DAMAGE_GENO && creature_ptr->chp == 0)
479 chg_virtue(creature_ptr, V_SACRIFICE, 1);
480 chg_virtue(creature_ptr, V_CHANCE, 2);
484 if (creature_ptr->chp < 0)
486 bool android = (creature_ptr->prace == RACE_ANDROID ? TRUE : FALSE);
488 #ifdef JP /* 死んだ時に強制終了して死を回避できなくしてみた by Habu */
490 if (!save_player()) msg_print("セーブ失敗!");
495 chg_virtue(creature_ptr, V_SACRIFICE, 10);
498 creature_ptr->leaving = TRUE;
501 creature_ptr->is_dead = TRUE;
503 if (creature_ptr->inside_arena)
505 concptr m_name = r_name + r_info[arena_info[creature_ptr->arena_number].r_idx].name;
506 msg_format(_("あなたは%sの前に敗れ去った。", "You are beaten by %s."), m_name);
508 if (record_arena) do_cmd_write_nikki(NIKKI_ARENA, -1 - creature_ptr->arena_number, m_name);
512 QUEST_IDX q_idx = quest_number(current_floor_ptr->dun_level);
513 bool seppuku = streq(hit_from, "Seppuku");
514 bool winning_seppuku = creature_ptr->total_winner && seppuku;
516 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_GAMEOVER);
519 /* Make screen dump */
520 screen_dump = make_screen_dump();
523 /* Note cause of death */
526 strcpy(creature_ptr->died_from, hit_from);
528 if (!winning_seppuku) strcpy(creature_ptr->died_from, "切腹");
535 sprintf(dummy, "%s%s%s", !creature_ptr->paralyzed ? "" : creature_ptr->free_act ? "彫像状態で" : "麻痺状態で", creature_ptr->image ? "幻覚に歪んだ" : "", hit_from);
537 sprintf(dummy, "%s%s", hit_from, !creature_ptr->paralyzed ? "" : " while helpless");
539 my_strcpy(creature_ptr->died_from, dummy, sizeof creature_ptr->died_from);
542 /* No longer a winner */
543 creature_ptr->total_winner = FALSE;
547 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, _("勝利の後切腹した。", "did Seppuku after the winning."));
553 if (creature_ptr->inside_arena)
554 strcpy(buf, _("アリーナ", "in the Arena"));
555 else if (!current_floor_ptr->dun_level)
556 strcpy(buf, _("地上", "on the surface"));
557 else if (q_idx && (is_fixed_quest_idx(q_idx) &&
558 !((q_idx == QUEST_OBERON) || (q_idx == QUEST_SERPENT))))
559 strcpy(buf, _("クエスト", "in a quest"));
561 sprintf(buf, _("%d階", "level %d"), (int)current_floor_ptr->dun_level);
563 sprintf(tmp, _("%sで%sに殺された。", "killed by %s %s."), buf, creature_ptr->died_from);
564 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, tmp);
567 do_cmd_write_nikki(NIKKI_GAMESTART, 1, _("-------- ゲームオーバー --------", "-------- Game Over --------"));
568 do_cmd_write_nikki(NIKKI_BUNSHOU, 1, "\n\n\n\n");
572 if (get_check_strict(_("画面を保存しますか?", "Dump the screen? "), CHECK_NO_HISTORY))
574 do_cmd_save_screen();
579 /* Initialize "last message" buffer */
580 if (creature_ptr->last_message) string_free(creature_ptr->last_message);
581 creature_ptr->last_message = NULL;
583 /* Hack -- Note death */
587 msg_format("あなたは%sました。", android ? "壊れ" : "死に");
589 msg_print(android ? "You are broken." : "You die.");
598 get_rnd_line(_("seppuku_j.txt", "seppuku.txt"), 0, death_message);
602 get_rnd_line(_("death_j.txt", "death.txt"), 0, death_message);
608 while (!get_string(winning_seppuku ? "辞世の句: " : "断末魔の叫び: ", death_message, 1024));
610 while (!get_string("Last word: ", death_message, 1024));
612 } while (winning_seppuku && !get_check_strict(_("よろしいですか?", "Are you sure? "), CHECK_NO_HISTORY));
614 if (death_message[0] == '\0')
617 strcpy(death_message, format("あなたは%sました。", android ? "壊れ" : "死に"));
619 strcpy(death_message, android ? "You are broken." : "You die.");
622 else creature_ptr->last_message = string_make(death_message);
630 int msg_pos_x[9] = { 5, 7, 9, 12, 14, 17, 19, 21, 23 };
631 int msg_pos_y[9] = { 3, 4, 5, 4, 5, 4, 5, 6, 4 };
638 for (i = 0; i < 40; i++)
639 Term_putstr(randint0(w / 2) * 2, randint0(h), 2, TERM_VIOLET, "υ");
642 if (strncmp(str, "「", 2) == 0) str += 2;
644 str2 = my_strstr(str, "」");
645 if (str2 != NULL) *str2 = '\0';
650 str2 = my_strstr(str, " ");
651 if (str2 == NULL) len = strlen(str);
652 else len = str2 - str;
656 Term_putstr_v(w * 3 / 4 - 2 - msg_pos_x[i] * 2, msg_pos_y[i], len,
658 if (str2 == NULL) break;
662 if (*str == 0) break;
666 Term_putstr(w - 1, h - 1, 1, TERM_WHITE, " ");
670 /* Make screen dump */
671 screen_dump = make_screen_dump();
674 /* Wait a key press */
679 msg_print(death_message);
689 /* Hitpoint warning */
690 if (creature_ptr->chp < warning)
692 /* Hack -- bell on first notice */
693 if (old_chp > warning) bell();
697 if (record_danger && (old_chp > warning))
699 if (creature_ptr->image && damage_type == DAMAGE_ATTACK)
700 hit_from = _("何か", "something");
702 sprintf(tmp, _("%sによってピンチに陥った。", "A critical situation because of %s."), hit_from);
703 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, tmp);
708 /* stop auto_more even if DAMAGE_USELIFE */
709 creature_ptr->now_damaged = TRUE;
712 msg_print(_("*** 警告:低ヒット・ポイント! ***", "*** LOW HITPOINT WARNING! ***"));
716 if (creature_ptr->wild_mode && !creature_ptr->leaving && (creature_ptr->chp < MAX(warning, creature_ptr->mhp / 5)))
718 change_wild_mode(FALSE);