OSDN Git Service

fa6341b136f2e8bdf7435f4081f1effe74b35c26
[hengbandforosx/hengbandosx.git] / src / object-enchant / weapon / apply-magic-sword.cpp
1 /*!
2  * @brief 剣に耐性等の追加効果を付与する処理
3  * @date 2022/03/22
4  * @author Hourier
5  */
6
7 #include "object-enchant/weapon/apply-magic-sword.h"
8 #include "floor/floor-base-definitions.h"
9 #include "inventory/inventory-slot-types.h"
10 #include "object-enchant/object-boost.h"
11 #include "sv-definition/sv-weapon-types.h"
12 #include "system/item-entity.h"
13 #include "view/display-messages.h"
14
15 /*!
16  * @brief 剣強化クラスのコンストラクタ
17  * @param player_ptr プレイヤーへの参照ポインタ
18  * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
19  * @param level 生成基準階
20  * @param power 生成ランク
21  */
22 SwordEnchanter::SwordEnchanter(PlayerType *player_ptr, ItemEntity *o_ptr, DEPTH level, int power)
23     : MeleeWeaponEnchanter(player_ptr, o_ptr, level, power)
24 {
25 }
26
27 void SwordEnchanter::decide_skip()
28 {
29     AbstractWeaponEnchanter::decide_skip();
30     const auto sval = this->o_ptr->bi_key.sval();
31     this->should_skip |= sval == SV_POISON_NEEDLE;
32 }
33
34 void SwordEnchanter::apply_magic()
35 {
36     this->decide_skip();
37     if (this->should_skip) {
38         return;
39     }
40
41     this->give_killing_bonus();
42     const auto sval = this->o_ptr->bi_key.sval();
43     if (sval == SV_DIAMOND_EDGE) {
44         return;
45     }
46
47     MeleeWeaponEnchanter::apply_magic();
48 }
49
50 void SwordEnchanter::give_ego_index()
51 {
52     while (true) {
53         this->o_ptr->ego_idx = get_random_ego(INVEN_MAIN_HAND, true);
54         if (this->o_ptr->ego_idx == EgoType::EARTHQUAKES) {
55             continue;
56         }
57
58         break;
59     }
60
61     switch (this->o_ptr->ego_idx) {
62     case EgoType::SHARPNESS:
63         this->o_ptr->pval = static_cast<short>(m_bonus(5, this->level) + 1);
64         break;
65     default:
66         break;
67     }
68 }
69
70 void SwordEnchanter::give_cursed()
71 {
72     if (randint0(MAX_DEPTH) >= this->level) {
73         return;
74     }
75
76     auto n = 0;
77     const auto sval = this->o_ptr->bi_key.sval();
78     while (true) {
79         this->o_ptr->ego_idx = get_random_ego(INVEN_MAIN_HAND, false);
80         if ((sval != SV_HAYABUSA) || (this->o_ptr->get_ego().max_pval >= 0)) {
81             return;
82         }
83
84         if (++n > 1000) {
85             msg_print(_("エラー:隼の剣に割り当てるエゴ無し", "Error: Cannot find for Hayabusa."));
86             return;
87         }
88
89         continue;
90     }
91 }