199 lines
5.8 KiB
Go
199 lines
5.8 KiB
Go
package exclusive
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"sync"
|
|
|
|
"go_dreamfactory/lego/core"
|
|
)
|
|
|
|
const (
|
|
game_exclusiveweapon = "game_exclusiveweapon.json" //装备信息表
|
|
game_exclusiveupgrade = "game_exclusiveupgrade.json" //装备信息表
|
|
game_exclusivestar = "game_exclusivestar.json" //装备信息表
|
|
game_exclusiverack = "game_exclusiverank.json" //装备信息表
|
|
game_exclusiveitem = "game_exclusiveitem.json" //经验道具
|
|
)
|
|
|
|
// /背包配置管理组件
|
|
type configureComp struct {
|
|
modules.MCompConfigure
|
|
module *Exclusive
|
|
lock sync.RWMutex
|
|
lvs map[string][]*cfg.GameExclusiveUpgradeData
|
|
stars map[string][]*cfg.GameExclusiveStarData
|
|
ranks map[string][]*cfg.GameExclusiveRankData
|
|
}
|
|
|
|
// 组件初始化接口
|
|
func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.MCompConfigure.Init(service, module, comp, options)
|
|
this.module = module.(*Exclusive)
|
|
this.LoadConfigure(game_exclusiveweapon, cfg.NewGameExclusiveWeapon)
|
|
this.LoadConfigure(game_exclusiveitem, cfg.NewGameExclusiveItem)
|
|
//等级
|
|
configure.RegisterConfigure(game_exclusiveupgrade, cfg.NewGameExclusiveUpgrade, func() {
|
|
this.lock.Lock()
|
|
if v, err := this.GetConfigure(game_exclusiveupgrade); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
this.lvs = make(map[string][]*cfg.GameExclusiveUpgradeData)
|
|
for _, v := range v.(*cfg.GameExclusiveUpgrade).GetDataList() {
|
|
if this.lvs[v.Weaponid] == nil {
|
|
this.lvs[v.Weaponid] = make([]*cfg.GameExclusiveUpgradeData, 0)
|
|
}
|
|
this.lvs[v.Weaponid] = append(this.lvs[v.Weaponid], v)
|
|
}
|
|
}
|
|
this.lock.Unlock()
|
|
})
|
|
//星级
|
|
configure.RegisterConfigure(game_exclusivestar, cfg.NewGameExclusiveStar, func() {
|
|
this.lock.Lock()
|
|
if v, err := this.GetConfigure(game_exclusivestar); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
this.stars = make(map[string][]*cfg.GameExclusiveStarData)
|
|
for _, v := range v.(*cfg.GameExclusiveStar).GetDataList() {
|
|
if this.stars[v.Weaponid] == nil {
|
|
this.stars[v.Weaponid] = make([]*cfg.GameExclusiveStarData, 0)
|
|
}
|
|
this.stars[v.Weaponid] = append(this.stars[v.Weaponid], v)
|
|
}
|
|
}
|
|
this.lock.Unlock()
|
|
})
|
|
//星级
|
|
configure.RegisterConfigure(game_exclusiverack, cfg.NewGameExclusiveRank, func() {
|
|
this.lock.Lock()
|
|
if v, err := this.GetConfigure(game_exclusiverack); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
this.ranks = make(map[string][]*cfg.GameExclusiveRankData)
|
|
for _, v := range v.(*cfg.GameExclusiveRank).GetDataList() {
|
|
if this.ranks[v.Weaponid] == nil {
|
|
this.ranks[v.Weaponid] = make([]*cfg.GameExclusiveRankData, 0)
|
|
}
|
|
this.ranks[v.Weaponid] = append(this.ranks[v.Weaponid], v)
|
|
}
|
|
}
|
|
this.lock.Unlock()
|
|
})
|
|
return
|
|
}
|
|
|
|
//获取全部资源
|
|
func (this *configureComp) GetAllGameExclusiveWeapon() (conf *cfg.GameExclusiveWeapon, err error) {
|
|
var (
|
|
v interface{}
|
|
)
|
|
if v, err = this.GetConfigure(game_exclusiveweapon); err == nil {
|
|
conf = v.(*cfg.GameExclusiveWeapon)
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取全部资源
|
|
func (this *configureComp) GetGameExclusiveWeapon(id string) (conf *cfg.GameExclusiveWeaponData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_exclusiveweapon); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
if conf, ok = v.(*cfg.GameExclusiveWeapon).GetDataMap()[id]; !ok {
|
|
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_exclusiveweapon, id)
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取全部资源
|
|
func (this *configureComp) GetGameExclusiveItem(id string) (conf *cfg.GameExclusiveItemData, err error) {
|
|
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_exclusiveitem); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
if conf, ok = v.(*cfg.GameExclusiveItem).GetDataMap()[id]; !ok {
|
|
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_exclusiveitem, id)
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取全部资源
|
|
func (this *configureComp) GetGameExclusiveUpgradeData(cid string, lv int32) (conf *cfg.GameExclusiveUpgradeData, err error) {
|
|
this.lock.RLock()
|
|
defer this.lock.RUnlock()
|
|
if _, ok := this.lvs[cid]; ok {
|
|
for _, v := range this.lvs[cid] {
|
|
if v.Lv == lv {
|
|
conf = v
|
|
return
|
|
}
|
|
}
|
|
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_exclusiveupgrade, fmt.Sprintf("%s-%d", cid, lv))
|
|
return
|
|
} else {
|
|
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_exclusiveupgrade, cid)
|
|
return
|
|
}
|
|
}
|
|
|
|
//获取全部资源
|
|
func (this *configureComp) GetGameExclusiveStarData(cid string, star int32) (conf *cfg.GameExclusiveStarData, err error) {
|
|
this.lock.RLock()
|
|
defer this.lock.RUnlock()
|
|
if _, ok := this.stars[cid]; ok {
|
|
for _, v := range this.stars[cid] {
|
|
if v.Star == star {
|
|
conf = v
|
|
return
|
|
}
|
|
}
|
|
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_exclusiveupgrade, fmt.Sprintf("%s-%d", cid, star))
|
|
return
|
|
} else {
|
|
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_exclusiveupgrade, cid)
|
|
return
|
|
}
|
|
}
|
|
|
|
//获取全部资源
|
|
func (this *configureComp) GetGameExclusiveRankData(cid string, rank int32) (conf *cfg.GameExclusiveRankData, err error) {
|
|
this.lock.RLock()
|
|
defer this.lock.RUnlock()
|
|
if _, ok := this.ranks[cid]; ok {
|
|
for _, v := range this.ranks[cid] {
|
|
if v.Rank == rank {
|
|
conf = v
|
|
return
|
|
}
|
|
}
|
|
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_exclusiveupgrade, fmt.Sprintf("%s-%d", cid, rank))
|
|
return
|
|
} else {
|
|
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_exclusiveupgrade, cid)
|
|
return
|
|
}
|
|
}
|