116 lines
3.1 KiB
Go
116 lines
3.1 KiB
Go
package tools
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
func NewModule() core.IModule {
|
|
m := new(Tools)
|
|
return m
|
|
}
|
|
|
|
type Tools struct {
|
|
modules.ModuleBase
|
|
configure *MCompConfigure
|
|
modelGlobal *modelGlobal
|
|
}
|
|
|
|
// 模块名
|
|
func (this *Tools) GetType() core.M_Modules {
|
|
return comm.ModuleTools
|
|
}
|
|
|
|
// 模块初始化接口 注册用户创建角色事件
|
|
func (this *Tools) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
|
err = this.ModuleBase.Init(service, module, options)
|
|
return
|
|
}
|
|
|
|
// 模块初始化接口 注册用户创建角色事件
|
|
func (this *Tools) Start() (err error) {
|
|
if err = this.ModuleBase.Start(); err != nil {
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// 装备组件
|
|
func (this *Tools) OnInstallComp() {
|
|
this.ModuleBase.OnInstallComp()
|
|
this.configure = this.RegisterComp(new(MCompConfigure)).(*MCompConfigure)
|
|
this.modelGlobal = this.RegisterComp(new(modelGlobal)).(*modelGlobal)
|
|
}
|
|
|
|
// 随机机器人
|
|
func (this *Tools) RandRobotConfig(num int32) (confs []*cfg.GameRobotData, err error) {
|
|
confs, err = this.configure.RandRobotConfig(num)
|
|
return
|
|
}
|
|
|
|
// 读取英雄配置
|
|
func (this *Tools) GetHeroConfig(heroCfgId string) (conf *cfg.GameHeroData, err error) {
|
|
conf, err = this.configure.GetHeroConfig(heroCfgId)
|
|
return
|
|
}
|
|
func (this *Tools) GetGroupDataByLottery(lotteryId int32, vipLv int32, lv int32) (items []*cfg.Gameatn) {
|
|
items = this.configure.GetGroupDataByLottery(lotteryId, vipLv, lv)
|
|
return
|
|
}
|
|
func (this *Tools) GetGroupDataByLotteryId(id int32) (data *cfg.GameLotteryData, err error) {
|
|
data = this.configure.GetLotterConfById(id)
|
|
if data == nil {
|
|
err = comm.NewNotFoundConfErr("game_lottery", game_lottery, id)
|
|
}
|
|
return
|
|
}
|
|
func (this *Tools) GetGlobalConf() *cfg.GameGlobalData {
|
|
return this.configure.GetGlobalConf()
|
|
}
|
|
func (this *Tools) GetPlayerlvConf(uid string) (conf *cfg.GamePlayerlvData, errdata *pb.ErrorData) {
|
|
var (
|
|
user *pb.DBUser
|
|
err error
|
|
)
|
|
if user, err = this.ModuleUser.GetUser(uid); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.String(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if conf, err = this.configure.GetPlayerlvConf(user.Lv); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.String(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *Tools) GetPriceGroupCost(pricegroupId int32, purchase int32) (res []*cfg.Gameatn, err error) {
|
|
return this.configure.GetPriceGroupCost(pricegroupId, purchase)
|
|
}
|
|
|
|
func (this *Tools) GetPriceGroupLen(pricegroupId int32) (count int32, err error) {
|
|
return this.configure.GetPriceGroupLen(pricegroupId)
|
|
}
|
|
|
|
func (this *Tools) GetGrormetLlame(id string) (data int32, err error) {
|
|
return this.configure.GetGrormetLlame(id)
|
|
}
|
|
|
|
func (this *Tools) GetGlobalData(key string, v interface{}) (err error) {
|
|
return this.modelGlobal.GetGlobalData(key, v)
|
|
}
|
|
|
|
func (this *Tools) UpdateGlobalData(key string, v interface{}) (err error) {
|
|
return this.modelGlobal.UpdateGlobalData(key, v)
|
|
}
|