OSDN Git Service

Merge pull request #1780 from Hourier/Remove-Unnecessary-Return-Init-Buildings
[hengbandforosx/hengbandosx.git] / src / player-status / player-stealth.cpp
1 #include "player-status/player-stealth.h"
2 #include "mind/mind-ninja.h"
3 #include "mutation/mutation-flag-types.h"
4 #include "player-info/class-info.h"
5 #include "player-info/equipment-info.h"
6 #include "player-info/mimic-info-table.h"
7 #include "player-info/race-types.h"
8 #include "player/player-personality.h"
9 #include "player/player-skill.h"
10 #include "player/player-status-flags.h"
11 #include "player/player-status.h"
12 #include "player/race-info-table.h"
13 #include "spell-realm/spells-hex.h"
14 #include "system/object-type-definition.h"
15 #include "system/player-type-definition.h"
16 #include "util/bit-flags-calculator.h"
17 #include "util/enum-converter.h"
18
19 /*!
20  * @brief 隠密能力計算 - 種族
21  * @return 隠密能力の増分
22  * @details
23  * * 種族による加算
24  */
25 int16_t PlayerStealth::race_value()
26 {
27     const player_race_info *tmp_rp_ptr;
28
29     if (this->player_ptr->mimic_form)
30         tmp_rp_ptr = &mimic_info[this->player_ptr->mimic_form];
31     else
32         tmp_rp_ptr = &race_info[enum2i(this->player_ptr->prace)];
33
34     return tmp_rp_ptr->r_stl;
35 }
36
37 /*!
38  * @brief 隠密能力計算 - 性格
39  * @return 隠密能力の増分
40  * @details
41  * * 性格による加算
42  */
43 int16_t PlayerStealth::personality_value()
44 {
45     const player_personality *a_ptr = &personality_info[this->player_ptr->ppersonality];
46     return a_ptr->a_stl;
47 }
48
49 /*!
50  * @brief 隠密能力計算 - 職業(基礎値)
51  * @return 隠密能力の増分
52  * @details
53  * * 職業による加算
54  */
55 int16_t PlayerStealth::class_base_value()
56 {
57     const player_class_info *c_ptr = &class_info[enum2i(this->player_ptr->pclass)];
58     return c_ptr->c_stl + (c_ptr->x_stl * this->player_ptr->lev / 10);
59 }
60
61 /*!
62  * @brief 隠密能力計算 - 職業(追加分)
63  * @return 隠密能力の増分
64  * @details
65  * * 忍者がheavy_armorならば減算(-レベル/10)
66  * * 忍者がheavy_armorでなく適正な武器を持っていれば加算(+レベル/10)
67  */
68 int16_t PlayerStealth::class_value()
69 {
70     ACTION_SKILL_POWER result = 0;
71
72     if (this->player_ptr->pclass == PlayerClassType::NINJA) {
73         if (heavy_armor(this->player_ptr)) {
74             result -= (this->player_ptr->lev) / 10;
75         } else if ((!this->player_ptr->inventory_list[INVEN_MAIN_HAND].k_idx || can_attack_with_main_hand(this->player_ptr))
76             && (!this->player_ptr->inventory_list[INVEN_SUB_HAND].k_idx || can_attack_with_sub_hand(this->player_ptr))) {
77             result += (this->player_ptr->lev) / 10;
78         }
79     }
80
81     return result;
82 }
83
84 /*!
85  * @brief 隠密能力計算 - 変異
86  * @return 隠密能力の増分
87  * @details
88  * * 変異MUT3_XTRA_NOISで減算(-3)
89  * * 変異MUT3_MOTIONで加算(+1)
90  */
91 int16_t PlayerStealth::mutation_value()
92 {
93     int16_t result = 0;
94     const auto &muta = this->player_ptr->muta;
95     if (muta.has(MUTA::XTRA_NOIS)) {
96         result -= 3;
97     }
98     if (muta.has(MUTA::MOTION)) {
99         result += 1;
100     }
101     return result;
102 }
103
104 /*!
105  * @brief 隠密能力計算 - 一時効果
106  * @return 隠密能力の増分
107  * @details
108  * * 呪術を唱えていると減算(-(詠唱数+1))
109  * * 狂戦士化で減算(-7)
110  * * 隠密の歌で加算(+999)
111  */
112 int16_t PlayerStealth::time_effect_value()
113 {
114     int16_t result = 0;
115     if (this->player_ptr->realm1 == REALM_HEX) {
116         SpellHex spell_hex(this->player_ptr);
117         if (spell_hex.is_spelling_any()) {
118             result -= spell_hex.get_casting_num() + 1;
119         }
120     }
121
122     if (is_shero(this->player_ptr)) {
123         result -= 7;
124     }
125
126     if (is_time_limit_stealth(this->player_ptr)) {
127         result += 999;
128     }
129
130     return result;
131 }
132
133 bool PlayerStealth::is_aggravated_s_fairy()
134 {
135     return player_aggravate_state(this->player_ptr) == AGGRAVATE_S_FAIRY;
136 }
137
138 /*!
139  * @brief 隠密能力計算 - 影フェアリー反感時の例外処理
140  * @return 修正後の隠密能力
141  * @details
142  * * セクシーギャルでない影フェアリーがTRC_AGGRAVATE持ちの時、別処理でTRC_AGGRAVATEを無効にする代わりに減算(-3か3未満なら(現在値+2)/2)
143  */
144 int16_t PlayerStealth::set_exception_value(int16_t value)
145 {
146     if (this->is_aggravated_s_fairy()) {
147         value = std::min<int16_t>(value - 3, (value + 2) / 2);
148     }
149     return value;
150 }
151
152 /*!
153  * @brief 隠密マイナスフラグ判定
154  * @return マイナスフラグの集合体
155  * @details
156  * * TR_STELATHがマイナスの要素に加え、種族影フェアリーかつ反感のとき種族にマイナスフラグを与える
157  */
158 BIT_FLAGS PlayerStealth::get_bad_flags()
159 {
160     BIT_FLAGS result = PlayerStatusBase::get_bad_flags();
161
162     if (this->is_aggravated_s_fairy())
163         set_bits(result, FLAG_CAUSE_RACE);
164
165     return result;
166 }
167
168 /*!
169  * @brief 隠密値の上限と下限の設定
170  * @details
171  * * 初期値1
172  * * 最大30、最低0に補正
173  */
174 void PlayerStealth::set_locals()
175 {
176     this->default_value = 1;
177     this->min_value = 0;
178     this->max_value = 30;
179     this->tr_flag = TR_STEALTH;
180     this->tr_bad_flag = TR_STEALTH;
181 }