7 #include "pet/pet-fall-off.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 "floor/cave.h"
13 #include "floor/geometry.h"
14 #include "grid/grid.h"
15 #include "monster-attack/monster-attack-player.h"
16 #include "monster-race/monster-race.h"
17 #include "monster/monster-describer.h"
18 #include "pet/pet-util.h"
19 #include "player-base/player-class.h"
20 #include "player/player-damage.h"
21 #include "player/player-move.h"
22 #include "player/player-skill.h"
23 #include "system/floor-type-definition.h"
24 #include "system/grid-type-definition.h"
25 #include "system/monster-race-info.h"
26 #include "system/monster-type-definition.h"
27 #include "system/player-type-definition.h"
28 #include "system/terrain-type-definition.h"
29 #include "target/target-checker.h"
30 #include "view/display-messages.h"
33 * @brief モンスターから直接攻撃を受けた時に落馬するかどうかを判定し、判定アウトならば落馬させる
34 * @param player_ptr プレイヤーへの参照ポインタ
35 * @param monap_ptr モンスターからプレイヤーへの直接攻撃構造体への参照ポインタ
37 void check_fall_off_horse(PlayerType *player_ptr, MonsterAttackPlayer *monap_ptr)
39 if ((player_ptr->riding == 0) || (monap_ptr->damage == 0)) {
43 char m_steed_name[MAX_NLEN];
44 monster_desc(player_ptr, m_steed_name, &player_ptr->current_floor_ptr->m_list[player_ptr->riding], 0);
45 if (process_fall_off_horse(player_ptr, (monap_ptr->damage > 200) ? 200 : monap_ptr->damage, false)) {
46 msg_format(_("%^sから落ちてしまった!", "You have fallen from %s."), m_steed_name);
52 * @param player_ptr プレイヤーへの参照ポインタ
53 * @param dam 落馬判定を発した際に受けたダメージ量
54 * @param force TRUEならば強制的に落馬する
55 * @param 乗馬中のモンスターのレベル
56 * @return FALSEなら落馬しないことで確定、TRUEなら処理続行
57 * @details レベルの低い乗馬からは落馬しにくい
59 static bool calc_fall_off_possibility(PlayerType *player_ptr, const int dam, const bool force, MonsterRaceInfo *r_ptr)
65 auto cur = player_ptr->skill_exp[PlayerSkillKindType::RIDING];
67 int fall_off_level = r_ptr->level;
68 if (player_ptr->riding_ryoute) {
72 PlayerSkill(player_ptr).gain_riding_skill_exp_on_fall_off_check(dam);
74 if (randint0(dam / 2 + fall_off_level * 2) >= cur / 30 + 10) {
78 if ((PlayerClass(player_ptr).is_tamer() && !player_ptr->riding_ryoute) || !one_in_(player_ptr->lev * (player_ptr->riding_ryoute ? 2 : 3) + 30)) {
87 * @param dam 落馬判定を発した際に受けたダメージ量
88 * @param force TRUEならば強制的に落馬する
89 * @return 実際に落馬したらTRUEを返す
91 bool process_fall_off_horse(PlayerType *player_ptr, int dam, bool force)
96 GAME_TEXT m_name[MAX_NLEN];
97 auto *m_ptr = &player_ptr->current_floor_ptr->m_list[player_ptr->riding];
98 auto *r_ptr = &monraces_info[m_ptr->r_idx];
100 if (!player_ptr->riding || player_ptr->wild_mode) {
104 if (dam >= 0 || force) {
105 if (!calc_fall_off_possibility(player_ptr, dam, force, r_ptr)) {
109 /* Check around the player */
110 for (DIRECTION i = 0; i < 8; i++) {
111 POSITION y = player_ptr->y + ddy_ddd[i];
112 POSITION x = player_ptr->x + ddx_ddd[i];
115 g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
121 /* Skip non-empty grids */
122 if (!g_ptr->cave_has_flag(TerrainCharacteristics::MOVE) && !g_ptr->cave_has_flag(TerrainCharacteristics::CAN_FLY)) {
123 if (!can_player_ride_pet(player_ptr, g_ptr, false)) {
128 if (g_ptr->cave_has_flag(TerrainCharacteristics::PATTERN)) {
132 /* Count "safe" grids */
135 /* Randomize choice */
136 if (randint0(sn) > 0) {
140 /* Save the safe location */
146 monster_desc(player_ptr, m_name, m_ptr, 0);
147 msg_format(_("%sから振り落とされそうになって、壁にぶつかった。", "You have nearly fallen from %s but bumped into a wall."), m_name);
148 take_hit(player_ptr, DAMAGE_NOESCAPE, r_ptr->level + 3, _("壁への衝突", "bumping into a wall"));
152 POSITION old_y = player_ptr->y;
153 POSITION old_x = player_ptr->x;
156 lite_spot(player_ptr, old_y, old_x);
157 lite_spot(player_ptr, player_ptr->y, player_ptr->x);
158 verify_panel(player_ptr);
161 player_ptr->riding = 0;
162 player_ptr->pet_extra_flags &= ~(PF_TWO_HANDS);
163 player_ptr->riding_ryoute = player_ptr->old_riding_ryoute = false;
165 player_ptr->update |= (PU_BONUS | PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE | PU_MONSTERS);
166 handle_stuff(player_ptr);
168 player_ptr->window_flags |= (PW_OVERHEAD | PW_DUNGEON);
169 player_ptr->redraw |= (PR_EXTRA);
171 /* Update health track of mount */
172 player_ptr->redraw |= (PR_UHEALTH);
174 bool fall_dam = false;
175 if (player_ptr->levitation && !force) {
176 monster_desc(player_ptr, m_name, m_ptr, 0);
177 msg_format(_("%sから落ちたが、空中でうまく体勢を立て直して着地した。", "You are thrown from %s but make a good landing."), m_name);
179 take_hit(player_ptr, DAMAGE_NOESCAPE, r_ptr->level + 3, _("落馬", "Falling from riding"));
183 if (sy && !player_ptr->is_dead) {
184 (void)move_player_effect(player_ptr, player_ptr->y, player_ptr->x, MPE_DONT_PICKUP | MPE_DONT_SWAP_MON);