OSDN Git Service

Merge pull request #2122 from sikabane-works/release/3.0.0Alpha52
[hengbandforosx/hengbandosx.git] / src / object-enchant / protector / apply-magic-helm.cpp
1 /*
2  * @brief 兜に耐性等の追加効果を付与する処理
3  * @date 2021/08/01
4  * @author Hourier
5  * @details ドラゴンヘルムは必ず付与する. それ以外は確率的に付与する.
6  */
7
8 #include "object-enchant/protector/apply-magic-helm.h"
9 #include "artifact/random-art-generator.h"
10 #include "inventory/inventory-slot-types.h"
11 #include "object-enchant/object-boost.h"
12 #include "object-enchant/object-ego.h"
13 #include "sv-definition/sv-protector-types.h"
14 #include "system/object-type-definition.h"
15
16 /*
17  * @brief コンストラクタ
18  * @param player_ptr プレイヤーへの参照ポインタ
19  * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
20  * @param level 生成基準階
21  * @param power 生成ランク
22  */
23 HelmEnchanter::HelmEnchanter(PlayerType *player_ptr, object_type *o_ptr, DEPTH level, int power)
24     : AbstractProtectorEnchanter{ o_ptr, level, power }
25     , player_ptr(player_ptr)
26 {
27 }
28
29 void HelmEnchanter::apply_magic()
30 {
31     if (this->o_ptr->sval == SV_DRAGON_HELM) {
32         dragon_resist(this->o_ptr);
33         if (!one_in_(3)) {
34             return;
35         }
36     }
37
38     if (this->power > 1) {
39         this->give_ego_index();
40         return;
41     }
42
43     if (this->power < -1) {
44         this->give_cursed();
45     }
46 }
47
48 /*
49  * @details power > 2はデバッグ専用.
50  */
51 void HelmEnchanter::give_ego_index()
52 {
53     if (one_in_(20) || (this->power > 2)) {
54         become_random_artifact(this->player_ptr, this->o_ptr, false);
55         return;
56     }
57
58     while (true) {
59         this->o_ptr->name2 = get_random_ego(INVEN_HEAD, true);
60         switch (this->o_ptr->name2) {
61         case EGO_BRILLIANCE:
62         case EGO_DARK:
63         case EGO_INFRAVISION:
64         case EGO_H_PROTECTION:
65         case EGO_LITE:
66             return;
67         case EGO_SEEING:
68             if (one_in_(7)) {
69                 add_low_telepathy(this->o_ptr);
70             }
71
72             return;
73         default:
74             continue;
75         }
76     }
77 }
78
79 void HelmEnchanter::give_cursed()
80 {
81     while (true) {
82         this->o_ptr->name2 = get_random_ego(INVEN_HEAD, false);
83         switch (this->o_ptr->name2) {
84         case EGO_ANCIENT_CURSE:
85             return;
86         default:
87             continue;
88         }
89     }
90 }