OSDN Git Service

[Refactor] 吟遊詩人の固有データを magic_num から分離する
[hengbandforosx/hengbandosx.git] / src / player-base / player-class.cpp
1 /*!
2  * @brief プレイヤーの職業クラスに基づく耐性・能力の判定処理等を行うクラス
3  * @date 2021/09/08
4  * @author Hourier
5  * @details 本クラス作成時点で責務に対する余裕はかなりあるので、適宜ここへ移してくること.
6  */
7 #include "player-base/player-class.h"
8 #include "core/player-redraw-types.h"
9 #include "core/player-update-types.h"
10 #include "player-info/bard-data-type.h"
11 #include "player-info/bluemage-data-type.h"
12 #include "player-info/force-trainer-data-type.h"
13 #include "player-info/magic-eater-data-type.h"
14 #include "player-info/smith-data-type.h"
15 #include "player-info/spell-hex-data-type.h"
16 #include "player/attack-defense-types.h"
17 #include "player/special-defense-types.h"
18 #include "realm/realm-types.h"
19 #include "system/player-type-definition.h"
20 #include "util/bit-flags-calculator.h"
21
22 PlayerClass::PlayerClass(player_type *player_ptr)
23     : player_ptr(player_ptr)
24 {
25 }
26
27 bool PlayerClass::can_resist_stun() const
28 {
29     return (this->player_ptr->pclass == CLASS_BERSERKER) && (this->player_ptr->lev > 34);
30 }
31
32 bool PlayerClass::is_wizard() const
33 {
34     auto is_wizard = this->player_ptr->pclass == CLASS_MAGE;
35     is_wizard |= this->player_ptr->pclass == CLASS_HIGH_MAGE;
36     is_wizard |= this->player_ptr->pclass == CLASS_SORCERER;
37     is_wizard |= this->player_ptr->pclass == CLASS_MAGIC_EATER;
38     is_wizard |= this->player_ptr->pclass == CLASS_BLUE_MAGE;
39     is_wizard |= this->player_ptr->pclass == CLASS_ELEMENTALIST;
40     return is_wizard;
41 }
42
43 bool PlayerClass::lose_balance()
44 {
45     if (this->player_ptr->pclass != CLASS_SAMURAI) {
46         return false;
47     }
48
49     if (none_bits(this->player_ptr->special_defense, KATA_MASK)) {
50         return false;
51     }
52
53     reset_bits(this->player_ptr->special_defense, KATA_MASK);
54     this->player_ptr->update |= PU_BONUS;
55     this->player_ptr->update |= PU_MONSTERS;
56     this->player_ptr->redraw |= PR_STATE;
57     this->player_ptr->redraw |= PR_STATUS;
58     this->player_ptr->action = ACTION_NONE;
59     return true;
60 }
61
62 /**
63  * @brief プレイヤーの職業にで使用する職業固有データ領域を初期化する
64  * @details 事前条件: player_type の職業や領域が決定済みであること
65  */
66 void PlayerClass::init_specific_data()
67 {
68     switch (this->player_ptr->pclass) {
69     case CLASS_SMITH:
70         this->player_ptr->class_specific_data = std::make_shared<smith_data_type>();
71         break;
72     case CLASS_FORCETRAINER:
73         this->player_ptr->class_specific_data = std::make_shared<force_trainer_data_type>();
74         break;
75     case CLASS_BLUE_MAGE:
76         this->player_ptr->class_specific_data = std::make_shared<bluemage_data_type>();
77         break;
78     case CLASS_MAGIC_EATER:
79         this->player_ptr->class_specific_data = std::make_shared<magic_eater_data_type>();
80         break;
81     case CLASS_BARD:
82         this->player_ptr->class_specific_data = std::make_shared<bard_data_type>();
83         break;
84     case CLASS_HIGH_MAGE:
85         if (this->player_ptr->realm1 == REALM_HEX) {
86             this->player_ptr->class_specific_data = std::make_shared<spell_hex_data_type>();
87         } else {
88             this->player_ptr->class_specific_data = no_class_specific_data();
89         }
90         break;
91     default:
92         this->player_ptr->class_specific_data = no_class_specific_data();
93         break;
94     }
95 }