OSDN Git Service

[Refactor] スナイパーの専用データを職業固有データに移動する
[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/mane-data-type.h"
15 #include "player-info/smith-data-type.h"
16 #include "player-info/sniper-data-type.h"
17 #include "player-info/spell-hex-data-type.h"
18 #include "player/attack-defense-types.h"
19 #include "player/special-defense-types.h"
20 #include "realm/realm-types.h"
21 #include "system/player-type-definition.h"
22 #include "util/bit-flags-calculator.h"
23
24 PlayerClass::PlayerClass(player_type *player_ptr)
25     : player_ptr(player_ptr)
26 {
27 }
28
29 bool PlayerClass::can_resist_stun() const
30 {
31     return (this->player_ptr->pclass == CLASS_BERSERKER) && (this->player_ptr->lev > 34);
32 }
33
34 bool PlayerClass::is_wizard() const
35 {
36     auto is_wizard = this->player_ptr->pclass == CLASS_MAGE;
37     is_wizard |= this->player_ptr->pclass == CLASS_HIGH_MAGE;
38     is_wizard |= this->player_ptr->pclass == CLASS_SORCERER;
39     is_wizard |= this->player_ptr->pclass == CLASS_MAGIC_EATER;
40     is_wizard |= this->player_ptr->pclass == CLASS_BLUE_MAGE;
41     is_wizard |= this->player_ptr->pclass == CLASS_ELEMENTALIST;
42     return is_wizard;
43 }
44
45 bool PlayerClass::lose_balance()
46 {
47     if (this->player_ptr->pclass != CLASS_SAMURAI) {
48         return false;
49     }
50
51     if (none_bits(this->player_ptr->special_defense, KATA_MASK)) {
52         return false;
53     }
54
55     reset_bits(this->player_ptr->special_defense, KATA_MASK);
56     this->player_ptr->update |= PU_BONUS;
57     this->player_ptr->update |= PU_MONSTERS;
58     this->player_ptr->redraw |= PR_STATE;
59     this->player_ptr->redraw |= PR_STATUS;
60     this->player_ptr->action = ACTION_NONE;
61     return true;
62 }
63
64 /**
65  * @brief プレイヤーの職業にで使用する職業固有データ領域を初期化する
66  * @details 事前条件: player_type の職業や領域が決定済みであること
67  */
68 void PlayerClass::init_specific_data()
69 {
70     switch (this->player_ptr->pclass) {
71     case CLASS_SMITH:
72         this->player_ptr->class_specific_data = std::make_shared<smith_data_type>();
73         break;
74     case CLASS_FORCETRAINER:
75         this->player_ptr->class_specific_data = std::make_shared<force_trainer_data_type>();
76         break;
77     case CLASS_BLUE_MAGE:
78         this->player_ptr->class_specific_data = std::make_shared<bluemage_data_type>();
79         break;
80     case CLASS_MAGIC_EATER:
81         this->player_ptr->class_specific_data = std::make_shared<magic_eater_data_type>();
82         break;
83     case CLASS_BARD:
84         this->player_ptr->class_specific_data = std::make_shared<bard_data_type>();
85         break;
86     case CLASS_IMITATOR:
87         this->player_ptr->class_specific_data = std::make_shared<mane_data_type>();
88         break;
89     case CLASS_SNIPER:
90         this->player_ptr->class_specific_data = std::make_shared<sniper_data_type>();
91         break;
92     case CLASS_HIGH_MAGE:
93         if (this->player_ptr->realm1 == REALM_HEX) {
94             this->player_ptr->class_specific_data = std::make_shared<spell_hex_data_type>();
95         } else {
96             this->player_ptr->class_specific_data = no_class_specific_data();
97         }
98         break;
99     default:
100         this->player_ptr->class_specific_data = no_class_specific_data();
101         break;
102     }
103 }