From b1cd34b06beceec44e506cfd9d83ed64fe12fea0 Mon Sep 17 00:00:00 2001 From: Habu Date: Fri, 15 Oct 2021 23:58:30 +0900 Subject: [PATCH] =?utf8?q?[Refactor]=20=E4=B9=97=E9=A6=AC=E3=82=B9?= =?utf8?q?=E3=82=AD=E3=83=AB=E3=81=AE=E4=B8=8A=E6=98=87=E5=87=A6=E7=90=86?= =?utf8?q?=E3=82=92=20PlayerSkill=20=E3=82=AF=E3=83=A9=E3=82=B9=E3=81=AB?= =?utf8?q?=E7=A7=BB=E8=A8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 乗馬スキルの上昇処理を PlayerSkill クラスに移設する。 乗馬スキルには3種の上昇処理があるので、それぞれメンバ関数を作成する。 - gain_riding_skill_exp_on_melee_attack 乗馬中に近接攻撃した時のスキル上昇処理 - gain_riding_skill_exp_on_range_attack 乗馬中に遠隔攻撃した時のスキル上昇処理 - gain_riding_skill_exp_on_fall_off_check 被ダメージによる落馬判定が発生した時のスキル上昇処理 また、乗馬スキル値から熟練度レベルを取得する関数 riding_exp_level を PlayerSkill クラスの静的メンバ関数にする。 --- src/cmd-action/cmd-attack.cpp | 22 +------- src/combat/shoot.cpp | 8 +-- src/knowledge/knowledge-experiences.cpp | 2 +- src/pet/pet-fall-off.cpp | 12 +---- src/player/player-skill.cpp | 89 +++++++++++++++++++++++++++++++++ src/player/player-skill.h | 12 ++--- src/player/player-status.cpp | 19 ------- src/player/player-status.h | 1 - 8 files changed, 98 insertions(+), 67 deletions(-) diff --git a/src/cmd-action/cmd-attack.cpp b/src/cmd-action/cmd-attack.cpp index b7f1ce625..27fd36c0c 100644 --- a/src/cmd-action/cmd-attack.cpp +++ b/src/cmd-action/cmd-attack.cpp @@ -257,27 +257,7 @@ bool do_cmd_attack(player_type *player_ptr, POSITION y, POSITION x, combat_optio } if (player_ptr->riding) { - int cur = player_ptr->skill_exp[SKILL_RIDING]; - int max = s_info[enum2i(player_ptr->pclass)].s_max[SKILL_RIDING]; - - if (cur < max) { - DEPTH ridinglevel = r_info[player_ptr->current_floor_ptr->m_list[player_ptr->riding].r_idx].level; - DEPTH targetlevel = r_ptr->level; - int inc = 0; - - if ((cur / 200 - 5) < targetlevel) - inc += 1; - - if ((cur / 100) < ridinglevel) { - if ((cur / 100 + 15) < ridinglevel) - inc += 1 + (ridinglevel - (cur / 100 + 15)); - else - inc += 1; - } - - player_ptr->skill_exp[SKILL_RIDING] = static_cast(std::min(max, cur + inc)); - player_ptr->update |= (PU_BONUS); - } + PlayerSkill(player_ptr).gain_riding_skill_exp_on_melee_attack(r_ptr); } player_ptr->riding_t_m_idx = g_ptr->m_idx; diff --git a/src/combat/shoot.cpp b/src/combat/shoot.cpp index 1becee6ca..eedd564ad 100644 --- a/src/combat/shoot.cpp +++ b/src/combat/shoot.cpp @@ -641,13 +641,7 @@ void exe_fire(player_type *player_ptr, INVENTORY_IDX item, object_type *j_ptr, S } if (player_ptr->riding) { - if ((player_ptr->skill_exp[SKILL_RIDING] < s_info[enum2i(player_ptr->pclass)].s_max[SKILL_RIDING]) - && ((player_ptr->skill_exp[SKILL_RIDING] - (RIDING_EXP_BEGINNER * 2)) / 200 - < r_info[player_ptr->current_floor_ptr->m_list[player_ptr->riding].r_idx].level) - && one_in_(2)) { - player_ptr->skill_exp[SKILL_RIDING] += 1; - set_bits(player_ptr->update, PU_BONUS); - } + PlayerSkill(player_ptr).gain_riding_skill_exp_on_range_attack(); } /* Did we hit it (penalize range) */ diff --git a/src/knowledge/knowledge-experiences.cpp b/src/knowledge/knowledge-experiences.cpp index 898084888..f78f58cb3 100644 --- a/src/knowledge/knowledge-experiences.cpp +++ b/src/knowledge/knowledge-experiences.cpp @@ -168,7 +168,7 @@ void do_cmd_knowledge_skill_exp(player_type *player_ptr) fprintf(fff, "!"); else fprintf(fff, " "); - fprintf(fff, "%s", exp_level_str[(i == SKILL_RIDING) ? riding_exp_level(skill_exp) : PlayerSkill::weapon_exp_level(skill_exp)]); + fprintf(fff, "%s", exp_level_str[(i == SKILL_RIDING) ? PlayerSkill::riding_exp_level(skill_exp) : PlayerSkill::weapon_exp_level(skill_exp)]); if (cheat_xtra) fprintf(fff, " %d", skill_exp); fprintf(fff, "\n"); diff --git a/src/pet/pet-fall-off.cpp b/src/pet/pet-fall-off.cpp index a4a0357d2..5350ca3b2 100644 --- a/src/pet/pet-fall-off.cpp +++ b/src/pet/pet-fall-off.cpp @@ -59,22 +59,12 @@ static bool calc_fall_off_possibility(player_type *player_ptr, const HIT_POINT d return true; auto cur = player_ptr->skill_exp[SKILL_RIDING]; - auto max = s_info[enum2i(player_ptr->pclass)].s_max[SKILL_RIDING]; - auto ridinglevel = r_ptr->level; int fall_off_level = r_ptr->level; if (player_ptr->riding_ryoute) fall_off_level += 20; - if ((cur < max) && (max > 1000) && (dam / 2 + ridinglevel) > (cur / 30 + 10)) { - short inc = 0; - if (ridinglevel > (cur / 100 + 15)) - inc += 1 + (ridinglevel - cur / 100 - 15); - else - inc += 1; - - player_ptr->skill_exp[SKILL_RIDING] = std::min(max, cur + inc); - } + PlayerSkill(player_ptr).gain_riding_skill_exp_on_fall_off_check(dam); if (randint0(dam / 2 + fall_off_level * 2) >= cur / 30 + 10) return true; diff --git a/src/player/player-skill.cpp b/src/player/player-skill.cpp index 7e4ddcade..1d000c7d7 100644 --- a/src/player/player-skill.cpp +++ b/src/player/player-skill.cpp @@ -1,5 +1,9 @@ #include "player/player-skill.h" #include "core/player-update-types.h" +#include "monster-race/monster-race.h" +#include "system/floor-type-definition.h" +#include "system/monster-race-definition.h" +#include "system/monster-type-definition.h" #include "system/object-type-definition.h" #include "system/player-type-definition.h" #include "util/bit-flags-calculator.h" @@ -11,6 +15,13 @@ constexpr SUB_EXP WEAPON_EXP_SKILLED = 6000; constexpr SUB_EXP WEAPON_EXP_EXPERT = 7000; constexpr SUB_EXP WEAPON_EXP_MASTER = 8000; +/* Proficiency of riding */ +constexpr SUB_EXP RIDING_EXP_UNSKILLED = 0; +constexpr SUB_EXP RIDING_EXP_BEGINNER = 500; +constexpr SUB_EXP RIDING_EXP_SKILLED = 2000; +constexpr SUB_EXP RIDING_EXP_EXPERT = 5000; +constexpr SUB_EXP RIDING_EXP_MASTER = 8000; + /* * The skill table */ @@ -73,6 +84,25 @@ bool PlayerSkill::valid_weapon_exp(int weapon_exp) return (WEAPON_EXP_UNSKILLED <= weapon_exp) && (weapon_exp <= WEAPON_EXP_MASTER); } +/*! + * @brief 騎乗スキルの抽象的ランクを返す。 / Return proficiency level of riding + * @param riding_exp 経験値 + * @return ランク値 + */ +int PlayerSkill::riding_exp_level(int riding_exp) +{ + if (riding_exp < RIDING_EXP_BEGINNER) + return EXP_LEVEL_UNSKILLED; + else if (riding_exp < RIDING_EXP_SKILLED) + return EXP_LEVEL_BEGINNER; + else if (riding_exp < RIDING_EXP_EXPERT) + return EXP_LEVEL_SKILLED; + else if (riding_exp < RIDING_EXP_MASTER) + return EXP_LEVEL_EXPERT; + else + return EXP_LEVEL_MASTER; +} + void PlayerSkill::gain_melee_weapon_exp(const object_type *o_ptr) { auto now_exp = this->player_ptr->weapon_exp[o_ptr->tval][o_ptr->sval]; @@ -152,3 +182,62 @@ void PlayerSkill::gain_two_weapon_skill_exp() this->player_ptr->skill_exp[SKILL_TWO_WEAPON] += amount; set_bits(this->player_ptr->update, PU_BONUS); } + +void PlayerSkill::gain_riding_skill_exp_on_melee_attack(const monster_race *r_ptr) +{ + auto now_exp = this->player_ptr->skill_exp[SKILL_RIDING]; + auto max_exp = s_info[enum2i(this->player_ptr->pclass)].s_max[SKILL_RIDING]; + if (now_exp >= max_exp) + return; + + auto riding_level = r_info[this->player_ptr->current_floor_ptr->m_list[this->player_ptr->riding].r_idx].level; + int inc = 0; + + if ((now_exp / 200 - 5) < r_ptr->level) + inc += 1; + + if ((now_exp / 100) < riding_level) { + if ((now_exp / 100 + 15) < riding_level) + inc += 1 + (riding_level - (now_exp / 100 + 15)); + else + inc += 1; + } + + this->player_ptr->skill_exp[SKILL_RIDING] = std::min(max_exp, now_exp + inc); + set_bits(this->player_ptr->update, PU_BONUS); +} + +void PlayerSkill::gain_riding_skill_exp_on_range_attack() +{ + auto now_exp = this->player_ptr->skill_exp[SKILL_RIDING]; + auto max_exp = s_info[enum2i(this->player_ptr->pclass)].s_max[SKILL_RIDING]; + if (now_exp >= max_exp) + return; + + if (((this->player_ptr->skill_exp[SKILL_RIDING] - (RIDING_EXP_BEGINNER * 2)) / 200 < r_info[this->player_ptr->current_floor_ptr->m_list[this->player_ptr->riding].r_idx].level) && one_in_(2)) { + this->player_ptr->skill_exp[SKILL_RIDING] += 1; + set_bits(this->player_ptr->update, PU_BONUS); + } +} + +void PlayerSkill::gain_riding_skill_exp_on_fall_off_check(HIT_POINT dam) +{ + auto now_exp = this->player_ptr->skill_exp[SKILL_RIDING]; + auto max_exp = s_info[enum2i(this->player_ptr->pclass)].s_max[SKILL_RIDING]; + if (now_exp >= max_exp || max_exp <= 1000) + return; + + auto riding_level = r_info[this->player_ptr->current_floor_ptr->m_list[this->player_ptr->riding].r_idx].level; + + if ((dam / 2 + riding_level) <= (now_exp / 30 + 10)) + return; + + int inc = 0; + if ((now_exp / 100 + 15) < riding_level) + inc += 1 + (riding_level - (now_exp / 100 + 15)); + else + inc += 1; + + player_ptr->skill_exp[SKILL_RIDING] = std::min(max_exp, now_exp + inc); + set_bits(this->player_ptr->update, PU_BONUS); +} diff --git a/src/player/player-skill.h b/src/player/player-skill.h index 2b55cb30e..679819833 100644 --- a/src/player/player-skill.h +++ b/src/player/player-skill.h @@ -22,13 +22,6 @@ enum skill_idx { #define EXP_LEVEL_EXPERT 3 #define EXP_LEVEL_MASTER 4 -/* Proficiency of riding */ -#define RIDING_EXP_UNSKILLED 0 -#define RIDING_EXP_BEGINNER 500 -#define RIDING_EXP_SKILLED 2000 -#define RIDING_EXP_EXPERT 5000 -#define RIDING_EXP_MASTER 8000 - /* Proficiency of spells */ #define SPELL_EXP_UNSKILLED 0 #define SPELL_EXP_BEGINNER 900 @@ -52,6 +45,7 @@ typedef struct skill_table { extern std::vector s_info; +struct monster_race; struct object_type; struct player_type; @@ -62,11 +56,15 @@ public: static SUB_EXP weapon_exp_at(int level); static bool valid_weapon_exp(int weapon_exp); static int weapon_exp_level(int weapon_exp); + static int riding_exp_level(int riding_exp); void gain_melee_weapon_exp(const object_type *o_ptr); void gain_range_weapon_exp(const object_type *o_ptr); void gain_martial_arts_skill_exp(); void gain_two_weapon_skill_exp(); + void gain_riding_skill_exp_on_melee_attack(const monster_race *r_ptr); + void gain_riding_skill_exp_on_range_attack(); + void gain_riding_skill_exp_on_fall_off_check(HIT_POINT dam); private: player_type *player_ptr; diff --git a/src/player/player-status.cpp b/src/player/player-status.cpp index 94fce29a6..0b04cfc57 100644 --- a/src/player/player-status.cpp +++ b/src/player/player-status.cpp @@ -150,25 +150,6 @@ static player_hand main_attack_hand(player_type *player_ptr); /*** Player information ***/ /*! - * @brief 騎乗スキルの抽象的ランクを返す。 / Return proficiency level of riding - * @param weapon_exp 経験値 - * @return ランク値 - */ -int riding_exp_level(int riding_exp) -{ - if (riding_exp < RIDING_EXP_BEGINNER) - return EXP_LEVEL_UNSKILLED; - else if (riding_exp < RIDING_EXP_SKILLED) - return EXP_LEVEL_BEGINNER; - else if (riding_exp < RIDING_EXP_EXPERT) - return EXP_LEVEL_SKILLED; - else if (riding_exp < RIDING_EXP_MASTER) - return EXP_LEVEL_EXPERT; - else - return EXP_LEVEL_MASTER; -} - -/*! * @brief プレイヤーの呪文レベルの抽象的ランクを返す。 / Return proficiency level of spells * @param spell_exp 経験値 * @return ランク値 diff --git a/src/player/player-status.h b/src/player/player-status.h index 1ba79ceb6..b67c106d7 100644 --- a/src/player/player-status.h +++ b/src/player/player-status.h @@ -9,7 +9,6 @@ struct object_type;; struct player_type; -int riding_exp_level(int riding_exp); int spell_exp_level(int spell_exp); WEIGHT calc_weapon_weight_limit(player_type *player_ptr); -- 2.11.0