OSDN Git Service

4a1187df0c00ef32397d47070fb7055434d276ff
[hengbandforosx/hengbandosx.git] / src / object-enchant / protector / apply-magic-soft-armor.cpp
1 /*
2  * @brief 軽鎧に耐性等の追加効果を付与する処理
3  * @date 2022/03/12
4  * @author Hourier
5  */
6
7 #include "object-enchant/protector/apply-magic-soft-armor.h"
8 #include "object/object-kind-hook.h"
9 #include "object/tval-types.h"
10 #include "sv-definition/sv-armor-types.h"
11 #include "system/baseitem-info.h"
12 #include "system/item-entity.h"
13 #include "system/player-type-definition.h"
14
15 /*
16  * @brief コンストラクタ
17  * @param player_ptr プレイヤーへの参照ポインタ
18  * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
19  * @param level 生成基準階
20  * @param power 生成ランク
21  */
22 SoftArmorEnchanter::SoftArmorEnchanter(PlayerType *player_ptr, ItemEntity *o_ptr, DEPTH level, int power)
23     : ArmorEnchanter{ player_ptr, o_ptr, level, power }
24 {
25 }
26
27 /*!
28  * @brief power > 2 はデバッグ専用.
29  */
30 void SoftArmorEnchanter::apply_magic()
31 {
32     this->sval_enchant();
33     if (this->power > 1) {
34         this->give_high_ego_index();
35         if (this->is_high_ego_generated) {
36             return;
37         }
38
39         this->give_ego_index();
40         return;
41     }
42
43     if (this->power < -1) {
44         this->give_cursed();
45     }
46 }
47
48 void SoftArmorEnchanter::sval_enchant()
49 {
50     const auto sval = this->o_ptr->bi_key.sval();
51     if (!sval.has_value()) {
52         return;
53     }
54
55     switch (sval.value()) {
56     case SV_KUROSHOUZOKU:
57         this->o_ptr->pval = randint1(4);
58         return;
59     case SV_ABUNAI_MIZUGI:
60         if (this->player_ptr->ppersonality != PERSONALITY_SEXY) {
61             return;
62         }
63
64         this->o_ptr->pval = 3;
65         this->o_ptr->art_flags.set(TR_STR);
66         this->o_ptr->art_flags.set(TR_INT);
67         this->o_ptr->art_flags.set(TR_WIS);
68         this->o_ptr->art_flags.set(TR_DEX);
69         this->o_ptr->art_flags.set(TR_CON);
70         this->o_ptr->art_flags.set(TR_CHR);
71         return;
72     default:
73         return;
74     }
75 }
76
77 /*
78  * @brief ベースアイテムがローブの時、確率で永続か宵闇のローブを生成する.
79  * @return 生成条件を満たしたらtrue、満たさなかったらfalse
80  * @details 永続:12%、宵闇:3%
81  */
82 void SoftArmorEnchanter::give_high_ego_index()
83 {
84     const auto sval = this->o_ptr->bi_key.sval();
85     if ((sval != SV_ROBE) || (randint0(100) >= 15)) {
86         return;
87     }
88
89     this->is_high_ego_generated = true;
90     auto ego_robe = one_in_(5);
91     this->o_ptr->ego_idx = ego_robe ? EgoType::TWILIGHT : EgoType::PERMANENCE;
92     if (!ego_robe) {
93         return;
94     }
95
96     const BaseitemKey key(ItemKindType::SOFT_ARMOR, SV_TWILIGHT_ROBE);
97     this->o_ptr->bi_id = lookup_baseitem_id(key);
98     this->o_ptr->bi_key = key;
99     this->o_ptr->ac = 0;
100     this->o_ptr->to_a = 0;
101     return;
102 }