forked from dgcor/DGEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpell.h
More file actions
executable file
·170 lines (135 loc) · 6.47 KB
/
Copy pathSpell.h
File metadata and controls
executable file
·170 lines (135 loc) · 6.47 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#pragma once
#include "Actions/Action.h"
#include "Classifiers.h"
#include "Formulas.h"
#include "LevelObjectClass.h"
#include "Queryable.h"
#include "Save/SaveItem.h"
#include <string>
#include "TexturePacks/TexturePack.h"
#include "Utils/FixedMap.h"
#include "Utils/Utils.h"
class Spell : public LevelObjectClass, public Queryable
{
private:
typedef FixedMap<uint16_t, LevelObjValue, 6> SpellProperties;
std::string name;
std::string spellType;
SpellProperties properties;
std::shared_ptr<TexturePack> texturePack1;
std::shared_ptr<TexturePack> texturePack2;
uint32_t textureIdx1;
uint32_t textureIdx2;
Formulas<std::array<Formula, 6>> formulas;
FixedMap<uint16_t, Formula, 4> customFormulas;
static constexpr size_t LifeFormula = 0;
static constexpr size_t ManaFormula = 1;
static constexpr size_t DamageFormula = 2;
static constexpr size_t DurationFormula = 3;
static constexpr size_t SpeedFormula = 4;
mutable std::array<std::string, 5> descriptions;
mutable bool updateDescr{ true };
Classifiers<5> descriptionClassifiers;
bool getDescription(size_t idx, const Queryable& obj, std::string& description) const;
void updateDescriptions(const Queryable& spellObj) const;
bool evalFormula(uint16_t nameHash, const Queryable& objA,
const Queryable& objB, LevelObjValue& val,
const std::string_view minMaxNumber = {}) const;
public:
using iterator = SpellProperties::iterator;
using const_iterator = SpellProperties::const_iterator;
using reverse_iterator = SpellProperties::reverse_iterator;
using const_reverse_iterator = SpellProperties::const_reverse_iterator;
iterator begin() noexcept { return properties.begin(); }
iterator end() noexcept { return properties.end(); }
const_iterator begin() const noexcept { return properties.begin(); }
const_iterator end() const noexcept { return properties.end(); }
const_iterator cbegin() const noexcept { return properties.cbegin(); }
const_iterator cend() const noexcept { return properties.cend(); }
reverse_iterator rbegin() noexcept { return properties.rbegin(); }
reverse_iterator rend() noexcept { return properties.rend(); }
const_reverse_iterator rbegin() const noexcept { return properties.rbegin(); }
const_reverse_iterator rend() const noexcept { return properties.rend(); }
const_reverse_iterator crbegin() const noexcept { return properties.crbegin(); }
const_reverse_iterator crend() const noexcept { return properties.crend(); }
Spell(const std::shared_ptr<TexturePack>& texturePack1_,
const std::shared_ptr<TexturePack>& texturePack2_,
uint32_t textureIdx1_, uint32_t textureIdx2_) : texturePack1(texturePack1_),
texturePack2(texturePack2_), textureIdx1(textureIdx1_), textureIdx2(textureIdx2_) {}
bool getNumberPropByHash(const Queryable& spell, const Queryable& player,
uint16_t propHash, const std::string_view minMaxNumber, LevelObjValue& value) const;
bool getNumberPropByHash(const Queryable& player,
uint16_t propHash, LevelObjValue& value) const;
bool getNumberPropByHash(const Queryable& player, uint16_t propHash,
const std::string_view minMaxNumber, LevelObjValue& value) const;
bool getNumberProp(const std::string_view prop, Number32& value) const override;
bool getProperty(const Queryable& spell, const Queryable& player,
uint16_t propHash, const std::string_view prop, Variable& var) const;
bool getProperty(const std::string_view prop, Variable& var) const override;
bool getTexture(uint32_t textureNumber, TextureInfo& ti) const override;
void setTexturePack1(const std::shared_ptr<TexturePack>& texturePack_) noexcept
{
texturePack1 = texturePack_;
}
void setTexturePack2(const std::shared_ptr<TexturePack>& texturePack_) noexcept
{
texturePack2 = texturePack_;
}
void setTextureIndex1(uint32_t idx_) noexcept { textureIdx1 = idx_; }
void setTextureIndex2(uint32_t idx_) noexcept { textureIdx2 = idx_; }
bool getTexture1(TextureInfo& ti) const
{
return texturePack1->get(textureIdx1, ti);
}
bool getTexture2(TextureInfo& ti) const
{
return texturePack2->get(textureIdx2, ti);
}
bool hasIntByHash(uint16_t propHash) const noexcept;
bool hasInt(const std::string_view prop) const noexcept;
LevelObjValue getIntByHash(uint16_t propHash) const;
LevelObjValue getInt(const std::string_view prop) const;
bool getIntByHash(uint16_t propHash, LevelObjValue& value) const;
bool getInt(const std::string_view prop, LevelObjValue& value) const;
void setIntByHash(uint16_t propHash, LevelObjValue value);
void setInt(const std::string_view prop, LevelObjValue value);
const std::string& Name() const noexcept { return name; }
const std::string& SpellType() const noexcept { return spellType; }
void Name(const std::string name_) { name = name_; }
void SpellType(const std::string type_)
{
spellType = type_;
}
void setDescription(size_t idx, Classifier* classifier, uint16_t skipFirst);
// if formula is empty, it clears the current formula.
void setFormula(uint16_t nameHash, const std::string_view formula);
LevelObjValue getLife(const Queryable& spell,
const Queryable& player, const std::string_view minMaxNumber = {}) const;
LevelObjValue getMana(const Queryable& spell,
const Queryable& player, const std::string_view minMaxNumber = {}) const;
LevelObjValue getDamage(const Queryable& spell,
const Queryable& player, const std::string_view minMaxNumber = {}) const;
LevelObjValue getDuration(const Queryable& spell,
const Queryable& player, const std::string_view minMaxNumber = {}) const;
LevelObjValue getSpeed(const Queryable& spell,
const Queryable& player, const std::string_view minMaxNumber = {}) const;
};
struct SpellInstance : public Queryable
{
Spell* spell{ nullptr };
const Queryable* spellOwner{ nullptr };
LevelObjValue spellLevel{ 0 };
SpellInstance() {}
SpellInstance(Spell* spell_, const Queryable* spellOwner_, LevelObjValue spellLevel_) :
spell(spell_), spellOwner(spellOwner_), spellLevel(spellLevel_) {}
bool getNumberPropByHash(uint16_t propHash, LevelObjValue& value) const;
bool getNumberPropByHash(const Queryable& player,
uint16_t propHash, LevelObjValue& value) const;
bool getNumberPropByHash(uint16_t propHash,
const std::string_view minMaxNumber, LevelObjValue& value) const;
bool getNumberPropByHash(const Queryable& player, uint16_t propHash,
const std::string_view minMaxNumber, LevelObjValue& value) const;
bool getNumberProp(const std::string_view prop, Number32& value) const override;
bool getProperty(const std::string_view prop, Variable& var) const override;
bool getTexture(uint32_t textureNumber, TextureInfo& ti) const override;
};