-
Notifications
You must be signed in to change notification settings - Fork 224
/
facility_conf.go
144 lines (121 loc) · 2.52 KB
/
facility_conf.go
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
package facility
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path"
"github.com/llr104/slgserver/config"
"github.com/llr104/slgserver/log"
"go.uber.org/zap"
)
const (
Main = 0 //主城
JiaoChang = 13 //校场
TongShuaiTing = 14 //统帅厅
JiShi = 15 //集市
MBS = 16 //募兵所
)
var FConf facilityConf
type conf struct {
Name string
Type int8
}
type facilityConf struct {
Title string `json:"title"`
List []conf `json:"list"`
facilitys map[int8]*facility
}
func (this *facilityConf) Load() {
this.facilitys = make(map[int8]*facility, 0)
jsonDir := config.File.MustValue("logic", "json_data", "../data/conf/")
fileName := path.Join(jsonDir, "facility", "facility.json")
jdata, err := ioutil.ReadFile(fileName)
if err != nil {
log.DefaultLog.Error("facilityConf load file error",
zap.Error(err),
zap.String("file", fileName))
os.Exit(0)
}
json.Unmarshal(jdata, this)
fdir := path.Join(jsonDir, "facility")
files, err := ioutil.ReadDir(fdir)
if err != nil{
return
}
for _, file := range files{
if file.IsDir(){
continue
}else{
if file.Name() == "facility.json" || file.Name() == "facility_addition.json"{
continue
}
fileName := path.Join(fdir, file.Name())
f := NewFacility(fileName)
this.facilitys[f.Type] = f
}
}
fmt.Println(this)
}
func (this *facilityConf) MaxLevel(fType int8) int8 {
f, ok := this.facilitys[fType]
if ok {
return int8(len(f.Levels))
}else{
return 0
}
}
func (this *facilityConf) Need(fType int8, level int8) (*NeedRes, bool) {
if level <= 0{
return nil, false
}
f, ok := this.facilitys[fType]
if ok {
if int8(len(f.Levels)) >= level {
return &f.Levels[level-1].Need, true
}else{
return nil, false
}
}else{
return nil, false
}
}
//升级需要的时间
func (this *facilityConf) CostTime(fType int8, level int8) int {
if level <= 0{
return 0
}
f, ok := this.facilitys[fType]
if ok {
if int8(len(f.Levels)) >= level {
return f.Levels[level-1].Time - 2 //比客户端快2s,保证客户端倒计时完一定是升级成功了
}else{
return 0
}
}else{
return 0
}
}
func (this *facilityConf) GetValues(fType int8, level int8) []int {
if level <= 0{
return []int{}
}
f, ok := this.facilitys[fType]
if ok {
if int8(len(f.Levels)) >= level {
return f.Levels[level-1].Values
}else{
return []int{}
}
}else{
return []int{}
}
}
func (this *facilityConf) GetAdditions(fType int8) []int8 {
f, ok := this.facilitys[fType]
if ok {
return f.Additions
}else{
return []int8{}
}
}