Horizon Official Technical Documentation
Horizon::Zone::ItemDatabase Class Reference

#include <ItemDB.hpp>

+ Collaboration diagram for Horizon::Zone::ItemDatabase:

Classes

struct  refine_config
 

Public Member Functions

 ItemDatabase ()
 
 ~ItemDatabase ()
 
bool load ()
 
bool load_refine_db ()
 
bool load_weapon_target_size_modifiers_db ()
 
bool load_weapon_attribute_modifiers_db ()
 
bool add_job_group_to_item (std::string const &group, item_config_data &id, bool enable, std::string const &file_path)
 
std::shared_ptr< const item_config_dataget_item_by_id (uint32_t item_id) const
 
std::shared_ptr< const item_config_dataget_item_by_key_name (std::string key_name) const
 
std::shared_ptr< const refine_configget_refine_config (refine_type type)
 
uint8_t get_weapon_target_size_modifier (item_weapon_type wtype, unit_size_type stype)
 
int32_t get_weapon_attribute_modifier (int32_t weapon_lv, element_type element, element_type def_ele)
 
std::string get_weapon_type_name (item_weapon_type type)
 

Static Public Member Functions

static ItemDatabaseget_instance ()
 

Private Member Functions

int load_items (sol::table const &item_tbl, std::string file_path)
 
bool load_refine_table (refine_type tbl_type, sol::table const &refine_table, std::string table_name, std::string file_path)
 

Private Attributes

std::array< std::string, IT_WT_SINGLE_MAX_weapontype2name_db
 
LockedLookupTable< int32_t, std::shared_ptr< const item_config_data > > _item_db
 
LockedLookupTable< std::string, std::shared_ptr< const item_config_data > > _item_db_str
 
LockedLookupTable< int32_t, std::shared_ptr< const refine_config > > _refine_db
 
LockedLookupTable< int32_t, std::shared_ptr< std::array< uint8_t, ESZ_MAX > > > _weapon_target_size_modifiers_db
 
LockedLookupTable< int32_t, std::shared_ptr< std::array< std::array< uint8_t, ELE_MAX >, ELE_MAX > > > _weapon_attribute_modifiers_db
 

Constructor & Destructor Documentation

◆ ItemDatabase()

ItemDatabase::ItemDatabase ( )
41{
44 _weapontype2name_db[IT_WT_1HSWORD] = "OneHandedSword";
45 _weapontype2name_db[IT_WT_2HSWORD] = "TwoHandedSword";
46 _weapontype2name_db[IT_WT_1HSPEAR] = "OneHandedSpear";
47 _weapontype2name_db[IT_WT_2HSPEAR] = "TwoHandedSpear";
48 _weapontype2name_db[IT_WT_1HAXE] = "OneHandedAxe";
49 _weapontype2name_db[IT_WT_2HAXE] = "TwoHandedAxe";
50 _weapontype2name_db[IT_WT_1HMACE] = "OneHandedMace";
51 _weapontype2name_db[IT_WT_2HMACE] = "TwoHandedMace";
52 _weapontype2name_db[IT_WT_STAFF] = "OneHandedStaff";
55 _weapontype2name_db[IT_WT_MUSICAL] = "MusicalInstrument";
61 _weapontype2name_db[IT_WT_GATLING] = "GatlingGun";
63 _weapontype2name_db[IT_WT_GRENADE] = "GrenadeLauncher";
64 _weapontype2name_db[IT_WT_HUUMA] = "FuumaShuriken";
65 _weapontype2name_db[IT_WT_2HSTAFF] = "TwoHandedStaff";
66}
@ IT_WT_FIST
Bare hands.
Definition: ItemDefinitions.hpp:100
@ IT_WT_1HSWORD
Definition: ItemDefinitions.hpp:102
@ IT_WT_KATAR
Definition: ItemDefinitions.hpp:116
@ IT_WT_2HSPEAR
Definition: ItemDefinitions.hpp:105
@ IT_WT_2HMACE
Definition: ItemDefinitions.hpp:109
@ IT_WT_GATLING
Definition: ItemDefinitions.hpp:119
@ IT_WT_GRENADE
Definition: ItemDefinitions.hpp:121
@ IT_WT_RIFLE
Definition: ItemDefinitions.hpp:118
@ IT_WT_2HAXE
Definition: ItemDefinitions.hpp:107
@ IT_WT_BOW
Definition: ItemDefinitions.hpp:111
@ IT_WT_2HSTAFF
Definition: ItemDefinitions.hpp:123
@ IT_WT_SHOTGUN
Definition: ItemDefinitions.hpp:120
@ IT_WT_HUUMA
Definition: ItemDefinitions.hpp:122
@ IT_WT_1HSPEAR
Definition: ItemDefinitions.hpp:104
@ IT_WT_BOOK
Definition: ItemDefinitions.hpp:115
@ IT_WT_WHIP
Definition: ItemDefinitions.hpp:114
@ IT_WT_MUSICAL
Definition: ItemDefinitions.hpp:113
@ IT_WT_STAFF
Definition: ItemDefinitions.hpp:110
@ IT_WT_KNUCKLE
Definition: ItemDefinitions.hpp:112
@ IT_WT_2HSWORD
Definition: ItemDefinitions.hpp:103
@ IT_WT_1HAXE
Definition: ItemDefinitions.hpp:106
@ IT_WT_1HMACE
Definition: ItemDefinitions.hpp:108
@ IT_WT_DAGGER
Definition: ItemDefinitions.hpp:101
@ IT_WT_REVOLVER
Definition: ItemDefinitions.hpp:117
std::array< std::string, IT_WT_SINGLE_MAX > _weapontype2name_db
Definition: ItemDB.hpp:109
LockedLookupTable< int32_t, std::shared_ptr< std::array< uint8_t, ESZ_MAX > > > _weapon_target_size_modifiers_db
Definition: ItemDB.hpp:113
LockedLookupTable< int32_t, std::shared_ptr< const item_config_data > > _item_db
Definition: ItemDB.hpp:110

References _weapontype2name_db, IT_WT_1HAXE, IT_WT_1HMACE, IT_WT_1HSPEAR, IT_WT_1HSWORD, IT_WT_2HAXE, IT_WT_2HMACE, IT_WT_2HSPEAR, IT_WT_2HSTAFF, IT_WT_2HSWORD, IT_WT_BOOK, IT_WT_BOW, IT_WT_DAGGER, IT_WT_FIST, IT_WT_GATLING, IT_WT_GRENADE, IT_WT_HUUMA, IT_WT_KATAR, IT_WT_KNUCKLE, IT_WT_MUSICAL, IT_WT_REVOLVER, IT_WT_RIFLE, IT_WT_SHOTGUN, IT_WT_STAFF, and IT_WT_WHIP.

◆ ~ItemDatabase()

Horizon::Zone::ItemDatabase::~ItemDatabase ( )
inline
51{ }

Member Function Documentation

◆ add_job_group_to_item()

bool ItemDatabase::add_job_group_to_item ( std::string const &  group,
item_config_data id,
bool  enable,
std::string const &  file_path 
)
105{
106 if (group.compare("All") == 0) {
107 id.requirements.job_ids.push_back(0);
108 for (int i = JOB_BASE_START; i < JOB_BASE_END; i++) {
109 if (enable)
110 id.requirements.job_ids.push_back(i);
111 else
112 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
113 }
114 for (int i = JOB_2_1_START; i < JOB_2_1_END; i++) {
115 if (enable)
116 id.requirements.job_ids.push_back(i);
117 else
118 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
119 }
120 for (int i = JOB_2_2_START; i < JOB_2_2_END; i++) {
121 if (enable)
122 id.requirements.job_ids.push_back(i);
123 else
124 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
125 }
126 for (int i = JOB_TRANS_BASE_START; i < JOB_TRANS_BASE_END; i++) {
127 if (enable)
128 id.requirements.job_ids.push_back(i);
129 else
130 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
131 }
132 for (int i = JOB_TRANS_2_1_START; i < JOB_TRANS_2_1_END; i++) {
133 if (enable)
134 id.requirements.job_ids.push_back(i);
135 else
136 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
137 }
138 // generate code for the rest of the job groups
139 for (int i = JOB_TRANS_2_2_START; i < JOB_TRANS_2_2_END; i++) {
140 if (enable)
141 id.requirements.job_ids.push_back(i);
142 else
143 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
144 }
145
146 for (int i = JOB_BABY_BASE_START; i < JOB_BABY_BASE_END; i++) {
147 if (enable)
148 id.requirements.job_ids.push_back(i);
149 else
150 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
151 }
152 for (int i = JOB_BABY_2_1_START; i < JOB_BABY_2_1_END; i++) {
153 if (enable)
154 id.requirements.job_ids.push_back(i);
155 else
156 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
157 }
158 for (int i = JOB_3_1_START; i < JOB_3_1_END; i++) {
159 if (enable)
160 id.requirements.job_ids.push_back(i);
161 else
162 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
163 }
164 for (int i = JOB_3_2_START; i < JOB_3_2_END; i++) {
165 if (enable)
166 id.requirements.job_ids.push_back(i);
167 else
168 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
169 }
170 for (int i = JOB_TRANS_3_1_START; i < JOB_TRANS_3_1_END; i++) {
171 if (enable)
172 id.requirements.job_ids.push_back(i);
173 else
174 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
175 }
176 for (int i = JOB_TRANS_3_2_START; i < JOB_TRANS_3_2_END; i++) {
177 if (enable)
178 id.requirements.job_ids.push_back(i);
179 else
180 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
181 }
182 for (int i = JOB_BABY_3_1_START; i < JOB_BABY_3_1_END; i++) {
183 if (enable)
184 id.requirements.job_ids.push_back(i);
185 else
186 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
187 }
188 for (int i = JOB_BABY_3_2_START; i < JOB_BABY_3_2_END; i++) {
189 if (enable)
190 id.requirements.job_ids.push_back(i);
191 else
192 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
193 }
194 return true;
195 } else if (group.compare("NormalJobs") == 0) {
196 for (int i = JOB_BASE_START; i < JOB_BASE_END; i++) {
197 if (enable)
198 id.requirements.job_ids.push_back(i);
199 else
200 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
201 }
202 for (int i = JOB_2_1_START; i < JOB_2_1_END; i++) {
203 if (enable)
204 id.requirements.job_ids.push_back(i);
205 else
206 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
207 }
208 for (int i = JOB_2_2_START; i < JOB_2_2_END; i++) {
209 if (enable)
210 id.requirements.job_ids.push_back(i);
211 else
212 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
213 }
214 } else if (group.compare("NormalBabyJobs") == 0) {
215 for (int i = JOB_BABY_BASE_START; i < JOB_BABY_BASE_END; i++) {
216 if (enable)
217 id.requirements.job_ids.push_back(i);
218 else
219 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
220 }
221 for (int i = JOB_BABY_2_1_START; i < JOB_BABY_2_1_END; i++) {
222 if (enable)
223 id.requirements.job_ids.push_back(i);
224 else
225 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
226 }
227 for (int i = JOB_BABY_2_2_START; i < JOB_BABY_2_2_END; i++) {
228 if (enable)
229 id.requirements.job_ids.push_back(i);
230 else
231 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
232 }
233 } else if (group.compare("TransJobs") == 0) {
234 for (int i = JOB_TRANS_BASE_START; i < JOB_TRANS_BASE_END; i++) {
235 if (enable)
236 id.requirements.job_ids.push_back(i);
237 else
238 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
239 }
240 for (int i = JOB_TRANS_2_1_START; i < JOB_TRANS_2_1_END; i++) {
241 if (enable)
242 id.requirements.job_ids.push_back(i);
243 else
244 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
245 }
246 for (int i = JOB_TRANS_2_2_START; i < JOB_TRANS_2_2_END; i++) {
247 if (enable)
248 id.requirements.job_ids.push_back(i);
249 else
250 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
251 }
252 } else if (group.compare("ThirdJobs") == 0) {
253 for (int i = JOB_3_1_START; i < JOB_3_1_END; i++) {
254 if (enable)
255 id.requirements.job_ids.push_back(i);
256 else
257 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
258 }
259 for (int i = JOB_3_2_START; i < JOB_3_2_END; i++) {
260 if (enable)
261 id.requirements.job_ids.push_back(i);
262 else
263 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
264 }
265 } else if (group.compare("ThirdTransJobs") == 0) {
266 for (int i = JOB_TRANS_3_1_START; i < JOB_TRANS_3_1_END; i++) {
267 if (enable)
268 id.requirements.job_ids.push_back(i);
269 else
270 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
271 }
272 for (int i = JOB_TRANS_3_2_START; i < JOB_TRANS_3_2_END; i++) {
273 if (enable)
274 id.requirements.job_ids.push_back(i);
275 else
276 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
277 }
278 } else if (group.compare("ThirdBabyJobs") == 0) {
279 for (int i = JOB_BABY_3_1_START; i < JOB_BABY_3_1_END; i++) {
280 if (enable)
281 id.requirements.job_ids.push_back(i);
282 else
283 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
284 }
285 for (int i = JOB_BABY_3_2_START; i < JOB_BABY_3_2_END; i++) {
286 if (enable)
287 id.requirements.job_ids.push_back(i);
288 else
289 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [i] (uint32_t id) { return i == id; });
290 }
291 } else if (group.compare("ExtendedJobs") == 0) {
292 if (enable) {
293 id.requirements.job_ids.push_back(JOB_SUPER_NOVICE);
294 id.requirements.job_ids.push_back(JOB_GUNSLINGER);
295 id.requirements.job_ids.push_back(JOB_NINJA);
296 id.requirements.job_ids.push_back(JOB_TAEKWON);
297 id.requirements.job_ids.push_back(JOB_STAR_GLADIATOR);
298 id.requirements.job_ids.push_back(JOB_STAR_GLADIATOR2);
299 id.requirements.job_ids.push_back(JOB_SOUL_LINKER);
300 id.requirements.job_ids.push_back(JOB_GANGSI);
301 id.requirements.job_ids.push_back(JOB_DEATH_KNIGHT);
302 id.requirements.job_ids.push_back(JOB_DARK_COLLECTOR);
303 id.requirements.job_ids.push_back(JOB_SUPER_NOVICE_E);
304 id.requirements.job_ids.push_back(JOB_SUPER_BABY_E);
305 id.requirements.job_ids.push_back(JOB_KAGEROU);
306 id.requirements.job_ids.push_back(JOB_OBORO);
307 id.requirements.job_ids.push_back(JOB_REBELLION);
308 } else {
309 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [] (uint32_t id)
310 {
311 if (id == JOB_SUPER_NOVICE)
312 return true;
313 if (id == JOB_GUNSLINGER)
314 return true;
315 if (id == JOB_NINJA)
316 return true;
317 if (id == JOB_TAEKWON)
318 return true;
319 if (id == JOB_STAR_GLADIATOR)
320 return true;
321 if (id == JOB_STAR_GLADIATOR2)
322 return true;
323 if (id == JOB_SOUL_LINKER)
324 return true;
325 if (id == JOB_GANGSI)
326 return true;
327 if (id == JOB_DEATH_KNIGHT)
328 return true;
329 if (id == JOB_DARK_COLLECTOR)
330 return true;
331 if (id == JOB_SUPER_NOVICE_E)
332 return true;
333 if (id == JOB_SUPER_BABY_E)
334 return true;
335 if (id == JOB_KAGEROU)
336 return true;
337 if (id == JOB_OBORO)
338 return true;
339 if (id == JOB_REBELLION)
340 return true;
341
342 return false;
343 });
344 }
345 } else {
346 HLog(error) << "Invalid Job Range '" << group << "' specified for entry in file '" << file_path << "', skipping...";
347 return false;
348 }
349
350 return true;
351}
#define HLog(type)
Definition: Logger.hpp:122
@ JOB_BABY_2_2_END
Definition: UnitDefinitions.hpp:634
@ JOB_TRANS_2_1_END
Definition: UnitDefinitions.hpp:626
@ JOB_BASE_END
Definition: UnitDefinitions.hpp:618
@ JOB_3_1_END
Definition: UnitDefinitions.hpp:636
@ JOB_3_1_START
Definition: UnitDefinitions.hpp:635
@ JOB_REBELLION
Definition: UnitDefinitions.hpp:613
@ JOB_2_2_END
Definition: UnitDefinitions.hpp:622
@ JOB_TRANS_3_2_START
Definition: UnitDefinitions.hpp:641
@ JOB_BABY_BASE_END
Definition: UnitDefinitions.hpp:630
@ JOB_DEATH_KNIGHT
Definition: UnitDefinitions.hpp:554
@ JOB_BABY_3_2_END
Definition: UnitDefinitions.hpp:646
@ JOB_TRANS_2_2_START
Definition: UnitDefinitions.hpp:627
@ JOB_DARK_COLLECTOR
Definition: UnitDefinitions.hpp:555
@ JOB_TRANS_2_2_END
Definition: UnitDefinitions.hpp:628
@ JOB_TRANS_3_2_END
Definition: UnitDefinitions.hpp:642
@ JOB_2_1_END
Definition: UnitDefinitions.hpp:620
@ JOB_TRANS_3_1_END
Definition: UnitDefinitions.hpp:640
@ JOB_2_2_START
Definition: UnitDefinitions.hpp:621
@ JOB_SUPER_NOVICE_E
Definition: UnitDefinitions.hpp:609
@ JOB_OBORO
Definition: UnitDefinitions.hpp:612
@ JOB_BABY_BASE_START
Definition: UnitDefinitions.hpp:629
@ JOB_TRANS_BASE_START
Definition: UnitDefinitions.hpp:623
@ JOB_SUPER_BABY_E
Definition: UnitDefinitions.hpp:610
@ JOB_BABY_2_1_START
Definition: UnitDefinitions.hpp:631
@ JOB_NINJA
Definition: UnitDefinitions.hpp:500
@ JOB_GANGSI
Definition: UnitDefinitions.hpp:553
@ JOB_KAGEROU
Definition: UnitDefinitions.hpp:611
@ JOB_3_2_START
Definition: UnitDefinitions.hpp:637
@ JOB_BABY_3_2_START
Definition: UnitDefinitions.hpp:645
@ JOB_STAR_GLADIATOR2
Definition: UnitDefinitions.hpp:551
@ JOB_SOUL_LINKER
Definition: UnitDefinitions.hpp:552
@ JOB_GUNSLINGER
Definition: UnitDefinitions.hpp:499
@ JOB_TRANS_2_1_START
Definition: UnitDefinitions.hpp:625
@ JOB_BABY_2_2_START
Definition: UnitDefinitions.hpp:633
@ JOB_STAR_GLADIATOR
Definition: UnitDefinitions.hpp:550
@ JOB_TRANS_BASE_END
Definition: UnitDefinitions.hpp:624
@ JOB_2_1_START
Definition: UnitDefinitions.hpp:619
@ JOB_TRANS_3_1_START
Definition: UnitDefinitions.hpp:639
@ JOB_BASE_START
Definition: UnitDefinitions.hpp:617
@ JOB_BABY_3_1_END
Definition: UnitDefinitions.hpp:644
@ JOB_SUPER_NOVICE
Definition: UnitDefinitions.hpp:498
@ JOB_3_2_END
Definition: UnitDefinitions.hpp:638
@ JOB_BABY_2_1_END
Definition: UnitDefinitions.hpp:632
@ JOB_BABY_3_1_START
Definition: UnitDefinitions.hpp:643
@ JOB_TAEKWON
Definition: UnitDefinitions.hpp:549

References HLog, JOB_2_1_END, JOB_2_1_START, JOB_2_2_END, JOB_2_2_START, JOB_3_1_END, JOB_3_1_START, JOB_3_2_END, JOB_3_2_START, JOB_BABY_2_1_END, JOB_BABY_2_1_START, JOB_BABY_2_2_END, JOB_BABY_2_2_START, JOB_BABY_3_1_END, JOB_BABY_3_1_START, JOB_BABY_3_2_END, JOB_BABY_3_2_START, JOB_BABY_BASE_END, JOB_BABY_BASE_START, JOB_BASE_END, JOB_BASE_START, JOB_DARK_COLLECTOR, JOB_DEATH_KNIGHT, JOB_GANGSI, JOB_GUNSLINGER, JOB_KAGEROU, JOB_NINJA, JOB_OBORO, JOB_REBELLION, JOB_SOUL_LINKER, JOB_STAR_GLADIATOR, JOB_STAR_GLADIATOR2, JOB_SUPER_BABY_E, JOB_SUPER_NOVICE, JOB_SUPER_NOVICE_E, JOB_TAEKWON, JOB_TRANS_2_1_END, JOB_TRANS_2_1_START, JOB_TRANS_2_2_END, JOB_TRANS_2_2_START, JOB_TRANS_3_1_END, JOB_TRANS_3_1_START, JOB_TRANS_3_2_END, JOB_TRANS_3_2_START, JOB_TRANS_BASE_END, and JOB_TRANS_BASE_START.

Referenced by load_items().

+ Here is the caller graph for this function:

◆ get_instance()

static ItemDatabase * Horizon::Zone::ItemDatabase::get_instance ( )
inlinestatic
54 {
55 static ItemDatabase instance;
56 return &instance;
57 }
ItemDatabase()
Definition: ItemDB.cpp:39

◆ get_item_by_id()

std::shared_ptr< const item_config_data > Horizon::Zone::ItemDatabase::get_item_by_id ( uint32_t  item_id) const
inline
66{ return _item_db.at(item_id); }
Value at(Key const &key, Value const &default_value=Value()) const
Definition: LockedLookupTable.hpp:63

References _item_db, and LockedLookupTable< Key, Value, Hash >::at().

+ Here is the call graph for this function:

◆ get_item_by_key_name()

std::shared_ptr< const item_config_data > Horizon::Zone::ItemDatabase::get_item_by_key_name ( std::string  key_name) const
inline
67{ return _item_db_str.at(key_name); }
LockedLookupTable< std::string, std::shared_ptr< const item_config_data > > _item_db_str
Definition: ItemDB.hpp:111

References _item_db_str, and LockedLookupTable< Key, Value, Hash >::at().

+ Here is the call graph for this function:

◆ get_refine_config()

std::shared_ptr< const refine_config > Horizon::Zone::ItemDatabase::get_refine_config ( refine_type  type)
inline
70 {
71 return _refine_db.at(type, std::shared_ptr<refine_config>());
72 }
LockedLookupTable< int32_t, std::shared_ptr< const refine_config > > _refine_db
Definition: ItemDB.hpp:112

References _refine_db.

◆ get_weapon_attribute_modifier()

int32_t Horizon::Zone::ItemDatabase::get_weapon_attribute_modifier ( int32_t  weapon_lv,
element_type  element,
element_type  def_ele 
)
inline
81 {
82 if (weapon_lv < 1 || weapon_lv > 5)
83 return 100;
84
85 if (element < ELE_NEUTRAL || element >= ELE_MAX)
86 return 100;
87
88 if (def_ele < ELE_NEUTRAL || def_ele >= ELE_MAX)
89 return 100;
90
91 std::shared_ptr<std::array<std::array<uint8_t, ELE_MAX>, ELE_MAX>> lvl_arr = _weapon_attribute_modifiers_db.at(weapon_lv);
92 std::array<uint8_t, ELE_MAX> ele_arr = lvl_arr->at(element);
93
94 return ele_arr[def_ele];
95 }
@ ELE_MAX
Definition: UnitDefinitions.hpp:981
LockedLookupTable< int32_t, std::shared_ptr< std::array< std::array< uint8_t, ELE_MAX >, ELE_MAX > > > _weapon_attribute_modifiers_db
Definition: ItemDB.hpp:114

References _weapon_attribute_modifiers_db, LockedLookupTable< Key, Value, Hash >::at(), and ELE_MAX.

+ Here is the call graph for this function:

◆ get_weapon_target_size_modifier()

uint8_t Horizon::Zone::ItemDatabase::get_weapon_target_size_modifier ( item_weapon_type  wtype,
unit_size_type  stype 
)
inline
75 {
76 std::shared_ptr<std::array<uint8_t, ESZ_MAX>> arr = _weapon_target_size_modifiers_db.at(wtype);
77 return arr != nullptr ? (*arr)[stype] : 100;
78 }

References _weapon_target_size_modifiers_db, and LockedLookupTable< Key, Value, Hash >::at().

+ Here is the call graph for this function:

◆ get_weapon_type_name()

std::string Horizon::Zone::ItemDatabase::get_weapon_type_name ( item_weapon_type  type)
inline
98 {
99 try {
100 return _weapontype2name_db[type];
101 } catch (std::exception & /*e*/) {
102 return "Unknown";
103 }
104 }

References _weapontype2name_db.

Referenced by load_weapon_attribute_modifiers_db(), and load_weapon_target_size_modifiers_db().

+ Here is the caller graph for this function:

◆ load()

bool ItemDatabase::load ( )
69{
70 std::shared_ptr<sol::state> lua = std::make_shared<sol::state>();
71 auto start = std::chrono::high_resolution_clock::now();
72
73 lua->open_libraries(sol::lib::base);
74 lua->open_libraries(sol::lib::package);
75
76 std::shared_ptr<UnitComponent> unit_component = std::make_shared<UnitComponent>();
77 std::shared_ptr<ItemComponent> item_component = std::make_shared<ItemComponent>();
78
79 unit_component->sync_definitions(lua);
80 unit_component->sync_data_types(lua);
81 unit_component->sync_functions(lua);
82
83 item_component->sync_definitions(lua);
84 item_component->sync_data_types(lua);
85 item_component->sync_functions(lua);
86
87 int total_entries = 0;
88
89
90 try {
91 std::string file_path = sZone->config().get_static_db_path().string() + "item_db.lua";
92 lua->script_file(file_path);
93 sol::table item_tbl = lua->get<sol::table>("item_db");
94 total_entries = load_items(item_tbl, file_path);
95 auto stop = std::chrono::high_resolution_clock::now();
96 HLog(info) << "Loaded " << total_entries << " entries from '" << file_path << "' (" << std::chrono::duration_cast<std::chrono::microseconds>(stop - start).count() << "µs, Max Collisions: " << _item_db.max_collisions() << ").";
97 } catch (sol::error err) {
98 HLog(error) << err.what();
99 }
100
101 return true;
102}
#define sZone
Definition: Zone.hpp:247
int load_items(sol::table const &item_tbl, std::string file_path)
Definition: ItemDB.cpp:353
int max_collisions()
Definition: LockedLookupTable.hpp:94

References _item_db, HLog, load_items(), LockedLookupTable< Key, Value, Hash >::max_collisions(), and sZone.

+ Here is the call graph for this function:

◆ load_items()

int ItemDatabase::load_items ( sol::table const &  item_tbl,
std::string  file_path 
)
private
354{
355 int entry = 0;
356 item_tbl.for_each([this, &entry, &file_path](sol::object const &key, sol::object const &value) {
357 uint32_t t_int = 0;
358 sol::table tbl = value.as<sol::table>();
359 std::string t_str;
361
362 entry++;
363
364 if (key.get_type() != sol::type::string)
365 return;
366
367 id.key_name = key.as<std::string>();
368
369 if (id.key_name.length() < 1) {
370 HLog(error) << "ItemDB::load_items: Invalid or non-existent mandatory field 'AegisName' for entry " << id.item_id << " in '" << file_path << "'. Skipping...";
371 return;
372 }
373
374 id.item_id = tbl.get_or("Id", 0);
375 if (id.item_id == 0) {
376 HLog(error) << "ItemDB::load_items: Invalid or non-existent mandatory field 'Id' for item '" << id.key_name << "' in '" << file_path << "'. Skipping...";
377 return;
378 }
379
380 id.name = tbl.get_or("Name", std::string(""));
381 if (id.name.empty()) {
382 HLog(error) << "ItemDB::load_items: Invalid or non-existent mandatory field 'Name' for entry " << id.item_id << " in '" << file_path << "'. Skipping...";
383 return;
384 }
385
386 id.type = (item_type) tbl.get_or("Type", (uint16_t) IT_TYPE_ETC);
387
388 if (id.type == IT_TYPE_WEAPON)
389 id.sub_type.weapon_t = (item_weapon_type) tbl.get_or("Subtype", (int) IT_WT_FIST);
390 else if (id.type == IT_TYPE_AMMO)
391 id.sub_type.ammo_t = (item_ammunition_type) tbl.get_or("Subtype", (int) IT_AT_NONE);
392
393 id.value_buy = tbl.get_or("Buy", -1);
394 id.value_sell = tbl.get_or("Sell", -1);
395
396 if (id.value_buy == -1 && id.value_sell == -1)
397 id.value_buy = id.value_sell = 0;
398 else if (id.value_buy == -1)
399 id.value_buy = id.value_sell * 2;
400 else if (id.value_sell == -1)
401 id.value_sell = id.value_buy / 2;
402
403 // Discount / Overcharge zeny exploit check.
404 if (id.value_buy / 124.0 < id.value_sell / 75.0) {
405 HLog(warning) << "Buying/Selling [" << id.value_buy << "/" << id.value_sell << "] price of item " << id.item_id << " (" << id.name << ") "
406 "allows Zeny making exploit through buying/selling at discounted/overcharged prices! File '" << file_path << "'.\n";
407 }
408
409 id.weight = tbl.get_or("Weight", 0);
410 id.attack = tbl.get_or("Atk", 0);
411 id.magic_atk = tbl.get_or("Matk", 0);
412 id.defense = tbl.get_or("Def", 0);
413 id.attack_range = tbl.get_or("Range", 0);
414 id.card_slot_count = tbl.get_or("Slots", 0);
415 t_int = tbl.get_or("WeaponLv", 1);
416
417 if (id.type == IT_TYPE_WEAPON)
418 id.level.weapon = t_int;
419 else
420 id.level.armor = t_int;
421
422 sol::optional<sol::object> maybe_job_tbl = tbl.get<sol::optional<sol::object>>("Job");
423 if (maybe_job_tbl && maybe_job_tbl.value().get_type() == sol::type::table) {
424 sol::table job_tbl = maybe_job_tbl.value().as<sol::table>();
425 job_tbl.for_each([this, &id, &file_path] (sol::object const &key, sol::object const &value)
426 {
427 bool enable = value.as<bool>();
428
429 if (key.get_type() == sol::type::string) {
430 std::string job_name = key.as<std::string>();
431 if (!add_job_group_to_item(job_name, id, enable, file_path))
432 return;
433 } else if (key.get_type() == sol::type::number) {
434 int job_id = key.as<int>();
435
436 if (enable) {
437 id.requirements.job_ids.push_back(job_id);
438 } else {
439 std::remove_if(id.requirements.job_ids.begin(), id.requirements.job_ids.end(), [job_id] (uint32_t id) { return job_id == id; });
440 }
441 } else if (!add_job_group_to_item("All", id, enable, file_path)) {
442 return;
443 }
444 });
445 } else if (maybe_job_tbl && maybe_job_tbl.value().get_type() == sol::type::string) {
446 std::string job_name = maybe_job_tbl.value().as<std::string>();
447 if (!add_job_group_to_item(job_name, id, true, file_path))
448 return;
449 } else if (maybe_job_tbl && maybe_job_tbl.value().get_type() == sol::type::number) {
450 id.requirements.job_ids.push_back(maybe_job_tbl.value().as<uint32_t>());
451 } else if (!add_job_group_to_item("All", id, true, file_path)) {
452 return;
453 }
454
455 id.requirements.gender = (item_gender_type) tbl.get_or("Gender", (char) IT_GENDER_ANY);
456
457 sol::optional<sol::object> location = tbl.get<sol::optional<sol::object>>("Loc");
458
459 if (location) {
460 sol::object loc = location.value();
461
462 if (loc.get_type() == sol::type::table) {
463 loc.as<sol::table>().for_each([&id, &file_path] (sol::object const &key, sol::object const &value) {
464 if (value.get_type() != sol::type::number) {
465 HLog(warning) <<"Invalid type for 'Loc' in entry '" << id.key_name << "' in file '" << file_path << "'";
466 return;
467 }
468
469 id.equip_location_mask |= value.as<int>();
470 });
471 } else if (loc.get_type() == sol::type::number) {
472 id.equip_location_mask |= loc.as<int>();
473 }
474 }
475
476 sol::optional<sol::object> maybe_elv = tbl.get<sol::optional<sol::object>>("EquipLv");
477
478 if (maybe_elv) {
479 if (maybe_elv.value().get_type() == sol::type::table) {
480 sol::table elv = maybe_elv.value();
481 id.requirements.min_lv = elv.get_or(0, 0);
482 id.requirements.max_lv = elv.get_or(1, 0);
483 } else if (maybe_elv.value().get_type() == sol::type::number) {
484 id.requirements.min_lv = maybe_elv.value().as<int32_t>();
485 } else {
486 id.requirements.min_lv = id.requirements.max_lv = 0;
487 }
488 } else {
489 id.requirements.min_lv = id.requirements.max_lv = 0;
490 }
491
492 id.config.refineable = tbl.get_or("Refine", false);
493 id.config.allow_item_options = tbl.get_or("EnableOptions", true);
494
495 id.config.bind_on_equip = tbl.get_or("BindOnEquip", false);
496 id.config.force_serial = tbl.get_or("ForceSerial", false);
497 id.config.keep_after_use = tbl.get_or("KeepAfterUse", false);
498 id.config.drop_announce = tbl.get_or("DropAnnounce", false);
499
500 id.config.show_drop_effect = tbl.get_or("ShowDropEffect", false);
501 id.drop_effect_mode = tbl.get_or("DropEffectMode", 0);
502
503 sol::optional<sol::object> no_trade = tbl.get<sol::optional<sol::object>>("NoTrade");
504
505 if (no_trade) {
506 sol::object nt = no_trade.value();
507
508 if (nt.get_type() == sol::type::table) {
509 nt.as<sol::table>().for_each([&id, &file_path] (sol::object const &key, sol::object const &value) {
510 if (value.get_type() != sol::type::number && value.get_type() != sol::type::boolean) {
511 HLog(warning) <<"Invalid type for 'NoTrade' in entry '" << id.key_name << "' in file '" << file_path << "'";
512 return;
513 }
514
515 if (key.get_type() != sol::type::number) {
516 if (key.as<std::string>().compare("override") == 0) {
517 id.trade_restriction_group_override_id = value.as<int>();
518 return;
519 } else if (key.as<std::string>().compare("partneroverride") == 0) {
520 id.trade_restriction_partner_override = value.as<bool>();
521 return;
522 }
523 }
524
525 id.trade_restriction_mask |= value.as<int>();
526 });
527 } else if (nt.get_type() == sol::type::number) {
528 id.trade_restriction_mask |= nt.as<int>();
529 }
530 }
531
532 sol::optional<sol::object> no_use = tbl.get<sol::optional<sol::object>>("RestrictUsage");
533
534 if (no_use) {
535 sol::object nu = no_use.value();
536
537 if (nu.get_type() == sol::type::table) {
538 nu.as<sol::table>().for_each([&id, &file_path] (sol::object const &key, sol::object const &value) {
539 if (value.get_type() != sol::type::number) {
540 HLog(warning) <<"Invalid type for 'RestrictUsage' in entry '" << id.key_name << "' in file '" << file_path << "'";
541 return;
542 }
543
544 if (key.get_type() != sol::type::number) {
545 if (key.as<std::string>().compare("override") == 0) {
546 id.usage_restriction_group_override_id = value.as<int>();
547 return;
548 }
549 }
550
551 id.usage_restriction_mask |= value.as<int>();
552 });
553 } else if (nu.get_type() == sol::type::number) {
554 id.usage_restriction_mask |= nu.as<int>();
555 }
556 }
557
558 sol::optional<sol::object> stack = tbl.get<sol::optional<sol::object>>("Stack");
559
560 if (stack) {
561 sol::object s = stack.value();
562
563 if (s.get_type() == sol::type::table) {
564 s.as<sol::table>().for_each([&id, &file_path] (sol::object const &key, sol::object const &value) {
565 if (value.get_type() != sol::type::number) {
566 HLog(warning) << "Invalid type for 'Stack' in entry '" << id.key_name << "' in file '" << file_path << "'";
567 return;
568 }
569
570 if (key.as<std::string>().compare("Inventory") == 0) {
571 id.stack.inventory = value.as<int>();
572 } else if (key.as<std::string>().compare("Cart") == 0) {
573 id.stack.cart = value.as<int>();
574 } else if (key.as<std::string>().compare("Storage") == 0) {
575 id.stack.storage = value.as<int>();
576 } else if (key.as<std::string>().compare("GuildStorage") == 0) {
577 id.stack.guild_storage = value.as<int>();
578 } else {
579 HLog(warning) << "Invalid type '" << key.as<std::string>() << "' for 'Stack' in entry '" << id.key_name << "' in file '" << file_path << "', skipping...";
580 }
581 });
582 } else {
583 id.stack.inventory = MAX_INVENTORY_STACK_LIMIT;
584 id.stack.cart = MAX_CART_STACK_LIMIT;
585 id.stack.storage = MAX_STORAGE_STACK_LIMIT;
586 id.stack.guild_storage = MAX_GSTORAGE_STACK_LIMIT;
587
588 HLog(warning) << "Invalid value type for 'Stack' in entry '" << id.key_name << "' in file '" << file_path << "', defaulting to max stack limits...";
589 }
590 } else {
591 id.stack.inventory = MAX_INVENTORY_STACK_LIMIT;
592 id.stack.cart = MAX_CART_STACK_LIMIT;
593 id.stack.storage = MAX_STORAGE_STACK_LIMIT;
594 id.stack.guild_storage = MAX_GSTORAGE_STACK_LIMIT;
595 }
596
597 id.delay = tbl.get_or("Delay", 0);
598
599 id.sprite_id = tbl.get_or("SpriteId", 0);
600
601 id.default_script = tbl.get_or("Script", std::string(""));
602 id.equip_script = tbl.get_or("OnEquipScript", std::string(""));
603 id.unequip_script = tbl.get_or("OnUnequipScript", std::string(""));
604
605 _item_db.insert(id.item_id, std::make_shared<item_config_data>(id));
606 _item_db_str.insert(id.key_name, std::make_shared<item_config_data>(id));
607 });
608
609 return _item_db.size();
610}
#define MAX_INVENTORY_STACK_LIMIT
Definition: ItemDefinitions.hpp:65
item_ammunition_type
Definition: ItemDefinitions.hpp:271
@ IT_AT_NONE
Definition: ItemDefinitions.hpp:272
#define MAX_CART_STACK_LIMIT
Definition: ItemDefinitions.hpp:66
#define MAX_STORAGE_STACK_LIMIT
Definition: ItemDefinitions.hpp:67
item_type
Definition: ItemDefinitions.hpp:253
@ IT_TYPE_ETC
Definition: ItemDefinitions.hpp:257
@ IT_TYPE_WEAPON
Definition: ItemDefinitions.hpp:258
@ IT_TYPE_AMMO
Definition: ItemDefinitions.hpp:264
#define MAX_GSTORAGE_STACK_LIMIT
Definition: ItemDefinitions.hpp:68
item_weapon_type
Definition: ItemDefinitions.hpp:99
item_gender_type
Definition: ItemDefinitions.hpp:159
@ IT_GENDER_ANY
Definition: ItemDefinitions.hpp:162
bool add_job_group_to_item(std::string const &group, item_config_data &id, bool enable, std::string const &file_path)
Definition: ItemDB.cpp:104
void insert(const Key &key, const Value &value)
Definition: LockedLookupTable.hpp:68
std::size_t size()
Definition: LockedLookupTable.hpp:96
Definition: ItemDefinitions.hpp:334
std::string key_name
Definition: ItemDefinitions.hpp:336

References _item_db, _item_db_str, add_job_group_to_item(), HLog, LockedLookupTable< Key, Value, Hash >::insert(), IT_AT_NONE, IT_GENDER_ANY, IT_TYPE_AMMO, IT_TYPE_ETC, IT_TYPE_WEAPON, IT_WT_FIST, item_config_data::key_name, MAX_CART_STACK_LIMIT, MAX_GSTORAGE_STACK_LIMIT, MAX_INVENTORY_STACK_LIMIT, MAX_STORAGE_STACK_LIMIT, and LockedLookupTable< Key, Value, Hash >::size().

Referenced by load().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ load_refine_db()

bool ItemDatabase::load_refine_db ( )
613{
614 sol::state lua;
615 auto start = std::chrono::high_resolution_clock::now();
616
617 lua.open_libraries(sol::lib::base);
618
619 int total_entries = 0;
620
621 std::string file_path = sZone->config().get_static_db_path().string() + "refine_db.lua";
622
623 try {
624 lua.script_file(file_path);
625 struct {
626 refine_type type;
627 std::string tbl_name;
628 } refine_tbls[] = {
629 { REFINE_TYPE_ARMOR, "Armors", },
630 { REFINE_TYPE_WEAPON1, "WeaponLevel1", },
631 { REFINE_TYPE_WEAPON2, "WeaponLevel2", },
632 { REFINE_TYPE_WEAPON3, "WeaponLevel3", },
633 { REFINE_TYPE_WEAPON4, "WeaponLevel4" }
634 };
635 for (auto &tbl : refine_tbls) {
636 if (load_refine_table(tbl.type, lua.get<sol::table>(tbl.tbl_name), tbl.tbl_name, file_path))
637 total_entries++;
638 }
639 auto stop = std::chrono::high_resolution_clock::now();
640 HLog(info) << "Loaded " << total_entries << " entries from '" << file_path << "' (" << std::chrono::duration_cast<std::chrono::microseconds>(stop - start).count() << "µs).";
641 } catch(const std::exception &e) {
642 HLog(error) << e.what() << " in file '" << file_path << "'";
643 return false;
644 }
645
646 return true;
647}
refine_type
Definition: ItemDefinitions.hpp:80
@ REFINE_TYPE_WEAPON1
Definition: ItemDefinitions.hpp:82
@ REFINE_TYPE_WEAPON4
Definition: ItemDefinitions.hpp:85
@ REFINE_TYPE_ARMOR
Definition: ItemDefinitions.hpp:81
@ REFINE_TYPE_WEAPON2
Definition: ItemDefinitions.hpp:83
@ REFINE_TYPE_WEAPON3
Definition: ItemDefinitions.hpp:84
bool load_refine_table(refine_type tbl_type, sol::table const &refine_table, std::string table_name, std::string file_path)
Definition: ItemDB.cpp:649

References HLog, load_refine_table(), REFINE_TYPE_ARMOR, REFINE_TYPE_WEAPON1, REFINE_TYPE_WEAPON2, REFINE_TYPE_WEAPON3, REFINE_TYPE_WEAPON4, and sZone.

+ Here is the call graph for this function:

◆ load_refine_table()

bool ItemDatabase::load_refine_table ( refine_type  tbl_type,
sol::table const &  refine_table,
std::string  table_name,
std::string  file_path 
)
private
650{
651 uint32_t bonus_per_level = 0, rand_bonus_start_lv = 0, rand_bonus_val = 0;
652 refine_config cfg;
653
654 bonus_per_level = refine_table.get_or("StatsPerLevel", 0);
655 rand_bonus_start_lv = refine_table.get_or("RandomBonusStartLevel", 0);
656 rand_bonus_val = refine_table.get_or("RandomBonusValue", 0);
657
658 sol::optional<sol::table> maybe_rates = refine_table.get<sol::optional<sol::table>>("Rates");
659
660 if (maybe_rates) {
661 if (maybe_rates.value().get_type() != sol::type::table) {
662 HLog(error) << "Invalid type for entry 'Rates' table '" << table_name << "' in file '" << file_path << "'. Skipping...";
663 return false;
664 }
665
666 sol::table rates_tbl = maybe_rates.value();
667
668 for (int i = 0; i < MAX_REFINE_LEVEL; i++) {
669 sol::optional<sol::table> maybe_level_tbl = rates_tbl.get<sol::optional<sol::table>>(i + 1);
670 if (maybe_level_tbl) {
671 sol::table level_tbl = maybe_level_tbl.value();
672 cfg.bonus[i] = bonus_per_level + level_tbl.get_or("Bonus", 0);
673 cfg.chance[REFINE_CHANCE_TYPE_NORMAL][i] = level_tbl.get_or("NormalChance", 100);
674 cfg.chance[REFINE_CHANCE_TYPE_ENRICHED][i] = level_tbl.get_or("EnrichedChance", i + 1 > 10 ? 0 : 100); // enriched ores up to +10 only.
675 cfg.chance[REFINE_CHANCE_TYPE_E_NORMAL][i] = level_tbl.get_or("EventNormalChance", 100);
676 cfg.chance[REFINE_CHANCE_TYPE_E_ENRICHED][i] = level_tbl.get_or("EventEnrichedChance", i + 1 > 10 ? 0 : 100); // enriched ores up to +10 only.
677 if (i + 1 >= rand_bonus_start_lv)
678 cfg.randombonus_max[i] = (rand_bonus_val * (i - rand_bonus_start_lv + 2));
679 } else {
680 // Defaults.
681 cfg.bonus[i] = bonus_per_level;
682 cfg.chance[REFINE_CHANCE_TYPE_NORMAL][i] = cfg.chance[REFINE_CHANCE_TYPE_E_NORMAL][i] = 100;
683 cfg.chance[REFINE_CHANCE_TYPE_ENRICHED][i] = cfg.chance[REFINE_CHANCE_TYPE_E_ENRICHED][i] = i + 1 > 10 ? 0 : 100; // enriched ores up to +10 only.
684 }
685 }
686 } else {
687 HLog(error) << "Non-existent configuration for entry 'Rates' table '" << table_name << "' in file '" << file_path << "'. Skipping...";
688 return false;
689 }
690
691 _refine_db.insert(type, std::make_shared<refine_config>(cfg));
692
693 return true;
694}
#define MAX_REFINE_LEVEL
Definition: ItemDefinitions.hpp:43
@ REFINE_CHANCE_TYPE_ENRICHED
Definition: ItemDefinitions.hpp:92
@ REFINE_CHANCE_TYPE_E_NORMAL
Definition: ItemDefinitions.hpp:93
@ REFINE_CHANCE_TYPE_NORMAL
Definition: ItemDefinitions.hpp:91
@ REFINE_CHANCE_TYPE_E_ENRICHED
Definition: ItemDefinitions.hpp:94

References _refine_db, Horizon::Zone::ItemDatabase::refine_config::bonus, Horizon::Zone::ItemDatabase::refine_config::chance, HLog, MAX_REFINE_LEVEL, Horizon::Zone::ItemDatabase::refine_config::randombonus_max, REFINE_CHANCE_TYPE_E_ENRICHED, REFINE_CHANCE_TYPE_E_NORMAL, REFINE_CHANCE_TYPE_ENRICHED, and REFINE_CHANCE_TYPE_NORMAL.

Referenced by load_refine_db().

+ Here is the caller graph for this function:

◆ load_weapon_attribute_modifiers_db()

bool ItemDatabase::load_weapon_attribute_modifiers_db ( )
743{
744 std::shared_ptr<sol::state> lua = std::make_shared<sol::state>();
745 auto start = std::chrono::high_resolution_clock::now();
746
747 lua->open_libraries(sol::lib::base);
748
749 std::shared_ptr<ItemComponent> item_component = std::make_shared<ItemComponent>();
750 std::shared_ptr<UnitComponent> unit_component = std::make_shared<UnitComponent>();
751
752 item_component->sync_definitions(lua);
753 item_component->sync_data_types(lua);
754 item_component->sync_functions(lua);
755
756 unit_component->sync_definitions(lua);
757 unit_component->sync_data_types(lua);
758 unit_component->sync_functions(lua);
759
760 int total_entries = 0;
761
762 std::string file_path = sZone->config().get_static_db_path().string() + "weapon_attribute_modifiers.lua";
763
764 try {
765 lua->script_file(file_path);
766
767 sol::table attr_mod_tbl = (*lua)["weapon_attribute_modifiers"];
768
769 struct {
770 element_type type;
771 std::string ele_name;
772 } attr_s[] = {
773 { ELE_NEUTRAL, "Neutral" },
774 { ELE_WATER, "Water" },
775 { ELE_EARTH, "Earth" },
776 { ELE_FIRE, "Fire" },
777 { ELE_WIND, "Wind" },
778 { ELE_POISON, "Poison" },
779 { ELE_HOLY, "Holy" },
780 { ELE_DARK, "Dark" },
781 { ELE_GHOST, "Ghost" },
782 { ELE_UNDEAD, "Undead" },
783 };
784
785 for (int i = IT_LVL_WEAPON1; i < IT_LVL_MAX; i++) {
786 std::shared_ptr<std::array<std::array<uint8_t, ELE_MAX>, ELE_MAX>> arr = std::make_shared<std::array<std::array<uint8_t, ELE_MAX>, ELE_MAX>>();
787 for (int j = ELE_NEUTRAL; j < ELE_MAX; j++) {
788 for (int k = ELE_NEUTRAL; k < ELE_MAX; k++) {
789 try {
790 (*arr)[j][k] = attr_mod_tbl[i][j][k + 1];
791 } catch (std::exception &err) {
792 HLog(error) << "Weapon target attribute modifier was not found for weapon type " << get_weapon_type_name((item_weapon_type) i) << " attribute [" << attr_s[j].ele_name << "][" << attr_s[k].ele_name << "], defaulting to 100%...";
793 (*arr)[j][k] = 100;
794 }
795 total_entries++;
796 }
797 }
799 }
800 auto stop = std::chrono::high_resolution_clock::now();
801 HLog(info) << "Loaded " << total_entries << " entries from '" << file_path << "' (" << std::chrono::duration_cast<std::chrono::microseconds>(stop - start).count() << "µs).";
802 } catch(const std::exception &e) {
803 HLog(error) << e.what() << " in file '" << file_path << "'.";
804 return false;
805 }
806
807 return true;
808}
item_level_type
Definition: ItemDefinitions.hpp:149
@ IT_LVL_MAX
Definition: ItemDefinitions.hpp:155
@ IT_LVL_WEAPON1
Definition: ItemDefinitions.hpp:151
element_type
Definition: UnitDefinitions.hpp:970
@ ELE_NEUTRAL
Definition: UnitDefinitions.hpp:971
@ ELE_EARTH
Definition: UnitDefinitions.hpp:973
@ ELE_HOLY
Definition: UnitDefinitions.hpp:977
@ ELE_POISON
Definition: UnitDefinitions.hpp:976
@ ELE_UNDEAD
Definition: UnitDefinitions.hpp:980
@ ELE_GHOST
Definition: UnitDefinitions.hpp:979
@ ELE_WATER
Definition: UnitDefinitions.hpp:972
@ ELE_WIND
Definition: UnitDefinitions.hpp:975
@ ELE_FIRE
Definition: UnitDefinitions.hpp:974
@ ELE_DARK
Definition: UnitDefinitions.hpp:978
std::string get_weapon_type_name(item_weapon_type type)
Definition: ItemDB.hpp:97

References _weapon_attribute_modifiers_db, ELE_DARK, ELE_EARTH, ELE_FIRE, ELE_GHOST, ELE_HOLY, ELE_MAX, ELE_NEUTRAL, ELE_POISON, ELE_UNDEAD, ELE_WATER, ELE_WIND, get_weapon_type_name(), HLog, LockedLookupTable< Key, Value, Hash >::insert(), IT_LVL_MAX, IT_LVL_WEAPON1, and sZone.

+ Here is the call graph for this function:

◆ load_weapon_target_size_modifiers_db()

bool ItemDatabase::load_weapon_target_size_modifiers_db ( )
697{
698 std::shared_ptr<sol::state> lua = std::make_shared<sol::state>();
699 auto start = std::chrono::high_resolution_clock::now();
700
701 lua->open_libraries(sol::lib::base);
702
703 std::shared_ptr<ItemComponent> item_component = std::make_shared<ItemComponent>();
704
705 item_component->sync_definitions(lua);
706 item_component->sync_data_types(lua);
707 item_component->sync_functions(lua);
708
709 int total_entries = 0;
710
711 std::string file_path = sZone->config().get_static_db_path().string() + "weapon_target_size_modifiers.lua";
712
713 try {
714 lua->script_file(file_path);
715
716 sol::table size_mod_tbl = (*lua)["weapon_target_size_modifiers"];
717
718 for (int i = IT_WT_FIST; i < IT_WT_SINGLE_MAX; i++) {
719 std::shared_ptr<std::array<uint8_t, ESZ_MAX>> arr = std::make_shared<std::array<uint8_t, ESZ_MAX>>();
720 for (int j = ESZ_SMALL; j < ESZ_MAX; j++) {
721 std::string size = j == ESZ_SMALL ? "Small" : j == ESZ_MEDIUM ? "Medium" : "Large";
722 try {
723 (*arr)[j] = size_mod_tbl[i][size];
724 } catch (std::exception &err) {
725 HLog(error) << "Weapon target size modifier was not found for weapon type " << get_weapon_type_name((item_weapon_type) i) << " size " << size << ", defaulting to 100%...";
726 (*arr)[j] = 100;
727 }
728 }
730 total_entries++;
731 }
732 auto stop = std::chrono::high_resolution_clock::now();
733 HLog(info) << "Loaded " << total_entries << " entries from '" << file_path << "' (" << std::chrono::duration_cast<std::chrono::microseconds>(stop - start).count() << "µs.";
734 } catch(const std::exception &e) {
735 HLog(error) << e.what() << " in file '" << file_path << "'";
736 return false;
737 }
738
739 return true;
740}
@ IT_WT_SINGLE_MAX
Definition: ItemDefinitions.hpp:124
@ ESZ_MEDIUM
Definition: UnitDefinitions.hpp:38
@ ESZ_MAX
Definition: UnitDefinitions.hpp:40
@ ESZ_SMALL
Definition: UnitDefinitions.hpp:37

References _weapon_target_size_modifiers_db, ESZ_MAX, ESZ_MEDIUM, ESZ_SMALL, get_weapon_type_name(), HLog, LockedLookupTable< Key, Value, Hash >::insert(), IT_WT_FIST, IT_WT_SINGLE_MAX, and sZone.

+ Here is the call graph for this function:

Member Data Documentation

◆ _item_db

LockedLookupTable<int32_t, std::shared_ptr<const item_config_data> > Horizon::Zone::ItemDatabase::_item_db
private

Referenced by get_item_by_id(), load(), and load_items().

◆ _item_db_str

LockedLookupTable<std::string, std::shared_ptr<const item_config_data> > Horizon::Zone::ItemDatabase::_item_db_str
private

Referenced by get_item_by_key_name(), and load_items().

◆ _refine_db

LockedLookupTable<int32_t, std::shared_ptr<const refine_config> > Horizon::Zone::ItemDatabase::_refine_db
private

◆ _weapon_attribute_modifiers_db

LockedLookupTable<int32_t, std::shared_ptr<std::array<std::array<uint8_t, ELE_MAX>, ELE_MAX> > > Horizon::Zone::ItemDatabase::_weapon_attribute_modifiers_db
private

◆ _weapon_target_size_modifiers_db

LockedLookupTable<int32_t, std::shared_ptr<std::array<uint8_t, ESZ_MAX> > > Horizon::Zone::ItemDatabase::_weapon_target_size_modifiers_db
private

◆ _weapontype2name_db

std::array<std::string, IT_WT_SINGLE_MAX> Horizon::Zone::ItemDatabase::_weapontype2name_db
private

The documentation for this class was generated from the following files: