上传价格组代码优化

This commit is contained in:
liwei 2023-07-12 17:24:54 +08:00
parent e182aae1a3
commit 99ee5e4f51

View File

@ -33,7 +33,7 @@ const (
game_food = "game_breakingbad.json" game_food = "game_breakingbad.json"
) )
///配置管理基础组件 // /配置管理基础组件
type MCompConfigure struct { type MCompConfigure struct {
cbase.ModuleCompBase cbase.ModuleCompBase
hlock sync.RWMutex hlock sync.RWMutex
@ -56,7 +56,7 @@ type MCompConfigure struct {
_price map[int32][]*cfg.GamePricegroupData _price map[int32][]*cfg.GamePricegroupData
} }
//组件初始化接口 // 组件初始化接口
func (this *MCompConfigure) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *MCompConfigure) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
err = this.ModuleCompBase.Init(service, module, comp, options) err = this.ModuleCompBase.Init(service, module, comp, options)
err = this.LoadConfigure(game_global, cfg.NewGameGlobal) err = this.LoadConfigure(game_global, cfg.NewGameGlobal)
@ -293,7 +293,7 @@ func (this *MCompConfigure) LoadConfigure(name string, fn interface{}) (err erro
return configure.RegisterConfigure(name, fn, nil) return configure.RegisterConfigure(name, fn, nil)
} }
//加载一个配置文件 // 加载一个配置文件
func (this *MCompConfigure) LoadDropData() { func (this *MCompConfigure) LoadDropData() {
if v, err := this.GetConfigure(game_drop); err == nil { if v, err := this.GetConfigure(game_drop); err == nil {
if configure, ok := v.(*cfg.GameDrop); ok { if configure, ok := v.(*cfg.GameDrop); ok {
@ -320,7 +320,7 @@ func (this *MCompConfigure) LoadDropData() {
return return
} }
//加载多个配置文件 // 加载多个配置文件
func (this *MCompConfigure) LoadMultiConfigure(confs map[string]interface{}) (err error) { func (this *MCompConfigure) LoadMultiConfigure(confs map[string]interface{}) (err error) {
for k, v := range confs { for k, v := range confs {
err = configure.RegisterConfigure(k, v, nil) err = configure.RegisterConfigure(k, v, nil)
@ -332,12 +332,12 @@ func (this *MCompConfigure) LoadMultiConfigure(confs map[string]interface{}) (er
return return
} }
//读取配置数据 // 读取配置数据
func (this *MCompConfigure) GetConfigure(name string) (v interface{}, err error) { func (this *MCompConfigure) GetConfigure(name string) (v interface{}, err error) {
return configure.GetConfigure(name) return configure.GetConfigure(name)
} }
//全局配置 // 全局配置
func (this *MCompConfigure) GetGlobalConf() *cfg.GameGlobalData { func (this *MCompConfigure) GetGlobalConf() *cfg.GameGlobalData {
var ( var (
configure *cfg.GameGlobal configure *cfg.GameGlobal
@ -492,7 +492,7 @@ func (this *MCompConfigure) GetHeroConfigData() (data []*cfg.GameHeroData) {
return nil return nil
} }
//读取物品配置 // 读取物品配置
func (this *MCompConfigure) GetItemConfigureData(id string) (item *cfg.GameItemData, err error) { func (this *MCompConfigure) GetItemConfigureData(id string) (item *cfg.GameItemData, err error) {
var ( var (
v interface{} v interface{}
@ -597,7 +597,7 @@ func (this *MCompConfigure) GetPriceGroupCost(pricegroupId int32, purchase int32
return return
} }
for _, v := range this._price[pricegroupId] { for _, v := range this._price[pricegroupId] {
if v.Purchasemin <= purchase && purchase <= v.Purchasemax { if v.Purchasemin <= purchase && (purchase <= v.Purchasemax || v.Purchasemax == -1) {
res = v.Cost res = v.Cost
return return
} }
@ -609,8 +609,12 @@ func (this *MCompConfigure) GetPriceGroupLen(pricegroupId int32) (count int32, e
if _, ok := this._price[pricegroupId]; !ok { if _, ok := this._price[pricegroupId]; !ok {
err = comm.NewNotFoundConfErr("tools", game_price, pricegroupId) err = comm.NewNotFoundConfErr("tools", game_price, pricegroupId)
} }
count = int32(len(this._price[pricegroupId])) count = 0
for _, v := range this._price[pricegroupId] {
if count < v.Purchasemax {
count = v.Purchasemax
}
}
return return
} }