level.cpp
1.84 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
#include "level.h"
#include <lib_file_tab_txt.h>
#include <share_msg.pb.h>
vip_level_cfg_mgr_t* g_vip_level_cfg_mgr;
void vip_level_cfg_mgr_t::init()
{
this->level_exp_cfg_map.clear();
}
bool vip_level_cfg_mgr_t::load_cfg()
{
const std::string cfg_path = "./cfg/vip_level.txt";
el::lib_file_tab_txt_t file_tab_txt;
int ret = file_tab_txt.load(cfg_path.c_str());
if (0 != ret){
ALERT_LOG("open");
return false;
}
this->init();
{
uint32_t level_idx = 1;
uint32_t score_last = 0;
vip_level_cfg_t* pre_vip_level_cfg = NULL;
FOREACH(file_tab_txt.content_vector, it_content){
std::vector<std::string>& r = *it_content;
std::string str_def;
vip_level_cfg_t vlc;
vlc.level = file_tab_txt.get_val_def("level", r, 0);
if (0 == vlc.level || level_idx != vlc.level){
ALERT_LOG("[level:%u]", vlc.level);
return false;
}
vlc.exp = file_tab_txt.get_val_def("score", r, 0);
if (1 != vlc.level){
if (vlc.exp <= score_last){
ALERT_LOG("[score:%u]", vlc.exp);
return false;
}
} else {
if (0 != vlc.exp){
ALERT_LOG("[score:%u]", vlc.exp);
return false;
}
}
vlc.add_item_ret = file_tab_txt.get_val_def("add_item", r, 1.000000f);
vlc.add_vip_ret = file_tab_txt.get_val_def("add_vip", r, 1.000000f);
this->level_exp_cfg_map[vlc.level] = vlc;
if (1 < vlc.level){
vip_level_cfg_t& pre_vlc = this->level_exp_cfg_map[vlc.level-1];
pre_vlc.exp_end = vlc.exp - 1;
}
level_idx++;
score_last = vlc.exp;
}
}
return true;
}
bool vip_level_cfg_mgr_t::has_level( uint32_t level )
{
return this->level_exp_cfg_map.end() != this->level_exp_cfg_map.find(level);
}
vip_level_cfg_t* vip_level_cfg_mgr_t::find( uint32_t exp )
{
FOREACH(this->level_exp_cfg_map, it){
if (exp <= it->second.exp_end){
return &it->second;
}
}
return &this->level_exp_cfg_map.rbegin()->second;
}