Horizon Official Technical Documentation
ItemDB.hpp
Go to the documentation of this file.
1/***************************************************
2 * _ _ _ *
3 * | | | | (_) *
4 * | |_| | ___ _ __ _ _______ _ __ *
5 * | _ |/ _ \| '__| |_ / _ \| '_ \ *
6 * | | | | (_) | | | |/ / (_) | | | | *
7 * \_| |_/\___/|_| |_/___\___/|_| |_| *
8 ***************************************************
9 * This file is part of Horizon (c).
10 *
11 * Copyright (c) 2019 Sagun K. (sagunxp@gmail.com).
12 * Copyright (c) 2019 Horizon Dev Team.
13 *
14 * Base Author - Sagun K. (sagunxp@gmail.com)
15 *
16 * This library is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this library. If not, see <http://www.gnu.org/licenses/>.
28 **************************************************/
29
30#ifndef HORIZON_ZONE_STATICDB_ITEMDB_HPP
31#define HORIZON_ZONE_STATICDB_ITEMDB_HPP
35#include <sol/sol.hpp>
36
37namespace Horizon
38{
39namespace Zone
40{
42{
43// bonus values and upgrade chances for refining equipment
45 int chance[REFINE_CHANCE_TYPE_MAX][MAX_REFINE_LEVEL]{{0}}; // success chance
46 int bonus[MAX_REFINE_LEVEL]{0}; // cumulative fixed bonus damage
47 int randombonus_max[MAX_REFINE_LEVEL]{0}; // cumulative maximum random bonus damage
48};
49public:
52
54 {
55 static ItemDatabase instance;
56 return &instance;
57 }
58
59 bool load();
60 bool load_refine_db();
63
64 bool add_job_group_to_item(std::string const &group, item_config_data &id, bool enable, std::string const &file_path);
65
66 std::shared_ptr<const item_config_data> get_item_by_id(uint32_t item_id) const { return _item_db.at(item_id); }
67 std::shared_ptr<const item_config_data> get_item_by_key_name(std::string key_name) const { return _item_db_str.at(key_name); }
68
69 std::shared_ptr<const refine_config> get_refine_config(refine_type type)
70 {
71 return _refine_db.at(type, std::shared_ptr<refine_config>());
72 }
73
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 }
79
80 int32_t get_weapon_attribute_modifier(int32_t weapon_lv, element_type element, element_type def_ele)
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 }
96
98 {
99 try {
100 return _weapontype2name_db[type];
101 } catch (std::exception & /*e*/) {
102 return "Unknown";
103 }
104 }
105
106private:
107 int load_items(sol::table const &item_tbl, std::string file_path);
108 bool load_refine_table(refine_type tbl_type, sol::table const &refine_table, std::string table_name, std::string file_path);
109 std::array<std::string, IT_WT_SINGLE_MAX> _weapontype2name_db;
115};
116}
117}
118
119#define ItemDB Horizon::Zone::ItemDatabase::get_instance()
120
121#endif /* HORIZON_ZONE_STATICDB_ITEMDB_HPP */
refine_type
Definition: ItemDefinitions.hpp:80
#define MAX_REFINE_LEVEL
Definition: ItemDefinitions.hpp:43
item_weapon_type
Definition: ItemDefinitions.hpp:99
@ REFINE_CHANCE_TYPE_MAX
Definition: ItemDefinitions.hpp:95
element_type
Definition: UnitDefinitions.hpp:970
@ ELE_MAX
Definition: UnitDefinitions.hpp:981
unit_size_type
Definition: UnitDefinitions.hpp:36
Definition: ItemDB.hpp:42
static ItemDatabase * get_instance()
Definition: ItemDB.hpp:53
std::array< std::string, IT_WT_SINGLE_MAX > _weapontype2name_db
Definition: ItemDB.hpp:109
bool load_weapon_attribute_modifiers_db()
Definition: ItemDB.cpp:742
LockedLookupTable< int32_t, std::shared_ptr< const refine_config > > _refine_db
Definition: ItemDB.hpp:112
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
std::string get_weapon_type_name(item_weapon_type type)
Definition: ItemDB.hpp:97
LockedLookupTable< int32_t, std::shared_ptr< std::array< uint8_t, ESZ_MAX > > > _weapon_target_size_modifiers_db
Definition: ItemDB.hpp:113
std::shared_ptr< const item_config_data > get_item_by_id(uint32_t item_id) const
Definition: ItemDB.hpp:66
int32_t get_weapon_attribute_modifier(int32_t weapon_lv, element_type element, element_type def_ele)
Definition: ItemDB.hpp:80
~ItemDatabase()
Definition: ItemDB.hpp:51
ItemDatabase()
Definition: ItemDB.cpp:39
LockedLookupTable< int32_t, std::shared_ptr< std::array< std::array< uint8_t, ELE_MAX >, ELE_MAX > > > _weapon_attribute_modifiers_db
Definition: ItemDB.hpp:114
std::shared_ptr< const refine_config > get_refine_config(refine_type type)
Definition: ItemDB.hpp:69
bool load_weapon_target_size_modifiers_db()
Definition: ItemDB.cpp:696
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
bool load_refine_db()
Definition: ItemDB.cpp:612
uint8_t get_weapon_target_size_modifier(item_weapon_type wtype, unit_size_type stype)
Definition: ItemDB.hpp:74
int load_items(sol::table const &item_tbl, std::string file_path)
Definition: ItemDB.cpp:353
bool load()
Definition: ItemDB.cpp:68
LockedLookupTable< std::string, std::shared_ptr< const item_config_data > > _item_db_str
Definition: ItemDB.hpp:111
std::shared_ptr< const item_config_data > get_item_by_key_name(std::string key_name) const
Definition: ItemDB.hpp:67
LockedLookupTable< int32_t, std::shared_ptr< const item_config_data > > _item_db
Definition: ItemDB.hpp:110
Definition: LockedLookupTable.hpp:44
Value at(Key const &key, Value const &default_value=Value()) const
Definition: LockedLookupTable.hpp:63
Definition: Element.hpp:7
int bonus[MAX_REFINE_LEVEL]
Definition: ItemDB.hpp:46
int chance[REFINE_CHANCE_TYPE_MAX][MAX_REFINE_LEVEL]
Definition: ItemDB.hpp:45
int randombonus_max[MAX_REFINE_LEVEL]
Definition: ItemDB.hpp:47
Definition: ItemDefinitions.hpp:334