1 #include "player/player-skill.h"
2 #include "core/player-update-types.h"
3 #include "monster-race/monster-race.h"
4 #include "player-info/class-info.h"
5 #include "player/player-realm.h"
6 #include "system/floor-type-definition.h"
7 #include "system/monster-race-definition.h"
8 #include "system/monster-type-definition.h"
9 #include "system/object-type-definition.h"
10 #include "system/player-type-definition.h"
11 #include "util/bit-flags-calculator.h"
13 /* Proficiency of weapons and misc. skills (except riding) */
14 constexpr SUB_EXP WEAPON_EXP_UNSKILLED = 0;
15 constexpr SUB_EXP WEAPON_EXP_BEGINNER = 4000;
16 constexpr SUB_EXP WEAPON_EXP_SKILLED = 6000;
17 constexpr SUB_EXP WEAPON_EXP_EXPERT = 7000;
18 constexpr SUB_EXP WEAPON_EXP_MASTER = 8000;
20 /* Proficiency of riding */
21 constexpr SUB_EXP RIDING_EXP_UNSKILLED = 0;
22 constexpr SUB_EXP RIDING_EXP_BEGINNER = 500;
23 constexpr SUB_EXP RIDING_EXP_SKILLED = 2000;
24 constexpr SUB_EXP RIDING_EXP_EXPERT = 5000;
25 constexpr SUB_EXP RIDING_EXP_MASTER = 8000;
27 /* Proficiency of spells */
28 constexpr SUB_EXP SPELL_EXP_UNSKILLED = 0;
29 constexpr SUB_EXP SPELL_EXP_BEGINNER = 900;
30 constexpr SUB_EXP SPELL_EXP_SKILLED = 1200;
31 constexpr SUB_EXP SPELL_EXP_EXPERT = 1400;
32 constexpr SUB_EXP SPELL_EXP_MASTER = 1600;
37 std::vector<skill_table> s_info;
42 const concptr exp_level_str[5] =
44 { "[初心者]", "[入門者]", "[熟練者]", "[エキスパート]", "[達人]" };
46 { "[Unskilled]", "[Beginner]", "[Skilled]", "[Expert]", "[Master]" };
51 using GainAmountList = std::array<int, EXP_LEVEL_MASTER>;
53 void gain_attack_skill_exp(player_type *player_ptr, short &exp, const GainAmountList &gain_amount_list)
57 if (exp < WEAPON_EXP_BEGINNER) {
58 gain_amount = std::min(gain_amount_list[EXP_LEVEL_UNSKILLED], WEAPON_EXP_BEGINNER - exp);
59 } else if (exp < WEAPON_EXP_SKILLED) {
60 gain_amount = std::min(gain_amount_list[EXP_LEVEL_BEGINNER], WEAPON_EXP_SKILLED - exp);
61 } else if ((exp < WEAPON_EXP_EXPERT) && (player_ptr->lev > 19)) {
62 gain_amount = std::min(gain_amount_list[EXP_LEVEL_SKILLED], WEAPON_EXP_EXPERT - exp);
63 } else if ((exp < WEAPON_EXP_MASTER) && (player_ptr->lev > 34)) {
64 gain_amount = std::min(gain_amount_list[EXP_LEVEL_EXPERT], WEAPON_EXP_MASTER - exp);
67 exp += static_cast<short>(gain_amount);
68 set_bits(player_ptr->update, PU_BONUS);
71 void gain_spell_skill_exp_aux(player_type *player_ptr, short &exp, const GainAmountList &gain_amount_list, int spell_level)
73 const auto dlev = player_ptr->current_floor_ptr->dun_level;
74 const auto plev = player_ptr->lev;
77 if (exp < SPELL_EXP_BEGINNER) {
78 gain_amount = std::min(gain_amount_list[EXP_LEVEL_UNSKILLED], SPELL_EXP_BEGINNER - exp);
79 } else if (exp < SPELL_EXP_SKILLED) {
80 if ((dlev > 4) && ((dlev + 10) > plev)) {
81 gain_amount = std::min(gain_amount_list[EXP_LEVEL_BEGINNER], SPELL_EXP_SKILLED - exp);
83 } else if (exp < SPELL_EXP_EXPERT) {
84 if (((dlev + 5) > plev) && ((dlev + 5) > spell_level)) {
85 gain_amount = std::min(gain_amount_list[EXP_LEVEL_SKILLED], SPELL_EXP_EXPERT - exp);
87 } else if (exp < SPELL_EXP_MASTER) {
88 if (((dlev + 5) > plev) && (dlev > spell_level)) {
89 gain_amount = std::min(gain_amount_list[EXP_LEVEL_EXPERT], SPELL_EXP_MASTER - exp);
93 exp += static_cast<short>(gain_amount);
94 set_bits(player_ptr->update, PU_BONUS);
99 PlayerSkill::PlayerSkill(player_type *player_ptr)
100 : player_ptr(player_ptr)
104 SUB_EXP PlayerSkill::weapon_exp_at(int level)
107 case EXP_LEVEL_UNSKILLED:
108 return WEAPON_EXP_UNSKILLED;
109 case EXP_LEVEL_BEGINNER:
110 return WEAPON_EXP_BEGINNER;
111 case EXP_LEVEL_SKILLED:
112 return WEAPON_EXP_SKILLED;
113 case EXP_LEVEL_EXPERT:
114 return WEAPON_EXP_EXPERT;
115 case EXP_LEVEL_MASTER:
116 return WEAPON_EXP_MASTER;
119 return WEAPON_EXP_UNSKILLED;
122 SUB_EXP PlayerSkill::spell_exp_at(int level)
125 case EXP_LEVEL_UNSKILLED:
126 return SPELL_EXP_UNSKILLED;
127 case EXP_LEVEL_BEGINNER:
128 return SPELL_EXP_BEGINNER;
129 case EXP_LEVEL_SKILLED:
130 return SPELL_EXP_SKILLED;
131 case EXP_LEVEL_EXPERT:
132 return SPELL_EXP_EXPERT;
133 case EXP_LEVEL_MASTER:
134 return SPELL_EXP_MASTER;
137 return SPELL_EXP_UNSKILLED;
140 * @brief 武器や各種スキル(騎乗以外)の抽象的表現ランクを返す。 / Return proficiency level of weapons and misc. skills (except riding)
141 * @param weapon_exp 経験値
144 int PlayerSkill::weapon_exp_level(int weapon_exp)
146 if (weapon_exp < WEAPON_EXP_BEGINNER)
147 return EXP_LEVEL_UNSKILLED;
148 else if (weapon_exp < WEAPON_EXP_SKILLED)
149 return EXP_LEVEL_BEGINNER;
150 else if (weapon_exp < WEAPON_EXP_EXPERT)
151 return EXP_LEVEL_SKILLED;
152 else if (weapon_exp < WEAPON_EXP_MASTER)
153 return EXP_LEVEL_EXPERT;
155 return EXP_LEVEL_MASTER;
158 bool PlayerSkill::valid_weapon_exp(int weapon_exp)
160 return (WEAPON_EXP_UNSKILLED <= weapon_exp) && (weapon_exp <= WEAPON_EXP_MASTER);
164 * @brief 騎乗スキルの抽象的ランクを返す。 / Return proficiency level of riding
165 * @param riding_exp 経験値
168 int PlayerSkill::riding_exp_level(int riding_exp)
170 if (riding_exp < RIDING_EXP_BEGINNER)
171 return EXP_LEVEL_UNSKILLED;
172 else if (riding_exp < RIDING_EXP_SKILLED)
173 return EXP_LEVEL_BEGINNER;
174 else if (riding_exp < RIDING_EXP_EXPERT)
175 return EXP_LEVEL_SKILLED;
176 else if (riding_exp < RIDING_EXP_MASTER)
177 return EXP_LEVEL_EXPERT;
179 return EXP_LEVEL_MASTER;
183 * @brief プレイヤーの呪文レベルの抽象的ランクを返す。 / Return proficiency level of spells
184 * @param spell_exp 経験値
187 int PlayerSkill::spell_exp_level(int spell_exp)
189 if (spell_exp < SPELL_EXP_BEGINNER)
190 return EXP_LEVEL_UNSKILLED;
191 else if (spell_exp < SPELL_EXP_SKILLED)
192 return EXP_LEVEL_BEGINNER;
193 else if (spell_exp < SPELL_EXP_EXPERT)
194 return EXP_LEVEL_SKILLED;
195 else if (spell_exp < SPELL_EXP_MASTER)
196 return EXP_LEVEL_EXPERT;
198 return EXP_LEVEL_MASTER;
201 concptr PlayerSkill::skill_name(PlayerSkillKindType skill)
204 case PlayerSkillKindType::MARTIAL_ARTS:
205 return _("マーシャルアーツ", "Martial Arts");
206 case PlayerSkillKindType::TWO_WEAPON:
207 return _("二刀流", "Dual Wielding");
208 case PlayerSkillKindType::RIDING:
209 return _("乗馬", "Riding");
210 case PlayerSkillKindType::SHIELD:
211 return _("盾", "Shield");
212 case PlayerSkillKindType::MAX:
216 return _("不明", "Unknown");
219 void PlayerSkill::gain_melee_weapon_exp(const object_type *o_ptr)
221 const GainAmountList gain_amount_list{ 80, 10, 1, (one_in_(2) ? 1 : 0) };
222 constexpr GainAmountList others_gain_amount_list{ 8, 1, 0, 0 };
224 for (auto sval = 0U; sval < this->player_ptr->weapon_exp[o_ptr->tval].size(); ++sval) {
225 auto &now_exp = this->player_ptr->weapon_exp[o_ptr->tval][sval];
226 if (now_exp < s_info[enum2i(this->player_ptr->pclass)].w_max[o_ptr->tval][sval]) {
227 gain_attack_skill_exp(this->player_ptr, now_exp,
228 (static_cast<int>(sval) == o_ptr->sval) ? gain_amount_list : others_gain_amount_list);
233 void PlayerSkill::gain_range_weapon_exp(const object_type *o_ptr)
235 constexpr GainAmountList gain_amount_list{ 80, 25, 10, 2 };
236 constexpr GainAmountList others_gain_amount_list{ 8, 2, 0, 0 };
238 for (auto sval = 0U; sval < this->player_ptr->weapon_exp[o_ptr->tval].size(); ++sval) {
239 auto &now_exp = this->player_ptr->weapon_exp[o_ptr->tval][sval];
240 if (now_exp < s_info[enum2i(this->player_ptr->pclass)].w_max[o_ptr->tval][sval]) {
241 gain_attack_skill_exp(this->player_ptr, now_exp,
242 (static_cast<int>(sval) == o_ptr->sval) ? gain_amount_list : others_gain_amount_list);
247 void PlayerSkill::gain_martial_arts_skill_exp()
249 if (this->player_ptr->skill_exp[PlayerSkillKindType::MARTIAL_ARTS] < s_info[enum2i(this->player_ptr->pclass)].s_max[PlayerSkillKindType::MARTIAL_ARTS]) {
250 const GainAmountList gain_amount_list{ 40, 5, 1, (one_in_(3) ? 1 : 0) };
251 gain_attack_skill_exp(this->player_ptr, this->player_ptr->skill_exp[PlayerSkillKindType::MARTIAL_ARTS], gain_amount_list);
255 void PlayerSkill::gain_two_weapon_skill_exp()
257 if (this->player_ptr->skill_exp[PlayerSkillKindType::TWO_WEAPON] < s_info[enum2i(this->player_ptr->pclass)].s_max[PlayerSkillKindType::TWO_WEAPON]) {
258 const GainAmountList gain_amount_list{ 80, 4, 1, (one_in_(3) ? 1 : 0) };
259 gain_attack_skill_exp(this->player_ptr, this->player_ptr->skill_exp[PlayerSkillKindType::TWO_WEAPON], gain_amount_list);
263 void PlayerSkill::gain_riding_skill_exp_on_melee_attack(const monster_race *r_ptr)
265 auto now_exp = this->player_ptr->skill_exp[PlayerSkillKindType::RIDING];
266 auto max_exp = s_info[enum2i(this->player_ptr->pclass)].s_max[PlayerSkillKindType::RIDING];
267 if (now_exp >= max_exp)
270 auto riding_level = r_info[this->player_ptr->current_floor_ptr->m_list[this->player_ptr->riding].r_idx].level;
273 if ((now_exp / 200 - 5) < r_ptr->level)
276 if ((now_exp / 100) < riding_level) {
277 if ((now_exp / 100 + 15) < riding_level)
278 inc += 1 + (riding_level - (now_exp / 100 + 15));
283 this->player_ptr->skill_exp[PlayerSkillKindType::RIDING] = std::min<SUB_EXP>(max_exp, now_exp + inc);
284 set_bits(this->player_ptr->update, PU_BONUS);
287 void PlayerSkill::gain_riding_skill_exp_on_range_attack()
289 auto now_exp = this->player_ptr->skill_exp[PlayerSkillKindType::RIDING];
290 auto max_exp = s_info[enum2i(this->player_ptr->pclass)].s_max[PlayerSkillKindType::RIDING];
291 if (now_exp >= max_exp)
294 if (((this->player_ptr->skill_exp[PlayerSkillKindType::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)) {
295 this->player_ptr->skill_exp[PlayerSkillKindType::RIDING] += 1;
296 set_bits(this->player_ptr->update, PU_BONUS);
300 void PlayerSkill::gain_riding_skill_exp_on_fall_off_check(HIT_POINT dam)
302 auto now_exp = this->player_ptr->skill_exp[PlayerSkillKindType::RIDING];
303 auto max_exp = s_info[enum2i(this->player_ptr->pclass)].s_max[PlayerSkillKindType::RIDING];
304 if (now_exp >= max_exp || max_exp <= 1000)
307 auto riding_level = r_info[this->player_ptr->current_floor_ptr->m_list[this->player_ptr->riding].r_idx].level;
309 if ((dam / 2 + riding_level) <= (now_exp / 30 + 10))
313 if ((now_exp / 100 + 15) < riding_level)
314 inc += 1 + (riding_level - (now_exp / 100 + 15));
318 this->player_ptr->skill_exp[PlayerSkillKindType::RIDING] = std::min<SUB_EXP>(max_exp, now_exp + inc);
319 set_bits(this->player_ptr->update, PU_BONUS);
322 void PlayerSkill::gain_spell_skill_exp(int realm, int spell_idx)
324 if (((spell_idx < 0) || (32 <= spell_idx)) ||
325 ((realm < 1) || (static_cast<int>(std::size(mp_ptr->info)) < realm)) ||
326 ((realm != this->player_ptr->realm1) && (realm != this->player_ptr->realm2))) {
330 constexpr GainAmountList gain_amount_list_first{ 60, 8, 2, 1 };
331 constexpr GainAmountList gain_amount_list_second{ 60, 8, 2, 0 };
333 const auto is_first_realm = (realm == this->player_ptr->realm1);
334 const auto *s_ptr = &mp_ptr->info[realm - 1][spell_idx];
336 gain_spell_skill_exp_aux(this->player_ptr, this->player_ptr->spell_exp[spell_idx + (is_first_realm ? 0 : 32)],
337 (is_first_realm ? gain_amount_list_first : gain_amount_list_second), s_ptr->slevel);
340 void PlayerSkill::gain_continuous_spell_skill_exp(int realm, int spell_idx)
342 if (((spell_idx < 0) || (32 <= spell_idx)) ||
343 ((realm != REALM_MUSIC) && (realm != REALM_HEX))) {
347 const auto *s_ptr = &technic_info[realm - MIN_TECHNIC][spell_idx];
349 const GainAmountList gain_amount_list{ 5, (one_in_(2) ? 1 : 0), (one_in_(5) ? 1 : 0), (one_in_(5) ? 1 : 0) };
351 gain_spell_skill_exp_aux(this->player_ptr, this->player_ptr->spell_exp[spell_idx], gain_amount_list, s_ptr->slevel);
354 int PlayerSkill::gain_spell_skill_exp_over_learning(int spell_idx)
356 if ((spell_idx < 0) || (static_cast<int>(std::size(this->player_ptr->spell_exp)) <= spell_idx)) {
357 return EXP_LEVEL_UNSKILLED;
360 auto &exp = this->player_ptr->spell_exp[spell_idx];
362 if (exp >= SPELL_EXP_EXPERT) {
363 exp = SPELL_EXP_MASTER;
364 } else if (exp >= SPELL_EXP_SKILLED) {
365 if (spell_idx >= 32) {
366 exp = SPELL_EXP_EXPERT;
368 exp += SPELL_EXP_EXPERT - SPELL_EXP_SKILLED;
370 } else if (exp >= SPELL_EXP_BEGINNER) {
371 exp = SPELL_EXP_SKILLED + (exp - SPELL_EXP_BEGINNER) * 2 / 3;
373 exp = SPELL_EXP_BEGINNER + exp / 3;
376 set_bits(this->player_ptr->update, PU_BONUS);
378 return PlayerSkill::spell_exp_level(exp);
383 * Returns experience of a spell
384 * @param use_realm 魔法領域
385 * @param spell_idx 呪文ID
388 EXP PlayerSkill::exp_of_spell(int realm, int spell_idx) const
390 if (this->player_ptr->pclass == PlayerClassType::SORCERER)
391 return SPELL_EXP_MASTER;
392 else if (this->player_ptr->pclass == PlayerClassType::RED_MAGE)
393 return SPELL_EXP_SKILLED;
394 else if (realm == this->player_ptr->realm1)
395 return this->player_ptr->spell_exp[spell_idx];
396 else if (realm == this->player_ptr->realm2)
397 return this->player_ptr->spell_exp[spell_idx + 32];