OSDN Git Service

[Refactor] #3496 optional 型の存在判定 has_value() を撤廃した その4
[hengbandforosx/hengbandosx.git] / src / object-enchant / others / apply-magic-lite.cpp
1 #include "object-enchant/others/apply-magic-lite.h"
2 #include "artifact/random-art-generator.h"
3 #include "inventory/inventory-slot-types.h"
4 #include "object-enchant/object-ego.h"
5 #include "sv-definition/sv-lite-types.h"
6 #include "system/item-entity.h"
7 #include "system/player-type-definition.h"
8
9 LiteEnchanter::LiteEnchanter(PlayerType *player_ptr, ItemEntity *o_ptr, int power)
10     : player_ptr(player_ptr)
11     , o_ptr(o_ptr)
12     , power(power)
13 {
14     const auto sval = this->o_ptr->bi_key.sval();
15     if (!sval) {
16         return;
17     }
18
19     switch (sval.value()) {
20     case SV_LITE_TORCH:
21         o_ptr->fuel = randint1(FUEL_TORCH / 2);
22         return;
23     case SV_LITE_LANTERN:
24         o_ptr->fuel = randint1(FUEL_LAMP / 2);
25         return;
26     default:
27         return;
28     }
29 }
30
31 void LiteEnchanter::apply_magic()
32 {
33     if (this->power > 2) {
34         become_random_artifact(this->player_ptr, this->o_ptr, false);
35         return;
36     }
37
38     if ((this->power == 2) || ((this->power == 1) && one_in_(3))) {
39         while (!this->o_ptr->is_ego()) {
40             this->give_ego_index();
41         }
42
43         return;
44     }
45
46     if (this->power == -2) {
47         this->give_cursed();
48     }
49 }
50
51 void LiteEnchanter::give_ego_index()
52 {
53     while (true) {
54         auto okay_flag = true;
55         this->o_ptr->ego_idx = get_random_ego(INVEN_LITE, true);
56         switch (this->o_ptr->ego_idx) {
57         case EgoType::LITE_LONG:
58             if (this->o_ptr->bi_key.sval() == SV_LITE_FEANOR) {
59                 okay_flag = false;
60             }
61
62             break;
63         default:
64             break;
65         }
66
67         if (okay_flag) {
68             return;
69         }
70     }
71 }
72
73 void LiteEnchanter::give_cursed()
74 {
75     this->o_ptr->ego_idx = get_random_ego(INVEN_LITE, false);
76     switch (this->o_ptr->ego_idx) {
77     case EgoType::LITE_DARKNESS:
78         this->o_ptr->fuel = 0;
79         this->add_dark_flag();
80         return;
81     default:
82         return;
83     }
84 }
85
86 void LiteEnchanter::add_dark_flag()
87 {
88     const auto sval = this->o_ptr->bi_key.sval();
89     if (!sval) {
90         return;
91     }
92
93     switch (sval.value()) {
94     case SV_LITE_TORCH:
95         this->o_ptr->art_flags.set(TR_LITE_M1);
96         return;
97     case SV_LITE_LANTERN:
98         this->o_ptr->art_flags.set(TR_LITE_M2);
99         return;
100     case SV_LITE_FEANOR:
101         this->o_ptr->art_flags.set(TR_LITE_M3);
102         return;
103     default:
104         return;
105     }
106 }