This commit is contained in:
liwei1dao 2022-06-28 15:03:40 +08:00
commit ce2f052465
32 changed files with 415 additions and 217 deletions

View File

@ -38,7 +38,7 @@ func (r *Robot) AccountLogin() {
builders := []*builder{ builders := []*builder{
{ {
mainType: string(comm.SM_UserModule), mainType: string(comm.SM_UserModule),
subType: user.User_SubType_Login, subType: user.UserSubTypeLogin,
req: &pb.UserLoginReq{ req: &pb.UserLoginReq{
Account: r.opts.Account, Account: r.opts.Account,
Sid: r.opts.ServerId, Sid: r.opts.ServerId,

View File

@ -152,7 +152,7 @@ func (r *Robot) onUserLoaded() {
//notify //notify
r.RunNotify() r.RunNotify()
//user //user
// r.RunUser() r.RunUser()
//friend //friend
// r.RunFriend() // r.RunFriend()

View File

@ -11,9 +11,9 @@ var user_builders = []*builder{
{ {
//create //create
mainType: string(comm.SM_UserModule), mainType: string(comm.SM_UserModule),
subType: user.User_SubType_Create, subType: user.UserSubTypeCreate,
req: &pb.UserCreateReq{ //设置请求参数 req: &pb.UserCreateReq{ //设置请求参数
NickName: "测试", NickName: "乐谷6281",
}, },
rsp: &pb.UserCreateRsp{}, rsp: &pb.UserCreateRsp{},
enabled: true, enabled: true,

View File

@ -65,7 +65,15 @@ const (
) )
const ( const (
PropertyHp = 1 //生命 PropertyHp int32 = 1 //生命
PropertyAtk = 2 //攻击 PropertyAtk int32 = 2 //攻击
PropertyDef = 3 //防御 PropertyDef int32 = 3 //防御
)
const (
CardTypeHero int32 = 1 //英雄卡
CardTypeStar int32 = 2 //升星卡
CardTypeLevel int32 = 3 //升级卡
CardTypeSkill int32 = 4 //技能升级卡
CardTypeMonster int32 = 5 //怪物卡
) )

View File

@ -34,11 +34,11 @@ type (
//英雄 //英雄
IHero interface { IHero interface {
//查询用户卡片数量 //查询用户卡片数量
QueryCardAmount(uId string, cardId int32) (amount uint32) QueryHeroAmount(uId string, heroCfgId int32) (amount uint32)
//添加/减少卡片 //消耗卡片
AddCard(uId string, cardId int32, add int32) (code pb.ErrorCode) ChangeCard(uId string, heroCfgId int32, count int32) (code pb.ErrorCode)
//创建新英雄 //创建新英雄
CreatMultiHero(uid string, heroCfgId ...int32) error CreatHero(uid string, heroCfgId ...int32) error
// 获取英雄 // 获取英雄
// heroId 英雄ID // heroId 英雄ID

View File

@ -1,14 +1,14 @@
package core package core
type S_Category string //服务类别 例如 网关服务 游戏服务 业务服务 主要用于服务功能分类 type S_Category string //服务类别 例如 网关服务 游戏服务 业务服务 主要用于服务功能分类
type M_Modules string //模块类型 type M_Modules string //模块类型
type S_Comps string //服务器组件类型 type S_Comps string //服务器组件类型
type ErrorCode int32 //错误码 type ErrorCode int32 //错误码
type Event_Key string //事件Key type Event_Key string //事件Key
type Rpc_Key string //RPC type Rpc_Key string //RPC
type Redis_Key string //Redis缓存 type Redis_Key string //Redis缓存
type SqlTable string //数据库表定义 type SqlTable string //数据库表定义
type CustomRoute uint8 //自定义网关 type CustomRoute uint8 //自定义网关
const ( const (
AutoIp = "0.0.0.0" //自动ip 可以匹配任意ip地址 AutoIp = "0.0.0.0" //自动ip 可以匹配任意ip地址

View File

@ -85,13 +85,13 @@ func (this *DB_Comp) Model_UpdateDBByLog(uid string) (err error) {
log.Errorf("parameter len _id : %s,uid : %s d.len:%v", data.ID, data.UID, len(data.D)) log.Errorf("parameter len _id : %s,uid : %s d.len:%v", data.ID, data.UID, len(data.D))
continue continue
} }
_obj := bson.M{} _obj := make(bson.A, len(data.D[1].(bson.A)))
for _, v := range data.D[1].(bson.D) { for i, v := range data.D[1].(bson.A) {
_obj[v.Key] = v.Value _obj[i] = v
} }
_key := data.D[0].(string) _key := data.D[0].(string)
_, err := this.DB.InsertOne(core.SqlTable(_key), _obj) _, err := this.DB.InsertMany(core.SqlTable(_key), _obj)
if err != nil { if err != nil {
log.Errorf("insert %s db err:%v", (core.SqlTable(_key)), err) log.Errorf("insert %s db err:%v", (core.SqlTable(_key)), err)
ErrorLogCount[data.ID]++ ErrorLogCount[data.ID]++
@ -138,16 +138,17 @@ func (this *DB_Comp) Model_UpdateDBByLog(uid string) (err error) {
} }
_tableName := data.D[0].(string) //表名 _tableName := data.D[0].(string) //表名
Where := bson.M{} Where := data.D[1].(bson.M)
Query := bson.M{} Query := data.D[2].(bson.M)
for _, v := range data.D[1].(bson.D) { // for key, v := range data.D[1].(bson.M) {
Where[v.Key] = v.Value // //Where[v.Key] = v.Value
} // Where = v
for _, v := range data.D[2].(bson.D) { // }
Query[v.Key] = v.Value // for _, v := range data.D[2].(bson.M) {
// Query[v.Key] = v.Value
} // }
_, err = this.DB.UpdateMany(core.SqlTable(_tableName), Where, bson.M{"$set": Query}) _, err = this.DB.UpdateMany(core.SqlTable(_tableName), Where, bson.M{"$set": Query})
if err != nil { if err != nil {
log.Errorf("Update %s db err:%v", core.SqlTable(_tableName), err) log.Errorf("Update %s db err:%v", core.SqlTable(_tableName), err)

View File

@ -1,14 +1,16 @@
package hero package hero
import ( import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/modules" "go_dreamfactory/modules"
) )
type Api_Comp struct { type apiComp struct {
modules.MComp_GateComp modules.MComp_GateComp
service core.IService service core.IService
module *Hero moduleHero *Hero
user comm.IUser
} }
const ( //消息回复的头名称 const ( //消息回复的头名称
@ -18,14 +20,22 @@ const ( //消息回复的头名称
) )
//组件初始化接口 //组件初始化接口
func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.MComp_GateComp.Init(service, module, comp, options) this.MComp_GateComp.Init(service, module, comp, options)
this.module = module.(*Hero) this.moduleHero = module.(*Hero)
this.service = service this.service = service
return return
} }
func (this *Api_Comp) Start() (err error) { func (this *apiComp) Start() (err error) {
err = this.MComp_GateComp.Start() err = this.MComp_GateComp.Start()
var module core.IModule
if module, err = this.service.GetModule(comm.SM_UserModule); err != nil {
return
}
this.user = module.(comm.IUser)
return return
} }

View File

@ -2,21 +2,32 @@ package hero
import ( import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb" "go_dreamfactory/pb"
) )
//参数校验 //参数校验
func (this *Api_Comp) StrengthenUplv_Check(session comm.IUserSession, req *pb.Hero_StrengthenUplv_Req) (result map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) StrengthenUplv_Check(session comm.IUserSession, req *pb.Hero_StrengthenUplv_Req) (result map[string]interface{}, code comm.ErrorCode) {
if req.HeroObjID == "" { if req.HeroObjID == "" {
code.Code = pb.ErrorCode_ReqParameterError code.Code = pb.ErrorCode_ReqParameterError
return return
} }
_hero, err := this.module.model_hero.moduleHero.GetHeroInfoByObjID(req.HeroObjID) // 校验升级的对象是否存在 var (
curLv int32
curExp int32 // 当前英雄的经验
costGold int32 // 当前需要消耗金币的数量
addExp int32 // 需要增加的经验
//atn = map[string]interface{}{}
)
_hero, err := this.moduleHero.modelHero.moduleHero.GetHero(session.GetUserId(), req.HeroObjID) // 校验升级的对象是否存在
if err != 0 { if err != 0 {
code.Code = pb.ErrorCode_HeroNoExist code.Code = pb.ErrorCode_HeroNoExist
return return
} }
_expHero, err := this.module.model_hero.moduleHero.GetHeroInfoByObjID(req.ExpCardID) // 校验需要消耗经验卡牌的对象是否存在 _expHero, err := this.moduleHero.modelHero.moduleHero.GetHero(session.GetUserId(), req.ExpCardID) // 校验需要消耗经验卡牌的对象是否存在
if err != 0 { if err != 0 {
code.Code = pb.ErrorCode_HeroNoExist code.Code = pb.ErrorCode_HeroNoExist
return return
@ -25,12 +36,11 @@ func (this *Api_Comp) StrengthenUplv_Check(session comm.IUserSession, req *pb.He
code.Code = pb.ErrorCode_HeroNoExist code.Code = pb.ErrorCode_HeroNoExist
return return
} }
curLv := _hero.Lv curLv = _hero.Lv
curExp := _hero.Exp // 当前英雄的经验 curExp = _hero.Exp // 当前英雄的经验
var costGold int32 // 当前需要消耗金币的数量
var addExp int32 // 需要增加的经验
// 查询 本次消耗会获得多少经验 // 查询 本次消耗会获得多少经验
expConf := this.module.configure_comp.GetHeroExp(_expHero.HeroID) expConf := this.moduleHero.configure.GetHeroExp(_expHero.HeroID)
if expConf != nil { if expConf != nil {
addExp = expConf.Heroexp * req.Amount addExp = expConf.Heroexp * req.Amount
} }
@ -44,29 +54,39 @@ func (this *Api_Comp) StrengthenUplv_Check(session comm.IUserSession, req *pb.He
code.Code = pb.ErrorCode_HeroMaxLv code.Code = pb.ErrorCode_HeroMaxLv
return return
} }
if _data := this.module.configure_comp.GetHeroLv(curLv); _data != nil {
costGold += _data.Gold[0].N var maxLv int32 // 校验等级达到上限
maxLv = _hero.Star * comm.HeroStarLvRatio
_data := this.moduleHero.configure.GetHeroLv(curLv)
if _data != nil {
if maxLv >= _hero.Lv && curExp >= _data.Heroexp[0].N { // 加经验之前校验是否达到最大等级
code.Code = pb.ErrorCode_HeroMaxLv
return
}
curExp += addExp // 先把经验加上 curExp += addExp // 先把经验加上
// 当前升级需要消耗的经验 for { // 死循环判断一键升级
for { // 死循环判断一键升级
if _data.Heroexp[0].N <= curExp { // 升级操作 if maxLv >= _hero.Lv && curExp >= _data.Heroexp[0].N { // 设置最大经验和等级
curLv = maxLv
curExp = _data.Heroexp[0].N curExp = _data.Heroexp[0].N
if curExp >= 0 { // 大于下一级经验
curLv += 1 // 经验够了 那么等级+1
if _data := this.module.configure_comp.GetHeroLv(curLv); _data != nil {
if _data.Heroexp[0].N > curExp { // 经验不足则 直接返回
break
}
costGold += _data.Gold[0].N
} else {
break
}
}
} else {
break break
} }
if _data.Heroexp[0].N > curExp { // 经验不够升级则不能执行升级操作
break
} else { // 升级操作
curExp -= _data.Heroexp[0].N
curLv += 1 // 经验够了 那么等级+1
_data = this.moduleHero.configure.GetHeroLv(curLv)
if _data == nil { // 等级加失败了 回到原来的等级
curLv -= 1
break
}
costGold += _data.Gold[0].N // 统计 升级需要消耗金币的数量
}
} }
} else {
code.Code = pb.ErrorCode_HeroNoExist
return
} }
// 校验金币消耗 // 校验金币消耗
@ -74,18 +94,46 @@ func (this *Api_Comp) StrengthenUplv_Check(session comm.IUserSession, req *pb.He
"costGold": costGold, "costGold": costGold,
"curExp": curExp, "curExp": curExp,
"curLv": curLv, "curLv": curLv,
"addExp": addExp,
//"atn": atn,
} }
return return
} }
/// 英雄升级 /// 英雄升级
func (this *Api_Comp) StrengthenUplv(session comm.IUserSession, agrs map[string]interface{}, req *pb.Hero_StrengthenUplv_Req) (code pb.ErrorCode) { func (this *apiComp) StrengthenUplv(session comm.IUserSession, agrs map[string]interface{}, req *pb.Hero_StrengthenUplv_Req) (code pb.ErrorCode) {
var (
curLv int32
curExp int32 // 当前英雄的经验
costGold int32 // 当前需要消耗金币的数量
addExp int32 // 需要增加的经验
//atn = map[string]interface{}{}
)
defer func() { defer func() {
if code == pb.ErrorCode_Success { if code == pb.ErrorCode_Success {
session.SendMsg(string(this.module.GetType()), StrengthenUplv, &pb.Hero_StrengthenUplv_Resp{}) session.SendMsg(string(this.moduleHero.GetType()), StrengthenUplv, &pb.Hero_StrengthenUplv_Resp{})
} }
}() }()
costGold = agrs["costGold"].(int32)
curLv = agrs["curLv"].(int32)
curExp = agrs["curExp"].(int32)
addExp = agrs["addExp"].(int32)
log.Debugf("升级后当前等级: %d,经验: %d,需要消耗的金币: %d,增加的经验: %d", curLv, curExp, costGold, addExp)
// 执行升级逻辑
code = this.moduleHero.modelHero.moduleHero.AddCardExp(session.GetUserId(), req.HeroObjID, addExp) // 加经验
if code != pb.ErrorCode_Success {
return
}
// 消耗道具
code = this.user.AddAttributeValue(session.GetUserId(), "gold", -costGold) // 减少金币
if code != pb.ErrorCode_Success {
return
}
// 删除经验卡
code = this.moduleHero.modelHero.moduleHero.DelCard(req.ExpCardID, req.Amount)
if code != pb.ErrorCode_Success {
return
}
return return
} }

View File

@ -6,9 +6,9 @@ import (
) )
//参数校验 //参数校验
func (this *Api_Comp) Info_Check(session comm.IUserSession, req *pb.Hero_Info_Req) (result map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) Info_Check(session comm.IUserSession, req *pb.Hero_Info_Req) (result map[string]interface{}, code comm.ErrorCode) {
result = map[string]interface{}{} result = map[string]interface{}{}
hero := this.module.model_hero.getOneHero(session.GetUserId(), req.HeroId) hero := this.moduleHero.modelHero.getOneHero(session.GetUserId(), req.HeroId)
if hero == nil { if hero == nil {
code = comm.ErrorCode{Code: pb.ErrorCode_HeroNoExist} code = comm.ErrorCode{Code: pb.ErrorCode_HeroNoExist}
} }
@ -16,10 +16,10 @@ func (this *Api_Comp) Info_Check(session comm.IUserSession, req *pb.Hero_Info_Re
return return
} }
func (this *Api_Comp) Info(session comm.IUserSession, result map[string]interface{}, req *pb.Hero_Info_Req) (code pb.ErrorCode) { func (this *apiComp) Info(session comm.IUserSession, result map[string]interface{}, req *pb.Hero_Info_Req) (code pb.ErrorCode) {
rsp := &pb.Hero_Info_Rsp{} rsp := &pb.Hero_Info_Rsp{}
defer func() { defer func() {
err := session.SendMsg(string(this.module.GetType()), Hero_SubType_Info, rsp) err := session.SendMsg(string(this.moduleHero.GetType()), Hero_SubType_Info, rsp)
if err != nil { if err != nil {
code = pb.ErrorCode_SystemError code = pb.ErrorCode_SystemError
return return

View File

@ -6,21 +6,21 @@ import (
) )
//参数校验 //参数校验
func (this *Api_Comp) List_Check(session comm.IUserSession, req *pb.Hero_List_Req) (result map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) List_Check(session comm.IUserSession, req *pb.Hero_List_Req) (result map[string]interface{}, code comm.ErrorCode) {
return return
} }
func (this *Api_Comp) List(session comm.IUserSession, result map[string]interface{}, req *pb.Hero_List_Req) (code pb.ErrorCode) { func (this *apiComp) List(session comm.IUserSession, result map[string]interface{}, req *pb.Hero_List_Req) (code pb.ErrorCode) {
rsp := &pb.Hero_List_Rsp{} rsp := &pb.Hero_List_Rsp{}
defer func() { defer func() {
err := session.SendMsg(this.module.api_comp.service.GetType(), Hero_SubType_List, rsp) err := session.SendMsg(this.moduleHero.api.service.GetType(), Hero_SubType_List, rsp)
if err != nil { if err != nil {
code = pb.ErrorCode_SystemError code = pb.ErrorCode_SystemError
} }
}() }()
list, err := this.module.model_hero.getHeroList(session.GetUserId()) list, err := this.moduleHero.modelHero.getHeroList(session.GetUserId())
if err != nil { if err != nil {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return

View File

@ -18,12 +18,12 @@ const (
) )
///配置管理组件 ///配置管理组件
type Configure_Comp struct { type configureComp struct {
modules.MComp_Configure modules.MComp_Configure
} }
//组件初始化接口 //组件初始化接口
func (this *Configure_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
err = this.MComp_Configure.Init(service, module, comp, options) err = this.MComp_Configure.Init(service, module, comp, options)
err = this.LoadMultiConfigure(map[string]interface{}{ err = this.LoadMultiConfigure(map[string]interface{}{
@ -39,7 +39,7 @@ func (this *Configure_Comp) Init(service core.IService, module core.IModule, com
} }
//获取英雄配置数据 //获取英雄配置数据
func (this *Configure_Comp) getHeroConfigure() (configure *cfg.Game_newHero, err error) { func (this *configureComp) getHeroConfigure() (configure *cfg.Game_newHero, err error) {
var ( var (
v interface{} v interface{}
ok bool ok bool
@ -56,7 +56,7 @@ func (this *Configure_Comp) getHeroConfigure() (configure *cfg.Game_newHero, err
} }
// 获取英雄强化增加属性配置数据 // 获取英雄强化增加属性配置数据
func (this *Configure_Comp) GetHeroStargrowCon() (configure *cfg.Game_heroStargrow, err error) { func (this *configureComp) GetHeroStargrowCon() (configure *cfg.Game_heroStargrow, err error) {
var ( var (
v interface{} v interface{}
ok bool ok bool
@ -74,7 +74,7 @@ func (this *Configure_Comp) GetHeroStargrowCon() (configure *cfg.Game_heroStargr
} }
// 获取英雄升级属性变化相关配置数据 // 获取英雄升级属性变化相关配置数据
func (this *Configure_Comp) GetHeroLevelgrowCon() (configure *cfg.Game_heroLevelgrow, err error) { func (this *configureComp) GetHeroLevelgrowCon() (configure *cfg.Game_heroLevelgrow, err error) {
var ( var (
v interface{} v interface{}
ok bool ok bool
@ -90,7 +90,7 @@ func (this *Configure_Comp) GetHeroLevelgrowCon() (configure *cfg.Game_heroLevel
} }
// 获取英雄升星相关配置数据 // 获取英雄升星相关配置数据
func (this *Configure_Comp) GetHeroStarupCon() (configure *cfg.Game_heroStarup, err error) { func (this *configureComp) GetHeroStarupCon() (configure *cfg.Game_heroStarup, err error) {
var ( var (
v interface{} v interface{}
ok bool ok bool
@ -107,7 +107,7 @@ func (this *Configure_Comp) GetHeroStarupCon() (configure *cfg.Game_heroStarup,
} }
// 获取英雄升级相关配置数据 // 获取英雄升级相关配置数据
func (this *Configure_Comp) GetHeroLevelUpCon() (configure *cfg.Game_heroLevelup, err error) { func (this *configureComp) GetHeroLevelUpCon() (configure *cfg.Game_heroLevelup, err error) {
var ( var (
v interface{} v interface{}
ok bool ok bool
@ -123,7 +123,7 @@ func (this *Configure_Comp) GetHeroLevelUpCon() (configure *cfg.Game_heroLevelup
return return
} }
func (this *Configure_Comp) GetHeroExpCon() (configure *cfg.Game_heroExp, err error) { func (this *configureComp) GetHeroExpCon() (configure *cfg.Game_heroExp, err error) {
var ( var (
v interface{} v interface{}
ok bool ok bool
@ -138,7 +138,7 @@ func (this *Configure_Comp) GetHeroExpCon() (configure *cfg.Game_heroExp, err er
} }
return return
} }
func (this *Configure_Comp) GetHeroExp(hid int32) *cfg.Game_heroExpData { func (this *configureComp) GetHeroExp(hid int32) *cfg.Game_heroExpData {
if v, err := this.GetConfigure(hero_exp); err == nil { if v, err := this.GetConfigure(hero_exp); err == nil {
if configure, ok := v.(*cfg.Game_heroExp); !ok { if configure, ok := v.(*cfg.Game_heroExp); !ok {
@ -154,7 +154,7 @@ func (this *Configure_Comp) GetHeroExp(hid int32) *cfg.Game_heroExpData {
} }
//英雄等级基础属性 //英雄等级基础属性
func (this *Configure_Comp) GetHeroLevelup() (configure *cfg.Game_heroLevelup, err error) { func (this *configureComp) GetHeroLevelup() (configure *cfg.Game_heroLevelup, err error) {
var ( var (
v interface{} v interface{}
ok bool ok bool
@ -171,7 +171,7 @@ func (this *Configure_Comp) GetHeroLevelup() (configure *cfg.Game_heroLevelup, e
} }
//英雄品质系数 //英雄品质系数
func (this *Configure_Comp) GetHeroStargrow() (configure *cfg.Game_heroStargrow, err error) { func (this *configureComp) GetHeroStargrow() (configure *cfg.Game_heroStargrow, err error) {
var ( var (
v interface{} v interface{}
ok bool ok bool
@ -188,7 +188,7 @@ func (this *Configure_Comp) GetHeroStargrow() (configure *cfg.Game_heroStargrow,
} }
//获取英雄配置 //获取英雄配置
func (this *Configure_Comp) GetHero(heroId int32) *cfg.Game_newHeroData { func (this *configureComp) GetHero(heroId int32) *cfg.Game_newHeroData {
cfg, err := this.getHeroConfigure() cfg, err := this.getHeroConfigure()
if err != nil { if err != nil {
return nil return nil
@ -200,7 +200,7 @@ func (this *Configure_Comp) GetHero(heroId int32) *cfg.Game_newHeroData {
} }
//获取英雄星级配置 //获取英雄星级配置
func (this *Configure_Comp) GetHeroStar(star int32) *cfg.Game_heroStargrowData { func (this *configureComp) GetHeroStar(star int32) *cfg.Game_heroStargrowData {
cfg, err := this.GetHeroStargrow() cfg, err := this.GetHeroStargrow()
if err != nil { if err != nil {
return nil return nil
@ -213,7 +213,7 @@ func (this *Configure_Comp) GetHeroStar(star int32) *cfg.Game_heroStargrowData {
} }
//获取英雄等级配置 //获取英雄等级配置
func (this *Configure_Comp) GetHeroLv(lv int32) *cfg.Game_heroLevelupData { func (this *configureComp) GetHeroLv(lv int32) *cfg.Game_heroLevelupData {
cfg, err := this.GetHeroLevelup() cfg, err := this.GetHeroLevelup()
if err != nil { if err != nil {
return nil return nil
@ -225,7 +225,7 @@ func (this *Configure_Comp) GetHeroLv(lv int32) *cfg.Game_heroLevelupData {
} }
// 英雄成长系数 // 英雄成长系数
func (this *Configure_Comp) GetHeroLevelgrow() (configure *cfg.Game_heroLevelgrow, err error) { func (this *configureComp) GetHeroLevelgrow() (configure *cfg.Game_heroLevelgrow, err error) {
var ( var (
v interface{} v interface{}
ok bool ok bool
@ -242,7 +242,7 @@ func (this *Configure_Comp) GetHeroLevelgrow() (configure *cfg.Game_heroLevelgro
} }
//英雄成长配置 //英雄成长配置
func (this *Configure_Comp) GetHeroLvgrow(heroId int32) *cfg.Game_heroLevelgrowData { func (this *configureComp) GetHeroLvgrow(heroId int32) *cfg.Game_heroLevelgrowData {
cfg, err := this.GetHeroLevelgrow() cfg, err := this.GetHeroLevelgrow()
if err != nil { if err != nil {
return nil return nil

View File

@ -69,22 +69,22 @@ func TestMain(m *testing.M) {
//创建一个英雄s //创建一个英雄s
func TestCreateOneHero(t *testing.T) { func TestCreateOneHero(t *testing.T) {
err := module.model_hero.createOneHero("u1", 25001) err := module.modelHero.createOneHero("u1", 25001)
fmt.Println(err) fmt.Println(err)
} }
//获取玩家英雄 //获取玩家英雄
func TestGetOneHero(t *testing.T) { func TestGetOneHero(t *testing.T) {
d := module.model_hero.getOneHero("u1", "62b534bebf4745d4117acabe") d := module.modelHero.getOneHero("u1", "62b534bebf4745d4117acabe")
fmt.Printf("%v", d) fmt.Printf("%v", d)
} }
func TestPropertyCompute(t *testing.T) { func TestPropertyCompute(t *testing.T) {
m := module.model_hero.PropertyCompute("u1", "62b534bebf4745d4117acabe") m := module.modelHero.PropertyCompute("u1", "62b534bebf4745d4117acabe")
fmt.Println(m) fmt.Println(m)
} }
func TestHeroList(t *testing.T) { func TestHeroList(t *testing.T) {
heroes, err := module.model_hero.getHeroList("u1") heroes, err := module.modelHero.getHeroList("u1")
fmt.Printf("%v %v", heroes, err) fmt.Printf("%v %v", heroes, err)
} }

View File

@ -5,6 +5,7 @@ import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/log"
"go_dreamfactory/lego/sys/redis"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"math" "math"
@ -27,7 +28,7 @@ func (this *ModelHero) Init(service core.IService, module core.IModule, comp cor
//初始化英雄 //初始化英雄
func (this *ModelHero) initHero(uid string, heroCfgId int32) *pb.DB_HeroData { func (this *ModelHero) initHero(uid string, heroCfgId int32) *pb.DB_HeroData {
heroCfg := this.moduleHero.configure_comp.GetHero(heroCfgId) heroCfg := this.moduleHero.configure.GetHero(heroCfgId)
if heroCfg == nil { if heroCfg == nil {
log.Errorf("%v hero not found from config %v", heroCfgId) log.Errorf("%v hero not found from config %v", heroCfgId)
return nil return nil
@ -37,11 +38,12 @@ func (this *ModelHero) initHero(uid string, heroCfgId int32) *pb.DB_HeroData {
Id: objId, Id: objId,
Uid: uid, Uid: uid,
HeroID: heroCfg.Hid, HeroID: heroCfg.Hid,
Star: heroCfg.Star, Star: heroCfg.Star, //初始星级
Lv: 1, //初始等级 Lv: 1, //初始等级
NormalSkill: []*pb.SkillData{}, NormalSkill: []*pb.SkillData{}, //初始技能
Skins: []int32{}, Skins: []int32{},
EquipID: make([]string, 6), EquipID: make([]string, 6), //初始装备
AddProperty: make(map[int32]int32), AddProperty: make(map[int32]int32),
Energy: make(map[int32]int32), Energy: make(map[int32]int32),
Property: make(map[int32]int32), Property: make(map[int32]int32),
@ -53,38 +55,51 @@ func (this *ModelHero) initHero(uid string, heroCfgId int32) *pb.DB_HeroData {
func (this *ModelHero) createOneHero(uid string, heroCfgId int32) error { func (this *ModelHero) createOneHero(uid string, heroCfgId int32) error {
hero := this.initHero(uid, heroCfgId) hero := this.initHero(uid, heroCfgId)
if hero != nil { if hero != nil {
return this.moduleHero.model_hero.AddList(uid, hero.Id, hero) return this.moduleHero.modelHero.AddList(uid, hero.Id, hero)
} }
return nil return nil
} }
//创建多个指定的英雄 //创建多个指定的英雄 heroCfgIds可填入多个英雄ID
func (this *ModelHero) createMultiHero(uid string, heroCfgId ...int32) error { func (this *ModelHero) createMultiHero(uid string, heroCfgIds ...int32) error {
data := make(map[string]interface{}) data := make(map[string]interface{})
for _, v := range heroCfgId { for _, v := range heroCfgIds {
hero := this.initHero(uid, v) hero := this.initHero(uid, v)
if hero != nil { if hero != nil {
data[hero.Id] = hero data[hero.Id] = hero
} }
} }
return this.moduleHero.model_hero.AddLists(uid, data) return this.moduleHero.modelHero.AddLists(uid, data)
} }
//获取一个英雄 //获取一个英雄
func (this *ModelHero) getOneHero(uid, heroId string) *pb.DB_HeroData { func (this *ModelHero) getOneHero(uid, heroId string) *pb.DB_HeroData {
hero := &pb.DB_HeroData{} hero := &pb.DB_HeroData{}
err := this.moduleHero.model_hero.GetListObj(uid, heroId, hero) err := this.moduleHero.modelHero.GetListObj(uid, heroId, hero)
if err != nil { if err != nil {
return nil return nil
} }
return hero return hero
} }
//消耗一张英雄卡
func (this *ModelHero) consumeOneHeroCard(uid, heroId string) error {
return this.moduleHero.modelHero.DelListlds(uid, heroId)
}
func (this *Hero) ModifyHero(heroId *pb.DB_HeroData) (*pb.DB_HeroData, pb.ErrorCode) {
return nil, pb.ErrorCode_HeroNoExist
}
//获取玩家的英雄列表 //获取玩家的英雄列表
func (this *ModelHero) getHeroList(uid string) ([]*pb.DB_HeroData, error) { func (this *ModelHero) getHeroList(uid string) ([]*pb.DB_HeroData, error) {
herokeys := make(map[string]string) herokeys := make(map[string]string)
err := this.Get(uid, herokeys) err := this.Get(uid, herokeys)
if err != nil { if err != nil {
if err == redis.RedisNil {
return make([]*pb.DB_HeroData, 0), nil
}
return nil, err return nil, err
} }
@ -111,7 +126,7 @@ func (this *ModelHero) setEquipment(uid, heroId string, equipIds []string) pb.Er
//指定英雄升级 //指定英雄升级
func (this *ModelHero) levelUp(uid string, heroId int32) error { func (this *ModelHero) levelUp(uid string, heroId int32) error {
var heroes []*pb.DB_HeroData var heroes []*pb.DB_HeroData
err := this.moduleHero.model_hero.GetList(uid, heroes) err := this.moduleHero.modelHero.GetList(uid, heroes)
if err != nil { if err != nil {
log.Errorf("levelUp err:%v", err) log.Errorf("levelUp err:%v", err)
return err return err
@ -133,31 +148,31 @@ func (this *ModelHero) PropertyCompute(uid, heroId string) map[int32]int32 {
} }
//英雄等级基础属性levelup //英雄等级基础属性levelup
heroLvCfg := this.moduleHero.configure_comp.GetHeroLv(hero.Lv) heroLvCfg := this.moduleHero.configure.GetHeroLv(hero.Lv)
if heroLvCfg == nil { if heroLvCfg == nil {
return nil return nil
} }
//英雄基础配置 newhero //英雄基础配置 newhero
heroCfg := this.moduleHero.configure_comp.GetHero(hero.HeroID) heroCfg := this.moduleHero.configure.GetHero(hero.HeroID)
if heroCfg == nil { if heroCfg == nil {
return nil return nil
} }
//品质系数 //品质系数
stargrowCfg := this.moduleHero.configure_comp.GetHeroStar(heroCfg.Star) stargrowCfg := this.moduleHero.configure.GetHeroStar(heroCfg.Star)
if stargrowCfg == nil { if stargrowCfg == nil {
return nil return nil
} }
//英雄星级对应等级属性 //英雄星级对应等级属性
heroStarCfg := this.moduleHero.configure_comp.GetHeroLv(stargrowCfg.Level) heroStarCfg := this.moduleHero.configure.GetHeroLv(stargrowCfg.Level)
if heroStarCfg == nil { if heroStarCfg == nil {
return nil return nil
} }
//成长系数 //成长系数
lvGrow := this.moduleHero.configure_comp.GetHeroLvgrow(hero.HeroID) lvGrow := this.moduleHero.configure.GetHeroLvgrow(hero.HeroID)
if lvGrow == nil { if lvGrow == nil {
return nil return nil
} }

View File

@ -14,9 +14,10 @@ func NewModule() core.IModule {
type Hero struct { type Hero struct {
modules.ModuleBase modules.ModuleBase
api_comp *Api_Comp api *apiComp
configure_comp *Configure_Comp configure *configureComp
model_hero *ModelHero modelHero *ModelHero
items comm.IItems
} }
//模块名 //模块名
@ -33,60 +34,136 @@ func (this *Hero) Init(service core.IService, module core.IModule, options core.
//装备组件 //装备组件
func (this *Hero) OnInstallComp() { func (this *Hero) OnInstallComp() {
this.ModuleBase.OnInstallComp() this.ModuleBase.OnInstallComp()
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp) this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.model_hero = this.RegisterComp(new(ModelHero)).(*ModelHero) this.modelHero = this.RegisterComp(new(ModelHero)).(*ModelHero)
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp) this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
}
//通过唯一对象获取英雄信息
func (this *Hero) GetHeroInfoByObjID(id string) (*pb.DB_HeroData, pb.ErrorCode) {
return nil, pb.ErrorCode_HeroNoExist
} }
//创建新英雄 //创建新英雄
func (this *Hero) CreatMultiHero(uid string, heroCfgId ...int32) error { func (this *Hero) CreatHero(uid string, heroCfgId ...int32) error {
return this.model_hero.createMultiHero(uid, heroCfgId...) return this.modelHero.createMultiHero(uid, heroCfgId...)
}
//消耗英雄卡
func (this *Hero) ChangeCard(uId string, heroCfgId int32, count int32) (code pb.ErrorCode) {
heroes := this.GetHeroList(uId)
var curList []*pb.DB_HeroData
for _, v := range heroes {
if heroCfgId == v.HeroID {
curList = append(curList, v)
}
}
if int32(len(curList)) < count {
return pb.ErrorCode_HeroNoEnough
}
for _, v := range curList {
err := this.modelHero.consumeOneHeroCard(uId, v.Id)
if err != nil {
return pb.ErrorCode_DBError
}
}
return pb.ErrorCode_Success
} }
//获取英雄 //获取英雄
func (this *Hero) GetHero(uid, heroId string) (*pb.DB_HeroData, pb.ErrorCode) { func (this *Hero) GetHero(uid, heroId string) (*pb.DB_HeroData, pb.ErrorCode) {
hero := this.model_hero.getOneHero(uid, heroId) hero := this.modelHero.getOneHero(uid, heroId)
if hero == nil { if hero == nil {
return nil, pb.ErrorCode_HeroNoExist return nil, pb.ErrorCode_HeroNoExist
} }
return hero, pb.ErrorCode_Success return hero, pb.ErrorCode_Success
} }
func (this *Hero) ModifyHero(heroId *pb.DB_HeroData) (*pb.DB_HeroData, pb.ErrorCode) {
return nil, pb.ErrorCode_HeroNoExist
}
//佩戴装备 //佩戴装备
func (this *Hero) UpdateEquipment(hero *pb.DB_HeroData, equip []*pb.DB_Equipment) (code pb.ErrorCode) { func (this *Hero) UpdateEquipment(hero *pb.DB_HeroData, equip []*pb.DB_Equipment) (code pb.ErrorCode) {
equipIds := make([]string, 4) equipIds := make([]string, 4)
for _, v := range equip { for _, v := range equip {
equipIds = append(equipIds, v.Id) equipIds = append(equipIds, v.Id)
} }
return this.model_hero.setEquipment(hero.Uid, hero.Id, equipIds) return this.modelHero.setEquipment(hero.Uid, hero.Id, equipIds)
} }
//英雄列表 //英雄列表
func (this *Hero) GetHeroList(uid string) []*pb.DB_HeroData { func (this *Hero) GetHeroList(uid string) []*pb.DB_HeroData {
list, err := this.model_hero.getHeroList(uid) list, err := this.modelHero.getHeroList(uid)
if err != nil { if err != nil {
return nil return nil
} }
return list return list
} }
func (this *Hero) AddCard(uId string, cardId int32, add int32) (code pb.ErrorCode) { //查询英雄数量
return func (this *Hero) QueryHeroAmount(uId string, heroCfgId int32) (amount uint32) {
heroes := this.GetHeroList(uId)
for _, v := range heroes {
if v.HeroID == heroCfgId {
amount++
}
}
return amount
} }
func (this *Hero) QueryCardAmount(uId string, cardId int32) (amount uint32) { func (this *Hero) QueryCardAmount(uId string, cardId int32) (amount uint32) {
return 0 return 0
} }
// 给指定英雄加经验
func (this *Hero) AddCardExp(uid string, cardid string, exp int32) (code pb.ErrorCode) {
var (
curExp int32
curLv int32
)
_hero, err := this.GetHero(uid, cardid) // 获取英雄信息
if err != 0 {
code = pb.ErrorCode_HeroNoExist
return
}
curExp = _hero.Exp
curLv = _hero.Lv
var maxLv int32 // 校验等级达到上限
maxLv = _hero.Star * comm.HeroStarLvRatio
_data := this.configure.GetHeroLv(curLv)
if _data != nil {
if maxLv >= _hero.Lv && curExp >= _data.Heroexp[0].N { // 加经验之前校验是否达到最大等级
code = pb.ErrorCode_HeroMaxLv
return
}
curExp += exp // 先把经验加上
for { // 死循环判断一键升级
if maxLv >= _hero.Lv && curExp >= _data.Heroexp[0].N { // 设置最大经验和等级
curLv = maxLv
curExp = _data.Heroexp[0].N
break
}
if _data.Heroexp[0].N > curExp { // 经验不够升级则不能执行升级操作
break
} else { // 升级操作
curExp -= _data.Heroexp[0].N
curLv += 1 // 经验够了 那么等级+1
_data = this.configure.GetHeroLv(curLv)
if _data == nil { // 等级加失败了 回到原来的等级
curLv -= 1
break
}
}
}
_hero.Lv = curLv
_hero.Exp = curExp
this.ModifyHero(_hero) // 修改英雄数据
} else {
code = pb.ErrorCode_HeroNoExist
return
}
return
}
// 删除指定卡牌
func (this *Hero) DelCard(cardid string, amount int32) (code pb.ErrorCode) {
return
}

View File

@ -15,14 +15,14 @@ const (
GetNewEMailResp = "getnewEmailresp" GetNewEMailResp = "getnewEmailresp"
) )
type Api_Comp struct { type apiComp struct {
modules.MComp_GateComp modules.MComp_GateComp
service core.IService service core.IService
module *Mail module *Mail
items comm.IItems items comm.IItems
} }
func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.MComp_GateComp.Init(service, module, comp, options) this.MComp_GateComp.Init(service, module, comp, options)
this.service = service this.service = service
this.module = module.(*Mail) this.module = module.(*Mail)
@ -30,7 +30,7 @@ func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core
return return
} }
func (this *Api_Comp) Start() (err error) { func (this *apiComp) Start() (err error) {
err = this.MComp_GateComp.Start() err = this.MComp_GateComp.Start()
var module core.IModule var module core.IModule

View File

@ -7,12 +7,12 @@ import (
) )
//参数校验 //参数校验
func (this *Api_Comp) DelMail_Check(session comm.IUserSession, req *pb.Mail_DelMail_Req) (result map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) DelMail_Check(session comm.IUserSession, req *pb.Mail_DelMail_Req) (result map[string]interface{}, code comm.ErrorCode) {
return return
} }
// 删除邮件 // 删除邮件
func (this *Api_Comp) DelMail(session comm.IUserSession, agrs map[string]interface{}, req *pb.Mail_DelMail_Req) (code pb.ErrorCode) { func (this *apiComp) DelMail(session comm.IUserSession, agrs map[string]interface{}, req *pb.Mail_DelMail_Req) (code pb.ErrorCode) {
var err error var err error
mailinfo := make([]*pb.DB_MailData, 0) mailinfo := make([]*pb.DB_MailData, 0)
defer func() { defer func() {
@ -22,13 +22,13 @@ func (this *Api_Comp) DelMail(session comm.IUserSession, agrs map[string]interfa
code = pb.ErrorCode_NoLogin code = pb.ErrorCode_NoLogin
return return
} }
bRet := this.module.db_comp.Mail_DelUserMail(req.ObjID) bRet := this.module.modelMail.Mail_DelUserMail(req.ObjID)
if !bRet { if !bRet {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return
} }
if mailinfo, err = this.module.db_comp.Mail_QueryUserMail(session.GetUserId()); err != nil { if mailinfo, err = this.module.modelMail.Mail_QueryUserMail(session.GetUserId()); err != nil {
log.Errorf("QueryUserMailResp err:%v", err) log.Errorf("QueryUserMailResp err:%v", err)
code = pb.ErrorCode_CacheReadError code = pb.ErrorCode_CacheReadError
return return

View File

@ -5,12 +5,12 @@ import (
"go_dreamfactory/pb" "go_dreamfactory/pb"
) )
func (this *Api_Comp) GetUserMailAttachment_Check(session comm.IUserSession, req *pb.Mail_GetUserMailAttachment_Req) (result map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) GetUserMailAttachment_Check(session comm.IUserSession, req *pb.Mail_GetUserMailAttachment_Req) (result map[string]interface{}, code comm.ErrorCode) {
return return
} }
// 领取附件 // 领取附件
func (this *Api_Comp) GetUserMailAttachment(session comm.IUserSession, agrs map[string]interface{}, req *pb.Mail_GetUserMailAttachment_Req) (code pb.ErrorCode) { func (this *apiComp) GetUserMailAttachment(session comm.IUserSession, agrs map[string]interface{}, req *pb.Mail_GetUserMailAttachment_Req) (code pb.ErrorCode) {
var ( var (
mail *pb.DB_MailData mail *pb.DB_MailData
@ -22,12 +22,12 @@ func (this *Api_Comp) GetUserMailAttachment(session comm.IUserSession, agrs map[
code = pb.ErrorCode_NoLogin code = pb.ErrorCode_NoLogin
return return
} }
_bGet := this.module.db_comp.Mail_GetMailAttachmentState(req.ObjID) _bGet := this.module.modelMail.Mail_GetMailAttachmentState(req.ObjID)
if !_bGet { if !_bGet {
code = pb.ErrorCode_StateInvalid code = pb.ErrorCode_StateInvalid
return return
} }
_data, err := this.module.db_comp.Mail_GetMailAttachment(req.ObjID) _data, err := this.module.modelMail.Mail_GetMailAttachment(req.ObjID)
if err == nil { if err == nil {
if len(_data) > 0 { if len(_data) > 0 {
// todo 领取附件 // todo 领取附件
@ -42,7 +42,7 @@ func (this *Api_Comp) GetUserMailAttachment(session comm.IUserSession, agrs map[
}, mail.Uid, _items) }, mail.Uid, _items)
if code == pb.ErrorCode_Success { if code == pb.ErrorCode_Success {
// 修改状态 // 修改状态
this.module.db_comp.Mail_UpdateMailAttachmentState(req.ObjID) this.module.modelMail.Mail_UpdateMailAttachmentState(req.ObjID)
mail.Reward = true mail.Reward = true
return return
} }

View File

@ -6,12 +6,12 @@ import (
"go_dreamfactory/pb" "go_dreamfactory/pb"
) )
func (this *Api_Comp) GetList_Check(session comm.IUserSession, req *pb.Mail_GetList_Req) (result map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) GetList_Check(session comm.IUserSession, req *pb.Mail_GetList_Req) (result map[string]interface{}, code comm.ErrorCode) {
return return
} }
// 查看所有邮件信息 // 查看所有邮件信息
func (this *Api_Comp) GetList(session comm.IUserSession, agrs map[string]interface{}, req *pb.Mail_GetList_Req) (code pb.ErrorCode) { func (this *apiComp) GetList(session comm.IUserSession, agrs map[string]interface{}, req *pb.Mail_GetList_Req) (code pb.ErrorCode) {
var err error var err error
mailinfo := make([]*pb.DB_MailData, 0) mailinfo := make([]*pb.DB_MailData, 0)
@ -22,7 +22,7 @@ func (this *Api_Comp) GetList(session comm.IUserSession, agrs map[string]interfa
code = pb.ErrorCode_NoLogin code = pb.ErrorCode_NoLogin
return return
} }
if mailinfo, err = this.module.db_comp.Mail_QueryUserMail(session.GetUserId()); err != nil { if mailinfo, err = this.module.modelMail.Mail_QueryUserMail(session.GetUserId()); err != nil {
log.Errorf("Mail_GetList_Resp err:%v", err) log.Errorf("Mail_GetList_Resp err:%v", err)
code = pb.ErrorCode_CacheReadError code = pb.ErrorCode_CacheReadError
return return

View File

@ -5,12 +5,12 @@ import (
"go_dreamfactory/pb" "go_dreamfactory/pb"
) )
func (this *Api_Comp) ReadMail_Check(session comm.IUserSession, req *pb.Mail_ReadMail_Req) (result map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) ReadMail_Check(session comm.IUserSession, req *pb.Mail_ReadMail_Req) (result map[string]interface{}, code comm.ErrorCode) {
return return
} }
// 查看某一封邮件 // 查看某一封邮件
func (this *Api_Comp) ReadMail(session comm.IUserSession, agrs map[string]interface{}, req *pb.Mail_ReadMail_Req) (code pb.ErrorCode) { func (this *apiComp) ReadMail(session comm.IUserSession, agrs map[string]interface{}, req *pb.Mail_ReadMail_Req) (code pb.ErrorCode) {
var ( var (
err error err error
mail *pb.DB_MailData mail *pb.DB_MailData
@ -23,7 +23,7 @@ func (this *Api_Comp) ReadMail(session comm.IUserSession, agrs map[string]interf
return return
} }
mail, err = this.module.db_comp.Mail_ReadOneMail(req.ObjID) mail, err = this.module.modelMail.Mail_ReadOneMail(req.ObjID)
if err != nil { if err != nil {
code = pb.ErrorCode_ReqParameterError code = pb.ErrorCode_ReqParameterError
} }

View File

@ -18,11 +18,11 @@ const (
DB_MailTable core.SqlTable = "mail" DB_MailTable core.SqlTable = "mail"
) )
type DB_Comp struct { type ModelMail struct {
modules.Model_Comp modules.Model_Comp
} }
func (this *DB_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *ModelMail) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.Model_Comp.Init(service, module, comp, options) this.Model_Comp.Init(service, module, comp, options)
this.TableName = "mail" this.TableName = "mail"
//创建uid索引 //创建uid索引
@ -32,7 +32,7 @@ func (this *DB_Comp) Init(service core.IService, module core.IModule, comp core.
return return
} }
func (this *DB_Comp) Mail_QueryUserMail(uId string) (mail []*pb.DB_MailData, err error) { func (this *ModelMail) Mail_QueryUserMail(uId string) (mail []*pb.DB_MailData, err error) {
if _data, err := this.DB.Find(DB_MailTable, bson.M{"userid": uId}); err == nil { if _data, err := this.DB.Find(DB_MailTable, bson.M{"userid": uId}); err == nil {
for _data.Next(context.TODO()) { for _data.Next(context.TODO()) {
@ -46,7 +46,7 @@ func (this *DB_Comp) Mail_QueryUserMail(uId string) (mail []*pb.DB_MailData, err
} }
// 插入一封新的邮件 // 插入一封新的邮件
func (this *DB_Comp) Mail_InsertUserMail(mail *pb.DB_MailData) (err error) { func (this *ModelMail) Mail_InsertUserMail(mail *pb.DB_MailData) (err error) {
mail.ObjId = primitive.NewObjectID().Hex() mail.ObjId = primitive.NewObjectID().Hex()
mail.Check = false mail.Check = false
@ -60,7 +60,7 @@ func (this *DB_Comp) Mail_InsertUserMail(mail *pb.DB_MailData) (err error) {
return err return err
} }
func (this *DB_Comp) Mail_ReadOneMail(objId string) (mail *pb.DB_MailData, err error) { func (this *ModelMail) Mail_ReadOneMail(objId string) (mail *pb.DB_MailData, err error) {
err = this.DB.FindOneAndUpdate( err = this.DB.FindOneAndUpdate(
DB_MailTable, DB_MailTable,
@ -75,7 +75,7 @@ func (this *DB_Comp) Mail_ReadOneMail(objId string) (mail *pb.DB_MailData, err e
} }
// 查询附件信息 // 查询附件信息
func (this *DB_Comp) Mail_GetMailAttachment(objId string) (itmes []*pb.MailAttachment, err error) { func (this *ModelMail) Mail_GetMailAttachment(objId string) (itmes []*pb.MailAttachment, err error) {
obj := this.DB.FindOne(DB_MailTable, bson.M{"_id": objId}) obj := this.DB.FindOne(DB_MailTable, bson.M{"_id": objId})
var nd *pb.DB_MailData var nd *pb.DB_MailData
@ -86,7 +86,7 @@ func (this *DB_Comp) Mail_GetMailAttachment(objId string) (itmes []*pb.MailAttac
} }
// 查看领取附件状态 // 查看领取附件状态
func (this *DB_Comp) Mail_GetMailAttachmentState(objId string) bool { func (this *ModelMail) Mail_GetMailAttachmentState(objId string) bool {
var nd *pb.DB_MailData var nd *pb.DB_MailData
err := this.DB.FindOne(DB_MailTable, bson.M{"_id": objId}).Decode(nd) err := this.DB.FindOne(DB_MailTable, bson.M{"_id": objId}).Decode(nd)
if err != nil { if err != nil {
@ -96,7 +96,7 @@ func (this *DB_Comp) Mail_GetMailAttachmentState(objId string) bool {
} }
// 更新领取附件状态 // 更新领取附件状态
func (this *DB_Comp) Mail_UpdateMailAttachmentState(objId string) bool { func (this *ModelMail) Mail_UpdateMailAttachmentState(objId string) bool {
this.DB.FindOneAndUpdate( this.DB.FindOneAndUpdate(
DB_MailTable, DB_MailTable,
bson.M{"_id": objId}, bson.M{"_id": objId},
@ -110,7 +110,7 @@ func (this *DB_Comp) Mail_UpdateMailAttachmentState(objId string) bool {
} }
// 删除一封邮件 // 删除一封邮件
func (this *DB_Comp) Mail_DelUserMail(objId string) bool { func (this *ModelMail) Mail_DelUserMail(objId string) bool {
var obj *pb.DB_MailData var obj *pb.DB_MailData
err := this.DB.FindOne(DB_MailTable, bson.M{"_id": objId}).Decode(obj) err := this.DB.FindOne(DB_MailTable, bson.M{"_id": objId}).Decode(obj)
if err != nil { if err != nil {

View File

@ -24,8 +24,8 @@ func NewModule() core.IModule {
type Mail struct { type Mail struct {
modules.ModuleBase modules.ModuleBase
api_comp *Api_Comp api *apiComp
db_comp *DB_Comp modelMail *ModelMail
configure_comp *Configure_Comp configure_comp *Configure_Comp
} }
@ -35,8 +35,8 @@ func (this *Mail) GetType() core.M_Modules {
func (this *Mail) OnInstallComp() { func (this *Mail) OnInstallComp() {
this.ModuleBase.OnInstallComp() this.ModuleBase.OnInstallComp()
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp) this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.db_comp = this.RegisterComp(new(DB_Comp)).(*DB_Comp) this.modelMail = this.RegisterComp(new(ModelMail)).(*ModelMail)
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp) this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp)
} }
@ -51,13 +51,13 @@ func (this *Mail) CreateNewMail(uId string) {
Check: false, Check: false,
Reward: false, Reward: false,
} }
err := this.db_comp.Mail_InsertUserMail(mail) err := this.modelMail.Mail_InsertUserMail(mail)
if err != nil { if err != nil {
log.Error("create mail failed") log.Error("create mail failed")
} }
// 通知玩家 // 通知玩家
var _cache = &pb.Cache_UserData{} var _cache = &pb.Cache_UserData{}
err = this.db_comp.Model_Comp.Get(uId, _cache) err = this.modelMail.Model_Comp.Get(uId, _cache)
if err == nil { if err == nil {
return return
} }

View File

@ -131,7 +131,7 @@ func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code p
code = pb.ErrorCode_ConfigurationException code = pb.ErrorCode_ConfigurationException
return return
} }
if amount = int32(hero.QueryCardAmount(uid, int32(resID))); amount < v.N { if amount = int32(hero.QueryHeroAmount(uid, int32(resID))); amount < v.N {
code = pb.ErrorCode_ResNoEnough code = pb.ErrorCode_ResNoEnough
return return
} }
@ -157,7 +157,10 @@ func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code p
items.AddItem(source, uid, int32(resID), -1*v.N) items.AddItem(source, uid, int32(resID), -1*v.N)
} else if v.A == comm.CardType { //卡片资源 } else if v.A == comm.CardType { //卡片资源
resID, _ = strconv.Atoi(v.T) resID, _ = strconv.Atoi(v.T)
hero.AddCard(uid, int32(resID), -1*v.N) hero.ChangeCard(uid, int32(resID), -1*v.N)
} else if v.A == comm.EquipmentType {
resID, _ = strconv.Atoi(v.T)
equipment.AddNewEquipments(source, uid, resID, -1*v.N)
} }
//不存在消耗武器的情况 //不存在消耗武器的情况
// } else if v.A == comm.EquipmentType { // } else if v.A == comm.EquipmentType {

View File

@ -9,26 +9,26 @@ import (
) )
const ( const (
User_SubType_Login = "login" UserSubTypeLogin = "login"
User_SubType_Logout = "logout" UserSubTypeLogout = "logout"
User_SubType_Create = "create" UserSubTypeCreate = "create"
) )
type Api_Comp struct { type apiComp struct {
modules.MComp_GateComp modules.MComp_GateComp
service base.IRPCXService service base.IRPCXService
module *User module *User
hero comm.IHero hero comm.IHero
} }
func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.MComp_GateComp.Init(service, module, comp, options) this.MComp_GateComp.Init(service, module, comp, options)
this.service = service.(base.IRPCXService) this.service = service.(base.IRPCXService)
this.module = module.(*User) this.module = module.(*User)
return return
} }
func (this *Api_Comp) Start() (err error) { func (this *apiComp) Start() (err error) {
err = this.MComp_GateComp.Start() err = this.MComp_GateComp.Start()
var module core.IModule var module core.IModule

View File

@ -6,7 +6,7 @@ import (
"go_dreamfactory/utils" "go_dreamfactory/utils"
) )
func (this *Api_Comp) Create_Check(session comm.IUserSession, req *pb.UserCreateReq) (result map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) Create_Check(session comm.IUserSession, req *pb.UserCreateReq) (result map[string]interface{}, code comm.ErrorCode) {
result = make(map[string]interface{}) result = make(map[string]interface{})
self := &pb.DB_UserData{} self := &pb.DB_UserData{}
err := this.module.modelUser.Get(session.GetUserId(), self) err := this.module.modelUser.Get(session.GetUserId(), self)
@ -19,11 +19,11 @@ func (this *Api_Comp) Create_Check(session comm.IUserSession, req *pb.UserCreate
} }
//创角 //创角
func (this *Api_Comp) Create(session comm.IUserSession, result map[string]interface{}, req *pb.UserCreateReq) (code pb.ErrorCode) { func (this *apiComp) Create(session comm.IUserSession, result map[string]interface{}, req *pb.UserCreateReq) (code pb.ErrorCode) {
defer utils.TraceFunc(session.GetUserId(), string(this.module.GetType()), User_SubType_Create, req, nil) defer utils.TraceFunc(session.GetUserId(), string(this.module.GetType()), UserSubTypeCreate, req, nil)
defer func() { defer func() {
err := session.SendMsg(string(this.module.GetType()), User_SubType_Create, &pb.UserCreateRsp{}) err := session.SendMsg(string(this.module.GetType()), UserSubTypeCreate, &pb.UserCreateRsp{})
if err != nil { if err != nil {
code = pb.ErrorCode_SystemError code = pb.ErrorCode_SystemError
} }
@ -39,8 +39,13 @@ func (this *Api_Comp) Create(session comm.IUserSession, result map[string]interf
return return
} }
//初始化英雄 //初始化英雄卡
// this.hero. defaultHero := []int32{15001, 25001} //TODO 从配置中读取
err = this.hero.CreatHero(session.GetUserId(), defaultHero...)
if err != nil {
code = pb.ErrorCode_HeroInitCreat
return
}
return return
} }

View File

@ -12,13 +12,13 @@ import (
) )
//参数校验 //参数校验
func (this *Api_Comp) Login_Check(session comm.IUserSession, req *pb.UserLoginReq) (result map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) Login_Check(session comm.IUserSession, req *pb.UserLoginReq) (result map[string]interface{}, code comm.ErrorCode) {
result = map[string]interface{}{} result = map[string]interface{}{}
return return
} }
//登录 //登录
func (this *Api_Comp) Login(session comm.IUserSession, result map[string]interface{}, req *pb.UserLoginReq) (code pb.ErrorCode) { func (this *apiComp) Login(session comm.IUserSession, result map[string]interface{}, req *pb.UserLoginReq) (code pb.ErrorCode) {
var ( var (
err error err error
user *pb.DB_UserData user *pb.DB_UserData
@ -26,7 +26,7 @@ func (this *Api_Comp) Login(session comm.IUserSession, result map[string]interfa
defer func() { defer func() {
if user != nil { if user != nil {
err = session.SendMsg(string(this.module.GetType()), User_SubType_Login, &pb.UserLoginResp{ err = session.SendMsg(string(this.module.GetType()), UserSubTypeLogin, &pb.UserLoginResp{
Data: user, Data: user,
}) })
if err != nil { if err != nil {

View File

@ -6,12 +6,12 @@ import (
"go_dreamfactory/pb" "go_dreamfactory/pb"
) )
func (this *Api_Comp) Logout_Check(session comm.IUserSession, req *pb.UserLoginReq) (result map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) Logout_Check(session comm.IUserSession, req *pb.UserLoginReq) (result map[string]interface{}, code comm.ErrorCode) {
return return
} }
//注销 //注销
func (this *Api_Comp) Logout(session comm.IUserSession, result map[string]interface{}, rsp *pb.UserLoginReq) (code pb.ErrorCode) { func (this *apiComp) Logout(session comm.IUserSession, result map[string]interface{}, rsp *pb.UserLoginReq) (code pb.ErrorCode) {
log.Debugf("User - Logout: session:%v rsp:%v", session.ToString(), rsp) log.Debugf("User - Logout: session:%v rsp:%v", session.ToString(), rsp)
return return

View File

@ -13,7 +13,7 @@ import (
) )
const ( //Redis const ( //Redis
DB_UserTable core.SqlTable = "user" //用户表 TableUser core.SqlTable = "user" //用户表
) )
type ModelUser struct { type ModelUser struct {
@ -31,7 +31,7 @@ func (this *ModelUser) User_FindByAccount(sid int32, account string) (*pb.DB_Use
"sid": sid, "sid": sid,
"binduid": account, "binduid": account,
} }
sr := this.DB.FindOne(DB_UserTable, filter) sr := this.DB.FindOne(TableUser, filter)
var nd *pb.DB_UserData var nd *pb.DB_UserData
err := sr.Decode(&nd) err := sr.Decode(&nd)
return nd, err return nd, err
@ -43,6 +43,6 @@ func (this *ModelUser) User_Create(user *pb.DB_UserData) (err error) {
user.Uid = fmt.Sprintf("%d_%s", user.Sid, _id) user.Uid = fmt.Sprintf("%d_%s", user.Sid, _id)
user.Uuid = uuid.NewV4().String() user.Uuid = uuid.NewV4().String()
user.Ctime = time.Now().Unix() user.Ctime = time.Now().Unix()
_, err = this.DB.InsertOne(DB_UserTable, user) _, err = this.DB.InsertOne(TableUser, user)
return err return err
} }

View File

@ -15,7 +15,7 @@ func NewModule() core.IModule {
type User struct { type User struct {
modules.ModuleBase modules.ModuleBase
user_comp *Api_Comp api *apiComp
modelUser *ModelUser modelUser *ModelUser
modelSession *ModelSession modelSession *ModelSession
} }
@ -32,7 +32,7 @@ func (this *User) Init(service core.IService, module core.IModule, options core.
func (this *User) OnInstallComp() { func (this *User) OnInstallComp() {
this.ModuleBase.OnInstallComp() this.ModuleBase.OnInstallComp()
this.user_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp) this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.modelUser = this.RegisterComp(new(ModelUser)).(*ModelUser) this.modelUser = this.RegisterComp(new(ModelUser)).(*ModelUser)
this.modelSession = this.RegisterComp(new(ModelSession)).(*ModelSession) this.modelSession = this.RegisterComp(new(ModelSession)).(*ModelSession)
} }
@ -42,3 +42,10 @@ func (this *User) GetHeroList(uid string) []*pb.DB_HeroData {
return nil return nil
} }
func (this *User) QueryAttributeValue(uid string, attr string) (value int32) {
return
}
func (this *User) AddAttributeValue(uid string, attr string, add int32) (code pb.ErrorCode) {
return
}

View File

@ -65,9 +65,10 @@ const (
ErrorCode_ItemsGridNumUpper ErrorCode = 1202 //背包格子数量已达上限 ErrorCode_ItemsGridNumUpper ErrorCode = 1202 //背包格子数量已达上限
ErrorCode_ItemsGirdAmountUpper ErrorCode = 1203 //背包格子容量已达上限 ErrorCode_ItemsGirdAmountUpper ErrorCode = 1203 //背包格子容量已达上限
// hero // hero
ErrorCode_HeroNoExist ErrorCode = 1300 //英雄不存在 ErrorCode_HeroNoExist ErrorCode = 1300 //英雄不存在
ErrorCode_HeroNoEnough ErrorCode = 1301 //英雄数量不足 ErrorCode_HeroNoEnough ErrorCode = 1301 //英雄数量不足
ErrorCode_HeroMaxLv ErrorCode = 1302 //英雄达到最大等级 ErrorCode_HeroMaxLv ErrorCode = 1302 //英雄达到最大等级
ErrorCode_HeroInitCreat ErrorCode = 1303 //初始化英雄
// equipment // equipment
ErrorCode_EquipmentOnFoundEquipment ErrorCode = 1400 // 未找到武器 ErrorCode_EquipmentOnFoundEquipment ErrorCode = 1400 // 未找到武器
ErrorCode_EquipmentLvlimitReached ErrorCode = 1401 // 武器等级已达上限 ErrorCode_EquipmentLvlimitReached ErrorCode = 1401 // 武器等级已达上限
@ -117,6 +118,7 @@ var (
1300: "HeroNoExist", 1300: "HeroNoExist",
1301: "HeroNoEnough", 1301: "HeroNoEnough",
1302: "HeroMaxLv", 1302: "HeroMaxLv",
1303: "HeroInitCreat",
1400: "EquipmentOnFoundEquipment", 1400: "EquipmentOnFoundEquipment",
1401: "EquipmentLvlimitReached", 1401: "EquipmentLvlimitReached",
} }
@ -162,6 +164,7 @@ var (
"HeroNoExist": 1300, "HeroNoExist": 1300,
"HeroNoEnough": 1301, "HeroNoEnough": 1301,
"HeroMaxLv": 1302, "HeroMaxLv": 1302,
"HeroInitCreat": 1303,
"EquipmentOnFoundEquipment": 1400, "EquipmentOnFoundEquipment": 1400,
"EquipmentLvlimitReached": 1401, "EquipmentLvlimitReached": 1401,
} }
@ -198,7 +201,7 @@ var File_errorcode_proto protoreflect.FileDescriptor
var file_errorcode_proto_rawDesc = []byte{ var file_errorcode_proto_rawDesc = []byte{
0x0a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x0a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x2a, 0x92, 0x07, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x6f, 0x2a, 0xa6, 0x07, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12,
0x0b, 0x0a, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x10, 0x00, 0x12, 0x11, 0x0a, 0x0d, 0x0b, 0x0a, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x10, 0x00, 0x12, 0x11, 0x0a, 0x0d,
0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x10, 0x0a, 0x12, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x10, 0x0a, 0x12,
0x1b, 0x0a, 0x17, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x1b, 0x0a, 0x17, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
@ -251,12 +254,13 @@ var file_errorcode_proto_rawDesc = []byte{
0x10, 0xb3, 0x09, 0x12, 0x10, 0x0a, 0x0b, 0x48, 0x65, 0x72, 0x6f, 0x4e, 0x6f, 0x45, 0x78, 0x69, 0x10, 0xb3, 0x09, 0x12, 0x10, 0x0a, 0x0b, 0x48, 0x65, 0x72, 0x6f, 0x4e, 0x6f, 0x45, 0x78, 0x69,
0x73, 0x74, 0x10, 0x94, 0x0a, 0x12, 0x11, 0x0a, 0x0c, 0x48, 0x65, 0x72, 0x6f, 0x4e, 0x6f, 0x45, 0x73, 0x74, 0x10, 0x94, 0x0a, 0x12, 0x11, 0x0a, 0x0c, 0x48, 0x65, 0x72, 0x6f, 0x4e, 0x6f, 0x45,
0x6e, 0x6f, 0x75, 0x67, 0x68, 0x10, 0x95, 0x0a, 0x12, 0x0e, 0x0a, 0x09, 0x48, 0x65, 0x72, 0x6f, 0x6e, 0x6f, 0x75, 0x67, 0x68, 0x10, 0x95, 0x0a, 0x12, 0x0e, 0x0a, 0x09, 0x48, 0x65, 0x72, 0x6f,
0x4d, 0x61, 0x78, 0x4c, 0x76, 0x10, 0x96, 0x0a, 0x12, 0x1e, 0x0a, 0x19, 0x45, 0x71, 0x75, 0x69, 0x4d, 0x61, 0x78, 0x4c, 0x76, 0x10, 0x96, 0x0a, 0x12, 0x12, 0x0a, 0x0d, 0x48, 0x65, 0x72, 0x6f,
0x70, 0x6d, 0x65, 0x6e, 0x74, 0x4f, 0x6e, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x45, 0x71, 0x75, 0x69, 0x49, 0x6e, 0x69, 0x74, 0x43, 0x72, 0x65, 0x61, 0x74, 0x10, 0x97, 0x0a, 0x12, 0x1e, 0x0a, 0x19,
0x70, 0x6d, 0x65, 0x6e, 0x74, 0x10, 0xf8, 0x0a, 0x12, 0x1c, 0x0a, 0x17, 0x45, 0x71, 0x75, 0x69, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x4f, 0x6e, 0x46, 0x6f, 0x75, 0x6e, 0x64,
0x70, 0x6d, 0x65, 0x6e, 0x74, 0x4c, 0x76, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x52, 0x65, 0x61, 0x63, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x10, 0xf8, 0x0a, 0x12, 0x1c, 0x0a, 0x17,
0x68, 0x65, 0x64, 0x10, 0xf9, 0x0a, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x4c, 0x76, 0x6c, 0x69, 0x6d, 0x69, 0x74,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 0x52, 0x65, 0x61, 0x63, 0x68, 0x65, 0x64, 0x10, 0xf9, 0x0a, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b,
0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (

View File

@ -48,10 +48,11 @@ enum ErrorCode {
ItemsGirdAmountUpper = 1203; // ItemsGirdAmountUpper = 1203; //
// hero // hero
HeroNoExist = 1300; // HeroNoExist = 1300; //
HeroNoEnough = 1301; // HeroNoEnough = 1301; //
HeroMaxLv = 1302; // HeroMaxLv = 1302; //
HeroInitCreat = 1303; //
// equipment // equipment
EquipmentOnFoundEquipment = 1400; // EquipmentOnFoundEquipment = 1400; //
EquipmentLvlimitReached = 1401; // EquipmentLvlimitReached = 1401; //
} }

View File

@ -1,4 +1,3 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// This code was generated by a tool. // This code was generated by a tool.
@ -11,19 +10,39 @@ package cfg
import "errors" import "errors"
type Game_atn struct { type Game_atn struct {
A string A string //资源类型
T string T string //资源名称
N int32 N int32 //数量
} }
func (Game_atn) GetTypeId() int { func (Game_atn) GetTypeId() int {
return -1770297697 return -1770297697
} }
func NewGame_atn(_buf map[string]interface{}) (_v *Game_atn, err error) { func NewGame_atn(_buf map[string]interface{}) (_v *Game_atn, err error) {
_v = &Game_atn{} _v = &Game_atn{}
{ var _ok_ bool; if _v.A, _ok_ = _buf["a"].(string); !_ok_ { err = errors.New("a error"); return } } {
{ var _ok_ bool; if _v.T, _ok_ = _buf["t"].(string); !_ok_ { err = errors.New("t error"); return } } var _ok_ bool
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["n"].(float64); !_ok_ { err = errors.New("n error"); return }; _v.N = int32(_tempNum_) } if _v.A, _ok_ = _buf["a"].(string); !_ok_ {
return err = errors.New("a error")
return
}
}
{
var _ok_ bool
if _v.T, _ok_ = _buf["t"].(string); !_ok_ {
err = errors.New("t error")
return
}
}
{
var _ok_ bool
var _tempNum_ float64
if _tempNum_, _ok_ = _buf["n"].(float64); !_ok_ {
err = errors.New("n error")
return
}
_v.N = int32(_tempNum_)
}
return
} }