216 lines
5.4 KiB
Go
216 lines
5.4 KiB
Go
package modules
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/core/cbase"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"sync"
|
|
)
|
|
|
|
const (
|
|
game_global = "game_global.json" //全局配置表
|
|
game_initial = "game_initial.json" //初始化表
|
|
game_playerlv = "game_playerlv.json" //玩家等级
|
|
game_facemod = "game_facemod.json" // 形象配置表
|
|
game_drop = "game_drop.json" //掉落
|
|
)
|
|
|
|
///配置管理基础组件
|
|
type MCompConfigure struct {
|
|
cbase.ModuleCompBase
|
|
hlock sync.RWMutex
|
|
_dropMap map[int32][]*cfg.GameDropData // 掉落表 key 是DiropId
|
|
}
|
|
|
|
//组件初始化接口
|
|
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.LoadConfigure(game_global, cfg.NewGameGlobal)
|
|
err = this.LoadConfigure(game_initial, cfg.NewGameInitial)
|
|
err = this.LoadConfigure(game_playerlv, cfg.NewGamePlayerlv)
|
|
err = this.LoadConfigure(game_facemod, cfg.NewGameFacemod)
|
|
this._dropMap = make(map[int32][]*cfg.GameDropData, 0)
|
|
configure.RegisterConfigure(game_drop, cfg.NewGameDrop, this.LoadDropData)
|
|
return
|
|
}
|
|
func (this *MCompConfigure) LoadConfigure(name string, fn interface{}) (err error) {
|
|
return configure.RegisterConfigure(name, fn, nil)
|
|
}
|
|
|
|
//加载一个配置文件
|
|
func (this *MCompConfigure) LoadDropData() {
|
|
if v, err := this.GetConfigure(game_drop); err == nil {
|
|
if configure, ok := v.(*cfg.GameDrop); ok {
|
|
this.hlock.Lock()
|
|
defer this.hlock.Unlock()
|
|
for _, value := range configure.GetDataList() {
|
|
this._dropMap[value.Dropid] = append(this._dropMap[value.Dropid], value)
|
|
}
|
|
return
|
|
}
|
|
} else {
|
|
log.Errorf("get game_pagoda conf err:%v", err)
|
|
}
|
|
return
|
|
}
|
|
|
|
//加载多个配置文件
|
|
func (this *MCompConfigure) LoadMultiConfigure(confs map[string]interface{}) (err error) {
|
|
for k, v := range confs {
|
|
err = configure.RegisterConfigure(k, v, nil)
|
|
if err != nil {
|
|
log.Errorf("配置文件:%s解析失败!", k)
|
|
break
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//读取配置数据
|
|
func (this *MCompConfigure) GetConfigure(name string) (v interface{}, err error) {
|
|
return configure.GetConfigure(name)
|
|
}
|
|
|
|
//全局配置
|
|
func (this *MCompConfigure) GetGlobalConf() *cfg.GameGlobalData {
|
|
var (
|
|
configure *cfg.GameGlobal
|
|
ok bool
|
|
)
|
|
if v, err := this.GetConfigure(game_global); err != nil {
|
|
log.Errorf("get global conf err:%v", err)
|
|
return nil
|
|
} else {
|
|
if configure, ok = v.(*cfg.GameGlobal); !ok {
|
|
log.Errorf("%T no is *cfg.Game_global", v)
|
|
return nil
|
|
}
|
|
}
|
|
return configure.GetDataList()[0] // 返回对象信息
|
|
}
|
|
|
|
func (this *MCompConfigure) GetGlobalInitConf() (configure *cfg.GameInitial, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_initial); err != nil {
|
|
return
|
|
} else {
|
|
if configure, ok = v.(*cfg.GameInitial); !ok {
|
|
err = fmt.Errorf("%T no is *cfg.Game_comInitial", v)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 主角等级经验配置列表
|
|
func (this *MCompConfigure) GetPlayerlvConfList() (list []*cfg.GamePlayerlvData) {
|
|
if v, err := this.GetConfigure(game_playerlv); err != nil {
|
|
return
|
|
} else {
|
|
if configure, ok := v.(*cfg.GamePlayerlv); !ok {
|
|
err = fmt.Errorf("%T no is *cfg.Game_playerlv", v)
|
|
return
|
|
} else {
|
|
if configure != nil {
|
|
list = configure.GetDataList()
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 玩家等级经验配置表
|
|
func (this *MCompConfigure) GetPlayerlvConf(lv int32) (data *cfg.GamePlayerlvData) {
|
|
if v, err := this.GetConfigure(game_playerlv); err != nil {
|
|
return
|
|
} else {
|
|
if configure, ok := v.(*cfg.GamePlayerlv); !ok {
|
|
err = fmt.Errorf("%T no is *cfg.Game_playerlv", v)
|
|
return
|
|
} else {
|
|
if configure != nil {
|
|
data = configure.GetDataMap()[lv]
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 玩家形象预设配置
|
|
func (this *MCompConfigure) GetPlayerFigureConf() (list []*cfg.GameFacemodData) {
|
|
if v, err := this.GetConfigure(game_facemod); err != nil {
|
|
return
|
|
} else {
|
|
if configure, ok := v.(*cfg.GameFacemod); !ok {
|
|
err = fmt.Errorf("%T no is *cfg.Game_playerlv", v)
|
|
return
|
|
} else {
|
|
if configure != nil {
|
|
list = configure.GetDataList()
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *MCompConfigure) GetDropData(dropId int32) (data []*cfg.GameDropData) {
|
|
data = this._dropMap[dropId]
|
|
return
|
|
}
|
|
|
|
// todo 调用drop 表 获取掉落信息
|
|
func (this *MCompConfigure) GetMultipleDropReward(count, dropId int32, items []*pb.UserAssets) (resData []*pb.UserAssets) {
|
|
res := make([]*cfg.Gameatn, 0)
|
|
|
|
for i := 0; i < int(count); i++ {
|
|
data := this.GetDropData(dropId)
|
|
szW := make([]int32, 0)
|
|
for _, value := range data {
|
|
szW = append(szW, value.P)
|
|
}
|
|
if len(szW) > 0 {
|
|
index := comm.GetRandW(szW)
|
|
res = append(res, data[index].Prize...)
|
|
}
|
|
}
|
|
for _, v := range res {
|
|
bFind := false
|
|
for _, v1 := range items {
|
|
if v.A == v1.A && v.T == v1.T {
|
|
v1.N += v.N
|
|
bFind = true
|
|
}
|
|
}
|
|
if !bFind {
|
|
items = append(items, &pb.UserAssets{
|
|
A: v.A,
|
|
T: v.T,
|
|
N: v.N,
|
|
})
|
|
}
|
|
}
|
|
resData = append(resData, items...)
|
|
return
|
|
}
|
|
func (this *MCompConfigure) GetDropReward(dropId int32, Items []*cfg.Gameatn) {
|
|
Items = make([]*cfg.Gameatn, 0)
|
|
|
|
data := this.GetDropData(dropId)
|
|
szW := make([]int32, 0)
|
|
for _, value := range data {
|
|
szW = append(szW, value.P)
|
|
}
|
|
index := comm.GetRandW(szW)
|
|
Items = append(Items, data[index].Prize...)
|
|
|
|
return
|
|
}
|