forked from cherry-game/cherry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrop_config.go
74 lines (59 loc) · 1.39 KB
/
drop_config.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
package main
import (
"github.com/ahmetb/go-linq/v3"
cerr "github.com/cherry-game/cherry/error"
"github.com/cherry-game/cherry/extend/mapstructure"
)
type (
DropConfig struct {
DropId int `json:"dropId"`
ItemType int `json:"itemType"`
ItemId int `json:"itemId"`
Num int `json:"num"`
DropType int `json:"dropType"`
DropValue int `json:"dropValue"`
Desc string `json:"desc"`
}
DropConfigs struct {
list []*DropConfig
}
)
func (d *DropConfigs) Name() string {
return "dropConfig"
}
func (d *DropConfigs) Init() {
}
func (d *DropConfigs) OnLoad(maps interface{}, reload bool) (int, error) {
list, ok := maps.([]interface{})
if ok == false {
return 0, cerr.Error("maps convert to []interface{} error.")
}
if reload {
d.list = d.list[0:0]
}
for _, data := range list {
var item DropConfig
err := cherryMapStructure.Decode(data, &item)
if err == nil {
d.list = append(d.list, &item)
}
}
return len(list), nil
}
func (d *DropConfigs) OnAfterLoad(reload bool) {
}
func (d *DropConfigs) Get(dropId int) *DropConfig {
for _, config := range d.list {
if config.DropId == dropId {
return config
}
}
return nil
}
func (d *DropConfigs) GetItemTypeList(itemType int) []*DropConfig {
var c []*DropConfig
linq.From(d.list).Where(func(i interface{}) bool {
return i.(*DropConfig).ItemType == itemType
}).ToSlice(&c)
return c
}