OSDN Git Service

[Refactor] 乗馬スキルの上昇処理を PlayerSkill クラスに移設
authorHabu <habu1010+github@gmail.com>
Fri, 15 Oct 2021 14:58:30 +0000 (23:58 +0900)
committerHabu <habu1010+github@gmail.com>
Fri, 15 Oct 2021 15:40:31 +0000 (00:40 +0900)
乗馬スキルの上昇処理を 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
src/combat/shoot.cpp
src/knowledge/knowledge-experiences.cpp
src/pet/pet-fall-off.cpp
src/player/player-skill.cpp
src/player/player-skill.h
src/player/player-status.cpp
src/player/player-status.h

index b7f1ce6..27fd36c 100644 (file)
@@ -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<short>(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;
index 1becee6..eedd564 100644 (file)
@@ -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) */
index 8980848..f78f58c 100644 (file)
@@ -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");
index a4a0357..5350ca3 100644 (file)
@@ -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<short>(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;
index 7e4ddca..1d000c7 100644 (file)
@@ -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<SUB_EXP>(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<SUB_EXP>(max_exp, now_exp + inc);
+    set_bits(this->player_ptr->update, PU_BONUS);
+}
index 2b55cb3..6798198 100644 (file)
@@ -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<skill_table> 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;
index 94fce29..0b04cfc 100644 (file)
@@ -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 ランク値
index 1ba79ce..b67c106 100644 (file)
@@ -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);