316 lines
8.2 KiB
Go
316 lines
8.2 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/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"sync"
|
|
)
|
|
|
|
const (
|
|
//game_gamecolor = "game_gamecolor.json" //颜色表
|
|
game_playerlv = "game_playerlv.json" //玩家等级
|
|
//game_facemod = "game_facemod.json" //形象配置表
|
|
game_drop = "game_drop.json" //掉落
|
|
new_hero = "game_hero.json"
|
|
// 签到
|
|
game_signreset = "game_signreset.json"
|
|
game_sign = "game_sign.json"
|
|
|
|
game_item = "game_item.json"
|
|
game_vip = "game_vip.json"
|
|
|
|
game_equip = "game_equip.json" //装备信息表
|
|
|
|
)
|
|
|
|
///配置管理基础组件
|
|
type MCompConfigure struct {
|
|
cbase.ModuleCompBase
|
|
module core.IModule
|
|
hlock sync.RWMutex
|
|
_dropMap map[int32][]*cfg.GameDropData // 掉落表 key 是DiropId
|
|
_sign map[int32]*cfg.GameSignData
|
|
}
|
|
|
|
//组件初始化接口
|
|
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)
|
|
this.module = module
|
|
//err = this.LoadConfigure(game_gamecolor, cfg.NewGameGameColor)
|
|
err = this.LoadConfigure(new_hero, cfg.NewGameHero)
|
|
err = this.LoadConfigure(game_playerlv, cfg.NewGamePlayerlv)
|
|
//err = this.LoadConfigure(game_facemod, cfg.NewGameFacemod)
|
|
err = this.LoadConfigure(game_signreset, cfg.NewGameSignReset)
|
|
err = this.LoadConfigure(game_equip, cfg.NewGameEquip)
|
|
//err = this.LoadConfigure(game_sign, cfg.NewGameSign)
|
|
err = this.LoadConfigure(game_item, cfg.NewGameItem)
|
|
err = this.LoadConfigure(game_vip, cfg.NewGameVip)
|
|
this._dropMap = make(map[int32][]*cfg.GameDropData, 0)
|
|
this._sign = make(map[int32]*cfg.GameSignData, 0)
|
|
configure.RegisterConfigure(game_drop, cfg.NewGameDrop, this.LoadDropData)
|
|
configure.RegisterConfigure(game_sign, cfg.NewGameSign, this.LoadSignData)
|
|
|
|
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() {
|
|
|
|
if value.Condition == 0 {
|
|
this._dropMap[value.Dropid] = append(this._dropMap[value.Dropid], value)
|
|
} else {
|
|
key := value.Condition
|
|
key = value.Dropid*100 + key
|
|
this._dropMap[key] = append(this._dropMap[key], value)
|
|
for _, v1 := range this._dropMap[value.Dropid] {
|
|
this._dropMap[key] = append(this._dropMap[key], v1)
|
|
}
|
|
}
|
|
}
|
|
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) 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) (conf *cfg.GamePlayerlvData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_playerlv); err != nil {
|
|
return
|
|
} else {
|
|
if conf, ok = v.(*cfg.GamePlayerlv).GetDataMap()[lv]; !ok {
|
|
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_playerlv, lv)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *MCompConfigure) GetDropData(dropId int32) (data []*cfg.GameDropData) {
|
|
data = this._dropMap[dropId]
|
|
return
|
|
}
|
|
|
|
func (this *MCompConfigure) GetDropReward(dropId int32) (result []*cfg.Gameatn) {
|
|
result = make([]*cfg.Gameatn, 0)
|
|
|
|
data := this.GetDropData(dropId)
|
|
if len(data) == 0 {
|
|
return
|
|
}
|
|
szW := make([]int32, 0)
|
|
for _, value := range data {
|
|
szW = append(szW, value.P)
|
|
}
|
|
index := comm.GetRandW(szW)
|
|
result = append(result, data[index].Prize...)
|
|
|
|
return
|
|
}
|
|
|
|
// 获取英雄原始星级
|
|
func (this *MCompConfigure) GetHeroConfig(heroCfgId string) (conf *cfg.GameHeroData, err error) {
|
|
var (
|
|
v interface{}
|
|
)
|
|
if v, err = this.GetConfigure(new_hero); err == nil {
|
|
if configure, ok := v.(*cfg.GameHero); ok {
|
|
if conf, ok = configure.GetDataMap()[heroCfgId]; !ok {
|
|
err = comm.NewNotFoundConfErr("gourmet", new_hero, heroCfgId)
|
|
}
|
|
return
|
|
}
|
|
}
|
|
err = comm.NewNotFoundConfErr("gourmet", new_hero, heroCfgId)
|
|
return
|
|
}
|
|
|
|
// 获取英雄原始星级
|
|
func (this *MCompConfigure) GetHeroConfigStar(heroCfgId string) int32 {
|
|
if v, err := this.GetConfigure(new_hero); err == nil {
|
|
if configure, ok := v.(*cfg.GameHero); ok {
|
|
if v, ok := configure.GetDataMap()[heroCfgId]; ok {
|
|
return v.Star
|
|
}
|
|
}
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// 获取签到信息
|
|
func (this *MCompConfigure) GetSignConf(day, group int32) *cfg.GameSignData {
|
|
if v, ok := this._sign[day<<8+group]; ok {
|
|
return v
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// 获取组id
|
|
func (this *MCompConfigure) GetSignResetConf(id int32) int32 {
|
|
if v, err := this.GetConfigure(game_signreset); err == nil {
|
|
if configure, ok := v.(*cfg.GameSignReset); ok {
|
|
if configure != nil {
|
|
return configure.Get(id).Groups
|
|
}
|
|
}
|
|
}
|
|
return -1
|
|
}
|
|
func (this *MCompConfigure) LoadSignData() {
|
|
if v, err := this.GetConfigure(game_sign); err == nil {
|
|
if configure, ok := v.(*cfg.GameSign); ok {
|
|
this.hlock.Lock()
|
|
defer this.hlock.Unlock()
|
|
for _, value := range configure.GetDataList() {
|
|
this._sign[value.Day<<8+value.Group] = value
|
|
}
|
|
return
|
|
}
|
|
} else {
|
|
log.Errorf("get game_sign conf err:%v", err)
|
|
}
|
|
return
|
|
}
|
|
func (this *MCompConfigure) GetHeroConfigData() (data []*cfg.GameHeroData) {
|
|
if v, err := this.GetConfigure(new_hero); err == nil {
|
|
if configure, ok := v.(*cfg.GameHero); ok {
|
|
return configure.GetDataList()
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
//读取物品配置
|
|
func (this *MCompConfigure) GetItemConfigureData(id string) (item *cfg.GameItemData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_item); err != nil {
|
|
log.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
if item, ok = v.(*cfg.GameItem).GetDataMap()[id]; !ok {
|
|
err = fmt.Errorf("no found item:%s configure", id)
|
|
log.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *MCompConfigure) GetVipConfigureData(lv int32) (item *cfg.GameVipData) {
|
|
|
|
if v, err := this.GetConfigure(game_vip); err == nil {
|
|
|
|
if configure, ok := v.(*cfg.GameVip); ok {
|
|
item = configure.Get(lv)
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (this *MCompConfigure) GetItemConfigureByType(useType int32) (item []*cfg.GameItemData) {
|
|
if v, err := this.GetConfigure(game_item); err == nil {
|
|
for _, v1 := range v.(*cfg.GameItem).GetDataMap() {
|
|
if v1.Usetype == useType {
|
|
item = append(item, v1)
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *MCompConfigure) GetItemConfigureByBagType(bagType int32) (item []*cfg.GameItemData) {
|
|
if v, err := this.GetConfigure(game_item); err == nil {
|
|
for _, v1 := range v.(*cfg.GameItem).GetDataMap() {
|
|
if v1.Bagtype == bagType {
|
|
item = append(item, v1)
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
func (this *MCompConfigure) GetEquipmentConfigureById(equipmentId string) (configure *cfg.GameEquipData) {
|
|
|
|
if v, err := this.GetConfigure(game_equip); err == nil {
|
|
configure = v.(*cfg.GameEquip).Get(equipmentId)
|
|
return
|
|
}
|
|
return
|
|
}
|
|
func (this *MCompConfigure) GetAllItemConfigure() (item []*cfg.GameItemData) {
|
|
if v, err := this.GetConfigure(game_item); err == nil {
|
|
for _, v1 := range v.(*cfg.GameItem).GetDataMap() {
|
|
item = append(item, v1)
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *MCompConfigure) GetAllEquipmentConfigure() (configure []*cfg.GameEquipData) {
|
|
|
|
if v, err := this.GetConfigure(game_equip); err == nil {
|
|
for _, v1 := range v.(*cfg.GameEquip).GetDataMap() {
|
|
configure = append(configure, v1)
|
|
}
|
|
return
|
|
}
|
|
return
|
|
}
|