OSDN Git Service

7e4ddcade9cf5a8c00c26682f665f9e4167646d2
[hengbandforosx/hengbandosx.git] / src / player / player-skill.cpp
1 #include "player/player-skill.h"
2 #include "core/player-update-types.h"
3 #include "system/object-type-definition.h"
4 #include "system/player-type-definition.h"
5 #include "util/bit-flags-calculator.h"
6
7 /* Proficiency of weapons and misc. skills (except riding) */
8 constexpr SUB_EXP WEAPON_EXP_UNSKILLED = 0;
9 constexpr SUB_EXP WEAPON_EXP_BEGINNER = 4000;
10 constexpr SUB_EXP WEAPON_EXP_SKILLED = 6000;
11 constexpr SUB_EXP WEAPON_EXP_EXPERT = 7000;
12 constexpr SUB_EXP WEAPON_EXP_MASTER = 8000;
13
14 /*
15  * The skill table
16  */
17 std::vector<skill_table> s_info;
18
19 /*!
20  * @brief 技能値到達表記テーブル
21  */
22 const concptr exp_level_str[5] =
23 #ifdef JP
24     { "[初心者]", "[入門者]", "[熟練者]", "[エキスパート]", "[達人]" };
25 #else
26     { "[Unskilled]", "[Beginner]", "[Skilled]", "[Expert]", "[Master]" };
27 #endif
28
29 PlayerSkill::PlayerSkill(player_type *player_ptr)
30     : player_ptr(player_ptr)
31 {
32 }
33
34 SUB_EXP PlayerSkill::weapon_exp_at(int level)
35 {
36     switch (level) {
37     case EXP_LEVEL_UNSKILLED:
38         return WEAPON_EXP_UNSKILLED;
39     case EXP_LEVEL_BEGINNER:
40         return WEAPON_EXP_BEGINNER;
41     case EXP_LEVEL_SKILLED:
42         return WEAPON_EXP_SKILLED;
43     case EXP_LEVEL_EXPERT:
44         return WEAPON_EXP_EXPERT;
45     case EXP_LEVEL_MASTER:
46         return WEAPON_EXP_MASTER;
47     }
48
49     return WEAPON_EXP_UNSKILLED;
50 }
51
52 /*!
53  * @brief 武器や各種スキル(騎乗以外)の抽象的表現ランクを返す。 /  Return proficiency level of weapons and misc. skills (except riding)
54  * @param weapon_exp 経験値
55  * @return ランク値
56  */
57 int PlayerSkill::weapon_exp_level(int weapon_exp)
58 {
59     if (weapon_exp < WEAPON_EXP_BEGINNER)
60         return EXP_LEVEL_UNSKILLED;
61     else if (weapon_exp < WEAPON_EXP_SKILLED)
62         return EXP_LEVEL_BEGINNER;
63     else if (weapon_exp < WEAPON_EXP_EXPERT)
64         return EXP_LEVEL_SKILLED;
65     else if (weapon_exp < WEAPON_EXP_MASTER)
66         return EXP_LEVEL_EXPERT;
67     else
68         return EXP_LEVEL_MASTER;
69 }
70
71 bool PlayerSkill::valid_weapon_exp(int weapon_exp)
72 {
73     return (WEAPON_EXP_UNSKILLED <= weapon_exp) && (weapon_exp <= WEAPON_EXP_MASTER);
74 }
75
76 void PlayerSkill::gain_melee_weapon_exp(const object_type *o_ptr)
77 {
78     auto now_exp = this->player_ptr->weapon_exp[o_ptr->tval][o_ptr->sval];
79     if (now_exp >= s_info[enum2i(this->player_ptr->pclass)].w_max[o_ptr->tval][o_ptr->sval])
80         return;
81
82     SUB_EXP amount = 0;
83     if (now_exp < WEAPON_EXP_BEGINNER)
84         amount = 80;
85     else if (now_exp < WEAPON_EXP_SKILLED)
86         amount = 10;
87     else if ((now_exp < WEAPON_EXP_EXPERT) && (this->player_ptr->lev > 19))
88         amount = 1;
89     else if ((player_ptr->lev > 34) && one_in_(2))
90         amount = 1;
91
92     this->player_ptr->weapon_exp[o_ptr->tval][o_ptr->sval] += amount;
93     set_bits(this->player_ptr->update, PU_BONUS);
94 }
95
96 void PlayerSkill::gain_range_weapon_exp(const object_type *o_ptr)
97 {
98     auto now_exp = this->player_ptr->weapon_exp[o_ptr->tval][o_ptr->sval];
99     if (now_exp >= s_info[enum2i(this->player_ptr->pclass)].w_max[o_ptr->tval][o_ptr->sval])
100         return;
101
102     SUB_EXP amount = 0;
103     if (now_exp < WEAPON_EXP_BEGINNER)
104         amount = 80;
105     else if (now_exp < WEAPON_EXP_SKILLED)
106         amount = 25;
107     else if ((now_exp < WEAPON_EXP_EXPERT) && (this->player_ptr->lev > 19))
108         amount = 10;
109     else if (this->player_ptr->lev > 34)
110         amount = 2;
111
112     this->player_ptr->weapon_exp[o_ptr->tval][o_ptr->sval] += amount;
113     set_bits(this->player_ptr->update, PU_BONUS);
114 }
115
116 void PlayerSkill::gain_martial_arts_skill_exp()
117 {
118     auto now_exp = this->player_ptr->skill_exp[SKILL_MARTIAL_ARTS];
119     if (now_exp >= s_info[enum2i(this->player_ptr->pclass)].s_max[SKILL_MARTIAL_ARTS])
120         return;
121
122     SUB_EXP amount = 0;
123     if (now_exp < WEAPON_EXP_BEGINNER)
124         amount = 40;
125     else if (now_exp < WEAPON_EXP_SKILLED)
126         amount = 5;
127     else if ((now_exp < WEAPON_EXP_EXPERT) && (this->player_ptr->lev > 19))
128         amount = 1;
129     else if ((this->player_ptr->lev > 34) && one_in_(3))
130         amount = 1;
131
132     this->player_ptr->skill_exp[SKILL_MARTIAL_ARTS] += amount;
133     set_bits(this->player_ptr->update, PU_BONUS);
134 }
135
136 void PlayerSkill::gain_two_weapon_skill_exp()
137 {
138     auto now_exp = this->player_ptr->skill_exp[SKILL_TWO_WEAPON];
139     if (now_exp >= s_info[enum2i(this->player_ptr->pclass)].s_max[SKILL_TWO_WEAPON])
140         return;
141
142     SUB_EXP amount = 0;
143     if (now_exp < WEAPON_EXP_BEGINNER)
144         amount = 80;
145     else if (now_exp < WEAPON_EXP_SKILLED)
146         amount = 4;
147     else if ((now_exp < WEAPON_EXP_EXPERT) && (this->player_ptr->lev > 19))
148         amount = 1;
149     else if ((this->player_ptr->lev > 34) && one_in_(3))
150         amount = 1;
151
152     this->player_ptr->skill_exp[SKILL_TWO_WEAPON] += amount;
153     set_bits(this->player_ptr->update, PU_BONUS);
154 }