-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathMagicRegistry.cpp
More file actions
239 lines (196 loc) · 7.88 KB
/
Copy pathMagicRegistry.cpp
File metadata and controls
239 lines (196 loc) · 7.88 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/**
* Alicia Server - dedicated server software
* Copyright (C) 2024 Story Of Alicia
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
**/
#include "libserver/registry/MagicRegistry.hpp"
#include <spdlog/spdlog.h>
#include <yaml-cpp/yaml.h>
#include <stdexcept>
namespace server::registry
{
namespace
{
uint32_t ReadSlotInfo(const YAML::Node& section, Magic::SlotInfo& slot)
{
slot.type = section["type"].as<uint32_t>();
slot.basicType = section["basicType"].as<uint32_t>();
slot.criticalType = section["criticalType"].as<uint32_t>();
slot.skillEffectId = section["skillEffectId"].as<uint32_t>();
slot.attackValue = section["attackValue"].as<uint32_t>();
slot.defenseValue = section["defenseValue"].as<uint32_t>();
slot.castingTime = section["castingTime"].as<float>();
slot.effectDelay = section["effectDelay"].as<float>();
slot.effectDisappearDelay = section["effectDisappearDelay"].as<float>();
slot.targetingDelay = section["targetingDelay"].as<float>();
slot.getStartDelay = section["getStartDelay"].as<float>();
slot.targetingType = section["targetingType"].as<uint32_t>();
slot.needTargeting = section["needTargeting"].as<uint32_t>();
slot.noneTargetable = section["noneTargetable"].as<uint32_t>();
slot.noneSummonStick = section["noneSummonStick"].as<uint32_t>();
slot.causeAttackRelease = section["causeAttackRelease"].as<uint32_t>();
slot.adjustMotionSpeed = section["adjustMotionSpeed"].as<uint32_t>();
slot.teamKill = section["teamKill"].as<uint32_t>();
slot.teamMode = section["teamMode"].as<uint32_t>();
slot.slidingReduce = section["slidingReduce"].as<uint32_t>();
slot.reflectable = section["reflectable"].as<uint32_t>();
slot.removeMagic = section["removeMagic"].as<uint32_t>();
slot.removeHotRodding = section["removeHotRodding"].as<uint32_t>();
slot.removeSummonTarget = section["removeSummonTarget"].as<uint32_t>();
slot.replaceEffect = section["replaceEffect"].as<uint32_t>();
slot.massEffect = section["massEffect"].as<uint32_t>();
slot.affectByCriticalAura = section["affectByCriticalAura"].as<uint32_t>();
slot.criticalByDarkFire = section["criticalByDarkFire"].as<uint32_t>();
slot.attackRank = section["attackRank"].as<uint32_t>(0);
// Crit items do not need the positional weights defined, base items carry that info
if (slot.type == slot.basicType)
slot.positionalWeights = section["positionalWeights"].as<std::array<uint32_t, 8>>();
return slot.type;
}
} // anonymous namespace
void MagicRegistry::ReadConfig(const std::filesystem::path& configPath)
{
const auto root = YAML::LoadFile(configPath.string());
const auto magicSection = root["magic"];
if (not magicSection)
throw std::runtime_error("Missing magic section");
// Slot info
{
const auto slotSection = magicSection["slotInfo"];
if (not slotSection)
throw std::runtime_error("Missing magic slotInfo section");
const auto collection = slotSection["collection"];
if (not collection)
throw std::runtime_error("Missing magic slotInfo collection");
for (const auto& entry : collection)
{
Magic::SlotInfo slot;
const auto type = ReadSlotInfo(entry, slot);
_slotInfo.emplace(type, std::move(slot));
}
}
// Pre-build the pick pools and positional weights so RandomMagicItem never has to filter at runtime.
for (const auto& [type, slot] : _slotInfo)
{
if (slot.basicType != type)
continue; // skip critical variants
_teamPool.push_back(type);
if (slot.teamMode == 0)
_soloPool.push_back(type);
// Only compile weights from base type
if (slot.type != slot.basicType)
continue;
for (size_t i = 0; i < slot.positionalWeights.size(); ++i)
{
const auto& pair = std::make_pair(
slot.positionalWeights[i],
slot);
// Add to team magic item weights since team is a superset of solo
_teamPositionWeights[i].emplace_back(pair);
// Do not add to solo position weights if team item
if (slot.teamMode != 0)
continue;
_soloPositionWeights[i].emplace_back(pair);
}
}
if (const auto regenSection = magicSection["regen"])
{
_regenInfo.pointPerTick = regenSection["pointPerTick"].as<uint32_t>(_regenInfo.pointPerTick);
_regenInfo.intervalMs = regenSection["intervalMs"].as<uint32_t>(_regenInfo.intervalMs);
_regenInfo.courageScaleBp = regenSection["courageScaleBp"].as<uint32_t>(_regenInfo.courageScaleBp);
}
_baseCritChanceBp = magicSection["critChanceBp"].as<uint32_t>(_baseCritChanceBp);
if (const auto scalingsSection = magicSection["statScalings"])
{
for (const auto& entry : scalingsSection)
{
const auto basicType = entry["basicType"].as<uint32_t>();
const auto statName = entry["stat"].as<std::string>();
Magic::StatScaling scaling{};
if (statName == "agility")
scaling.stat = Magic::MountStat::Agility;
else if (statName == "ambition")
scaling.stat = Magic::MountStat::Ambition;
else if (statName == "rush")
scaling.stat = Magic::MountStat::Rush;
else if (statName == "endurance")
scaling.stat = Magic::MountStat::Endurance;
else if (statName == "courage")
scaling.stat = Magic::MountStat::Courage;
else
throw std::runtime_error("Unknown stat in statScalings: " + statName);
scaling.durationScaleBp = entry["durationScaleBp"].as<uint32_t>(0);
scaling.critStepBp = entry["critStepBp"].as<uint32_t>(0);
scaling.targetDurationReductionBp = entry["targetDurationReductionBp"].as<uint32_t>(0);
_statScalings.emplace(basicType, scaling);
}
}
spdlog::info(
"Magic registry loaded {} slot(s) ({} solo, {} team)",
_slotInfo.size(),
_soloPool.size(),
_teamPool.size());
}
const Magic::SlotInfo& MagicRegistry::GetSlotInfo(uint32_t type) const
{
const auto it = _slotInfo.find(type);
if (it == _slotInfo.end())
throw std::runtime_error("Magic slot not found: " + std::to_string(type));
return it->second;
}
const Magic::SlotInfo& MagicRegistry::GetSlotInfoByEffectId(uint32_t effectId) const
{
for (const auto& [type, slot] : _slotInfo)
{
if (slot.skillEffectId == effectId)
return slot;
}
throw std::runtime_error("Magic slot not found for effect ID: " + std::to_string(effectId));
}
const std::unordered_map<uint32_t, Magic::SlotInfo>& MagicRegistry::GetSlotInfoMap() const
{
return _slotInfo;
}
const std::vector<uint32_t>& MagicRegistry::GetSoloPool() const
{
return _soloPool;
}
const std::vector<uint32_t>& MagicRegistry::GetTeamPool() const
{
return _teamPool;
}
const Magic::RegenInfo& MagicRegistry::GetRegenInfo() const
{
return _regenInfo;
}
uint32_t MagicRegistry::GetBaseCritChanceBp() const
{
return _baseCritChanceBp;
}
const Magic::StatScaling* MagicRegistry::GetStatScaling(uint32_t basicType) const
{
const auto it = _statScalings.find(basicType);
return it == _statScalings.cend() ? nullptr : &it->second;
}
const std::vector<std::pair<Magic::SlotWeight, Magic::SlotInfo>>& MagicRegistry::GetSoloPositionWeights(uint32_t position) const
{
return _soloPositionWeights.at(position);
}
const std::vector<std::pair<Magic::SlotWeight, Magic::SlotInfo>>& MagicRegistry::GetTeamPositionWeights(uint32_t position) const
{
return _teamPositionWeights.at(position);
}
} // namespace server::registry