命名修改

This commit is contained in:
meixiongfeng 2022-06-28 14:50:39 +08:00
parent e14e4563fb
commit d32cea4d30
8 changed files with 64 additions and 64 deletions

View File

@ -6,7 +6,7 @@ import (
"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
moduleHero *Hero moduleHero *Hero
@ -20,14 +20,14 @@ 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.moduleHero = 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 var module core.IModule

View File

@ -7,7 +7,7 @@ import (
) )
//参数校验 //参数校验
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
@ -20,13 +20,13 @@ func (this *Api_Comp) StrengthenUplv_Check(session comm.IUserSession, req *pb.He
//atn = map[string]interface{}{} //atn = map[string]interface{}{}
) )
_hero, err := this.moduleHero.model_hero.moduleHero.GetHero(session.GetUserId(), req.HeroObjID) // 校验升级的对象是否存在 _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.moduleHero.model_hero.moduleHero.GetHero(session.GetUserId(), 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
@ -40,7 +40,7 @@ func (this *Api_Comp) StrengthenUplv_Check(session comm.IUserSession, req *pb.He
curExp = _hero.Exp // 当前英雄的经验 curExp = _hero.Exp // 当前英雄的经验
// 查询 本次消耗会获得多少经验 // 查询 本次消耗会获得多少经验
expConf := this.moduleHero.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
} }
@ -57,7 +57,7 @@ func (this *Api_Comp) StrengthenUplv_Check(session comm.IUserSession, req *pb.He
var maxLv int32 // 校验等级达到上限 var maxLv int32 // 校验等级达到上限
maxLv = _hero.Star * comm.HeroStarLvRatio maxLv = _hero.Star * comm.HeroStarLvRatio
_data := this.moduleHero.configure_comp.GetHeroLv(curLv) _data := this.moduleHero.configure.GetHeroLv(curLv)
if _data != nil { if _data != nil {
if maxLv >= _hero.Lv && curExp >= _data.Heroexp[0].N { // 加经验之前校验是否达到最大等级 if maxLv >= _hero.Lv && curExp >= _data.Heroexp[0].N { // 加经验之前校验是否达到最大等级
code.Code = pb.ErrorCode_HeroMaxLv code.Code = pb.ErrorCode_HeroMaxLv
@ -76,7 +76,7 @@ func (this *Api_Comp) StrengthenUplv_Check(session comm.IUserSession, req *pb.He
} else { // 升级操作 } else { // 升级操作
curExp -= _data.Heroexp[0].N curExp -= _data.Heroexp[0].N
curLv += 1 // 经验够了 那么等级+1 curLv += 1 // 经验够了 那么等级+1
_data = this.moduleHero.configure_comp.GetHeroLv(curLv) _data = this.moduleHero.configure.GetHeroLv(curLv)
if _data == nil { // 等级加失败了 回到原来的等级 if _data == nil { // 等级加失败了 回到原来的等级
curLv -= 1 curLv -= 1
break break
@ -101,7 +101,7 @@ func (this *Api_Comp) StrengthenUplv_Check(session comm.IUserSession, req *pb.He
} }
/// 英雄升级 /// 英雄升级
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 ( var (
curLv int32 curLv int32
curExp int32 // 当前英雄的经验 curExp int32 // 当前英雄的经验
@ -120,7 +120,7 @@ func (this *Api_Comp) StrengthenUplv(session comm.IUserSession, agrs map[string]
addExp = agrs["addExp"].(int32) addExp = agrs["addExp"].(int32)
log.Debugf("升级后当前等级: %d,经验: %d,需要消耗的金币: %d,增加的经验: %d", curLv, curExp, costGold, addExp) log.Debugf("升级后当前等级: %d,经验: %d,需要消耗的金币: %d,增加的经验: %d", curLv, curExp, costGold, addExp)
// 执行升级逻辑 // 执行升级逻辑
code = this.moduleHero.model_hero.moduleHero.AddCardExp(session.GetUserId(), req.HeroObjID, addExp) // 加经验 code = this.moduleHero.modelHero.moduleHero.AddCardExp(session.GetUserId(), req.HeroObjID, addExp) // 加经验
if code != pb.ErrorCode_Success { if code != pb.ErrorCode_Success {
return return
} }
@ -130,7 +130,7 @@ func (this *Api_Comp) StrengthenUplv(session comm.IUserSession, agrs map[string]
return return
} }
// 删除经验卡 // 删除经验卡
code = this.moduleHero.model_hero.moduleHero.DelCard(req.ExpCardID, req.Amount) code = this.moduleHero.modelHero.moduleHero.DelCard(req.ExpCardID, req.Amount)
if code != pb.ErrorCode_Success { if code != pb.ErrorCode_Success {
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.moduleHero.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,7 +16,7 @@ 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.moduleHero.GetType()), Hero_SubType_Info, rsp) err := session.SendMsg(string(this.moduleHero.GetType()), Hero_SubType_Info, rsp)

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.moduleHero.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.moduleHero.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

@ -28,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
@ -55,7 +55,7 @@ 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
} }
@ -69,13 +69,13 @@ func (this *ModelHero) createMultiHero(uid string, heroCfgIds ...int32) error {
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
} }
@ -84,7 +84,7 @@ func (this *ModelHero) getOneHero(uid, heroId string) *pb.DB_HeroData {
//消耗一张英雄卡 //消耗一张英雄卡
func (this *ModelHero) consumeOneHeroCard(uid, heroId string) error { func (this *ModelHero) consumeOneHeroCard(uid, heroId string) error {
return this.moduleHero.model_hero.DelListlds(uid, heroId) return this.moduleHero.modelHero.DelListlds(uid, heroId)
} }
func (this *Hero) ModifyHero(heroId *pb.DB_HeroData) (*pb.DB_HeroData, pb.ErrorCode) { func (this *Hero) ModifyHero(heroId *pb.DB_HeroData) (*pb.DB_HeroData, pb.ErrorCode) {
@ -126,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
@ -148,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,10 +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 items comm.IItems
} }
//模块名 //模块名
@ -34,14 +34,14 @@ 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) CreatHero(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...)
} }
//消耗英雄卡 //消耗英雄卡
@ -58,7 +58,7 @@ func (this *Hero) ChangeCard(uId string, heroCfgId int32, count int32) (code pb.
} }
for _, v := range curList { for _, v := range curList {
err := this.model_hero.consumeOneHeroCard(uId, v.Id) err := this.modelHero.consumeOneHeroCard(uId, v.Id)
if err != nil { if err != nil {
return pb.ErrorCode_DBError return pb.ErrorCode_DBError
} }
@ -69,7 +69,7 @@ func (this *Hero) ChangeCard(uId string, heroCfgId int32, count int32) (code pb.
//获取英雄 //获取英雄
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
} }
@ -82,12 +82,12 @@ func (this *Hero) UpdateEquipment(hero *pb.DB_HeroData, equip []*pb.DB_Equipment
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
} }
@ -126,7 +126,7 @@ func (this *Hero) AddCardExp(uid string, cardid string, exp int32) (code pb.Erro
var maxLv int32 // 校验等级达到上限 var maxLv int32 // 校验等级达到上限
maxLv = _hero.Star * comm.HeroStarLvRatio maxLv = _hero.Star * comm.HeroStarLvRatio
_data := this.configure_comp.GetHeroLv(curLv) _data := this.configure.GetHeroLv(curLv)
if _data != nil { if _data != nil {
if maxLv >= _hero.Lv && curExp >= _data.Heroexp[0].N { // 加经验之前校验是否达到最大等级 if maxLv >= _hero.Lv && curExp >= _data.Heroexp[0].N { // 加经验之前校验是否达到最大等级
code = pb.ErrorCode_HeroMaxLv code = pb.ErrorCode_HeroMaxLv
@ -145,7 +145,7 @@ func (this *Hero) AddCardExp(uid string, cardid string, exp int32) (code pb.Erro
} else { // 升级操作 } else { // 升级操作
curExp -= _data.Heroexp[0].N curExp -= _data.Heroexp[0].N
curLv += 1 // 经验够了 那么等级+1 curLv += 1 // 经验够了 那么等级+1
_data = this.configure_comp.GetHeroLv(curLv) _data = this.configure.GetHeroLv(curLv)
if _data == nil { // 等级加失败了 回到原来的等级 if _data == nil { // 等级加失败了 回到原来的等级
curLv -= 1 curLv -= 1
break break