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

#include <ExpDB.hpp>

+ Collaboration diagram for Horizon::Zone::ExpDatabase:

Public Member Functions

 ExpDatabase ()
 
 ~ExpDatabase ()
 
bool load ()
 
std::shared_ptr< const exp_group_dataget_exp_group (std::string const &name, exp_group_type type)
 
uint32_t get_status_point (uint32_t level)
 
bool load_status_point_table ()
 

Static Public Member Functions

static ExpDatabaseget_instance ()
 

Protected Member Functions

int load_group (sol::table &tbl, exp_group_type type)
 

Protected Attributes

LockedLookupTable< std::string, std::shared_ptr< const exp_group_data > > _base_exp_group_db
 
LockedLookupTable< std::string, std::shared_ptr< const exp_group_data > > _job_exp_group_db
 
LockedLookupTable< uint32_t, uint32_t > _stat_point_db
 

Constructor & Destructor Documentation

◆ ExpDatabase()

Horizon::Zone::ExpDatabase::ExpDatabase ( )
inline
58{ }

◆ ~ExpDatabase()

Horizon::Zone::ExpDatabase::~ExpDatabase ( )
inline
59{ }

Member Function Documentation

◆ get_exp_group()

std::shared_ptr< const exp_group_data > Horizon::Zone::ExpDatabase::get_exp_group ( std::string const &  name,
exp_group_type  type 
)
inline
70 {
71 return type == EXP_GROUP_TYPE_BASE ? _base_exp_group_db.at(name) : _job_exp_group_db.at(name);
72 }
LockedLookupTable< std::string, std::shared_ptr< const exp_group_data > > _base_exp_group_db
Definition: ExpDB.hpp:85
LockedLookupTable< std::string, std::shared_ptr< const exp_group_data > > _job_exp_group_db
Definition: ExpDB.hpp:86
@ EXP_GROUP_TYPE_BASE
Definition: ExpDB.hpp:51

References _base_exp_group_db, _job_exp_group_db, and Horizon::Zone::EXP_GROUP_TYPE_BASE.

◆ get_instance()

static ExpDatabase * Horizon::Zone::ExpDatabase::get_instance ( )
inlinestatic
62 {
63 static ExpDatabase instance;
64 return &instance;
65 }
ExpDatabase()
Definition: ExpDB.hpp:58

◆ get_status_point()

uint32_t Horizon::Zone::ExpDatabase::get_status_point ( uint32_t  level)
inline
75 {
76 if (level <= 0 || level > _stat_point_db.size() || level > MAX_LEVEL)
77 return 0;
78 return _stat_point_db.at(level);
79 }
#define MAX_LEVEL
Definition: Horizon.hpp:48
LockedLookupTable< uint32_t, uint32_t > _stat_point_db
Definition: ExpDB.hpp:87
Value at(Key const &key, Value const &default_value=Value()) const
Definition: LockedLookupTable.hpp:63
std::size_t size()
Definition: LockedLookupTable.hpp:96

References _stat_point_db, LockedLookupTable< Key, Value, Hash >::at(), MAX_LEVEL, and LockedLookupTable< Key, Value, Hash >::size().

+ Here is the call graph for this function:

◆ load()

bool ExpDatabase::load ( )
37{
38 sol::state lua;
39 int total_entries[2] = { 0, 0 };
40 std::string tmp_string;
41 std::string file_path = sZone->config().get_static_db_path().string() + "exp_group_db.lua";
42
43 // Read the file. If there is an error, report it and exit.
44 try {
45 lua.script_file(file_path);
46 sol::table base_exp_tbl = lua["base_exp_group_db"];
47 sol::table job_exp_tbl = lua["job_exp_group_db"];
48 total_entries[0] = load_group(base_exp_tbl, EXP_GROUP_TYPE_BASE);
49 total_entries[1] = load_group(job_exp_tbl, EXP_GROUP_TYPE_JOB);
50 } catch(const std::exception &e) {
51 HLog(error) << "ExpDB::error: " << e.what();
52 return false;
53 }
54
55 HLog(info) << "Read " << total_entries[0] << " Base and " << total_entries[1] << " Job EXP groups from '" << file_path << "'";
56
57 return true;
58}
#define HLog(type)
Definition: Logger.hpp:122
#define sZone
Definition: Zone.hpp:247
int load_group(sol::table &tbl, exp_group_type type)
Definition: ExpDB.cpp:60
@ EXP_GROUP_TYPE_JOB
Definition: ExpDB.hpp:52

References Horizon::Zone::EXP_GROUP_TYPE_BASE, Horizon::Zone::EXP_GROUP_TYPE_JOB, HLog, load_group(), and sZone.

+ Here is the call graph for this function:

◆ load_group()

int ExpDatabase::load_group ( sol::table &  tbl,
exp_group_type  type 
)
protected
61{
63 int total_entries = 0;
64
65 group_tbl.for_each([group_db, &total_entries, type](sol::object const &key, sol::object const &value) {
66 std::string group_name = key.as<std::string>();
67 sol::table tbl = value.as<sol::table>();
68 exp_group_data expd;
69
70 std::shared_ptr<const exp_group_data> dup;
71 if ((dup = group_db->at(group_name)) != nullptr) {
72 HLog(warning) << "ExpDB::load: Found duplicate " << (type == EXP_GROUP_TYPE_BASE ? "base" : "job") << " Exp group for '" << group_name << "', overwriting...";
73 group_db->erase(group_name);
74 }
75
76 expd.max_level = tbl.get_or("MaxLevel", 0);
77 if (expd.max_level == 0) {
78 HLog(error) << "ExpDB::load: Max Level not given for group '" << group_name << "', skipping...";
79 return;
80 }
81
82 sol::optional<sol::table> maybe_exp_tbl = tbl.get<sol::optional<sol::table>>("Exp");
83 if (!maybe_exp_tbl) {
84 HLog(error) << "ExpDB::load: Missing Exp data for group '" << group_name << "', skipping...";
85 return;
86 }
87
88 sol::table &exp_tbl = maybe_exp_tbl.value();
89 exp_tbl.for_each([&expd, &group_name](sol::object const &key, sol::object const &value) {
90 if (key.get_type() != sol::type::number) {
91 HLog(error) << "ExpDB::load: Invalid Exp data found in array of group '" << group_name << "', aborting with '" << key.as<int>() << "' entries...";
92 return;
93 }
94 expd.exp.push_back(value.as<int>());
95 });
96
97 group_db->insert(group_name, std::make_shared<exp_group_data>(expd));
98 total_entries++;
99 });
100
101 return total_entries;
102}
Definition: LockedLookupTable.hpp:44
void insert(const Key &key, const Value &value)
Definition: LockedLookupTable.hpp:68
void erase(const Key &key)
Definition: LockedLookupTable.hpp:73
Definition: ExpDB.hpp:44

References _base_exp_group_db, _job_exp_group_db, LockedLookupTable< Key, Value, Hash >::at(), LockedLookupTable< Key, Value, Hash >::erase(), Horizon::Zone::EXP_GROUP_TYPE_BASE, HLog, and LockedLookupTable< Key, Value, Hash >::insert().

Referenced by load().

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

◆ load_status_point_table()

bool ExpDatabase::load_status_point_table ( )
105{
106 sol::state lua;
107 int total_entries = 0;
108 std::string tmp_string;
109 std::string file_path = sZone->config().get_static_db_path().string() + "status_points.lua";
110
111 // Read the file. If there is an error, report it and exit.
112 try {
113 lua.script_file(file_path);
114 sol::table status_points_tbl = lua["status_points"];
115 status_points_tbl.for_each([this, &file_path, &total_entries](sol::object const &key, sol::object const &value) {
116 if (key.get_type() != sol::type::number || value.get_type() != sol::type::number) {
117 HLog(error) << "Non-numeric key/value pair was found in '" << file_path << "'. Skipping...";
118 return;
119 }
120 _stat_point_db.insert(key.as<uint32_t>(), value.as<uint32_t>());
121 total_entries++;
122 });
123 } catch(const std::exception &e) {
124 HLog(error) << "ExpDatabase::load_status_point_table: " << e.what() << ".";
125 return false;
126 }
127
128 HLog(info) << "Read status points for " << total_entries << " levels from '" << file_path << "'";
129
130 return true;
131}

References _stat_point_db, HLog, LockedLookupTable< Key, Value, Hash >::insert(), and sZone.

+ Here is the call graph for this function:

Member Data Documentation

◆ _base_exp_group_db

LockedLookupTable<std::string, std::shared_ptr<const exp_group_data> > Horizon::Zone::ExpDatabase::_base_exp_group_db
protected

Referenced by get_exp_group(), and load_group().

◆ _job_exp_group_db

LockedLookupTable<std::string, std::shared_ptr<const exp_group_data> > Horizon::Zone::ExpDatabase::_job_exp_group_db
protected

Referenced by get_exp_group(), and load_group().

◆ _stat_point_db

LockedLookupTable<uint32_t, uint32_t> Horizon::Zone::ExpDatabase::_stat_point_db
protected

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