forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
relic.h
151 lines (124 loc) · 4.2 KB
/
relic.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#pragma once
#ifndef CATA_SRC_RELIC_H
#define CATA_SRC_RELIC_H
#include <string>
#include <vector>
#include "json_source_location.h"
#include "magic.h"
#include "magic_enchantment.h"
#include "translations.h"
class Creature;
class JsonIn;
class JsonObject;
class JsonOut;
struct tripoint;
enum class relic_recharge_type {
/** Recharges slowly with time */
time,
/** Recharges in sunlight */
solar,
/** Creates pain to recharge */
pain,
/** Drains HP to recharge */
hp,
/** Creates fatigue to recharge */
fatigue,
/** Consumes field to recharge */
field,
/** Consumes trap to recharge */
trap,
num
};
enum class relic_recharge_req {
/** No additional requirements */
none,
/** Must be worn/wielded */
equipped,
/**
* Must be worn on closest layer on at least 1 body part if armor, or
* must be wielding with nothing worn on left and/or right hand.
*/
close_to_skin,
/** Will recharge only when character is asleep */
sleep,
/** Must be irradiated/in irradiated tile */
rad,
/** Must be wet or in rain */
wet,
/** Must be a Z-level above the surface */
sky,
num
};
template<>
struct enum_traits<relic_recharge_type> {
static constexpr relic_recharge_type last = relic_recharge_type::num;
};
template<>
struct enum_traits<relic_recharge_req> {
static constexpr relic_recharge_req last = relic_recharge_req::num;
};
class relic_recharge
{
json_source_location src_loc;
public:
/** Relic recharge type */
relic_recharge_type type = relic_recharge_type::time;
/** Relic recharge requirements */
relic_recharge_req req = relic_recharge_req::none;
/** If relic consumes fields to recharge, this specifies field type */
field_type_str_id field_type;
/** If relic consumes traps to recharge, this specifies trap type */
trap_str_id trap_type;
/** For time-based recharge, specifies recharge interval */
time_duration interval = 1_seconds;
/** For intensity-based recharge types, specifies min intensity */
int intensity_min = 0;
/** For intensity-based recharge types, specifies max intensity */
int intensity_max = 0;
/** Specifies amount of charges gained per charge operation. Can be 0 or even negative. */
int rate = 0;
/** Recharge activation message. */
std::optional<std::string> message;
bool operator==( const relic_recharge &rhs ) const;
void load( const JsonObject &jo );
void serialize( JsonOut &json ) const;
void deserialize( JsonIn &jsin );
void check() const;
};
class relic
{
private:
std::vector<fake_spell> active_effects;
std::vector<enchantment> passive_effects;
std::vector<relic_recharge> recharge_scheme;
// the item's name will be replaced with this if the string is not empty
translation item_name_override;
int charges_per_activation;
// activating an artifact overrides all spell casting costs
int moves;
public:
bool operator==( const relic &rhs ) const;
std::string name() const;
// returns number of charges that should be consumed
int activate( Creature &caster, const tripoint &target ) const;
void load( const JsonObject &jo );
void serialize( JsonOut &jsout ) const;
void deserialize( JsonIn &jsin );
void add_passive_effect( const enchantment &ench );
void add_active_effect( const fake_spell &sp );
void add_recharge_scheme( const relic_recharge &r );
inline const std::vector<enchantment> &get_enchantments() const {
return passive_effects;
}
inline const std::vector<relic_recharge> &get_recharge_scheme() const {
return recharge_scheme;
}
void check() const;
};
namespace relic_funcs
{
bool check_recharge_reqs( const item &itm, const relic_recharge &rech, const Character &carrier );
bool process_recharge_entry( item &itm, const relic_recharge &rech, Character &carrier );
void process_recharge( item &itm, Character &carrier );
} // namespace relic_funcs
#endif // CATA_SRC_RELIC_H