check 函数

This commit is contained in:
meixiongfeng 2022-07-01 13:53:17 +08:00
parent 653d5f2dbd
commit e204ae71a3
13 changed files with 56 additions and 65 deletions

View File

@ -6,33 +6,38 @@ import (
"go_dreamfactory/pb" "go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs" cfg "go_dreamfactory/sys/configure/structs"
"strconv" "strconv"
"google.golang.org/protobuf/proto"
) )
//参数校验 //参数校验
func (this *apiComp) AwakenCheck(session comm.IUserSession, req *pb.HeroAwakenReq) (result map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) AwakenCheck(session comm.IUserSession, req *pb.HeroAwakenReq) (code comm.ErrorCode) {
var (
costRes map[string]int32
)
costRes = make(map[string]int32, 0)
if req.HeroObjID == "" { if req.HeroObjID == "" {
code.Code = pb.ErrorCode_ReqParameterError code.Code = pb.ErrorCode_ReqParameterError
return return
} }
return
}
/// 英雄觉醒
func (this *apiComp) Awaken(session comm.IUserSession, agrs map[string]interface{}, req *pb.HeroAwakenReq) (code pb.ErrorCode, data proto.Message) {
var ( var (
awakenData *cfg.Game_heroAwakenData awakenData *cfg.Game_heroAwakenData
bCheckOk bool bCheckOk bool
costRes map[string]int32
) )
costRes = make(map[string]int32, 0)
bCheckOk = true bCheckOk = true
_hero, err := this.moduleHero.GetHero(session.GetUserId(), req.HeroObjID) _hero, err := this.moduleHero.GetHero(session.GetUserId(), req.HeroObjID)
if err != pb.ErrorCode_Success { if err != pb.ErrorCode_Success {
code.Code = pb.ErrorCode_HeroNoExist code = pb.ErrorCode_HeroNoExist
return return
} }
AwakenConfig, err1 := this.moduleHero.configure.GetHeroAwakenConfig() AwakenConfig, err1 := this.moduleHero.configure.GetHeroAwakenConfig()
if err1 != nil { if err1 != nil {
code.Code = pb.ErrorCode_ConfigNoFound code = pb.ErrorCode_ConfigNoFound
return return
} }
for _, v := range AwakenConfig.GetDataMap() { for _, v := range AwakenConfig.GetDataMap() {
@ -42,7 +47,7 @@ func (this *apiComp) AwakenCheck(session comm.IUserSession, req *pb.HeroAwakenRe
} }
} }
if awakenData == nil { if awakenData == nil {
code.Code = pb.ErrorCode_ConfigNoFound code = pb.ErrorCode_ConfigNoFound
return return
} }
// 参数校验 // 参数校验
@ -66,23 +71,9 @@ func (this *apiComp) AwakenCheck(session comm.IUserSession, req *pb.HeroAwakenRe
} }
} }
if !bCheckOk { if !bCheckOk {
code.Code = pb.ErrorCode_GoldNoEnough code = pb.ErrorCode_GoldNoEnough
return return
} }
result = map[string]interface{}{
"awakenData": awakenData,
"heroObj": _hero,
"costRes": costRes,
}
return
}
/// 英雄觉醒
func (this *apiComp) Awaken(session comm.IUserSession, agrs map[string]interface{}, req *pb.HeroAwakenReq) (code pb.ErrorCode) {
awakenData := agrs["awakenData"].(*cfg.Game_heroAwakenData)
_hero := agrs["heroObj"].(*pb.DBHero)
costRes := agrs["costRes"].(map[string]int32)
if _hero == nil || awakenData == nil { if _hero == nil || awakenData == nil {
code = pb.ErrorCode_HeroNoExist code = pb.ErrorCode_HeroNoExist
return return
@ -95,8 +86,8 @@ func (this *apiComp) Awaken(session comm.IUserSession, agrs map[string]interface
for _, v := range awakenData.Phaseneed { for _, v := range awakenData.Phaseneed {
if v.A == "attr" { // 消耗玩家身上资源 if v.A == "attr" { // 消耗玩家身上资源
if data, ok := costRes[v.T]; ok { if _data, ok := costRes[v.T]; ok {
code = this.user.AddAttributeValue(session.GetUserId(), v.T, data) code = this.user.AddAttributeValue(session.GetUserId(), v.T, _data)
if code != pb.ErrorCode_Success { if code != pb.ErrorCode_Success {
return return
} }
@ -113,8 +104,8 @@ func (this *apiComp) Awaken(session comm.IUserSession, agrs map[string]interface
} }
} }
err := this.moduleHero.modelHero.PushHeroProperty(session, _hero.Id) // 推送属性变化 err1 = this.moduleHero.hero.PushHeroProperty(session, _hero.Id) // 推送属性变化
if err != nil { if err1 != nil {
log.Errorf("PushHeroProperty err!") log.Errorf("PushHeroProperty err!")
} }
return return

View File

@ -26,12 +26,12 @@ func (this *apiComp) Chouka(session comm.IUserSession, result map[string]interfa
}() }()
heroCfgIds := req.HeroIds heroCfgIds := req.HeroIds
if err := this.moduleHero.modelHero.createMultiHero(session.GetUserId(), heroCfgIds...); err != nil { if err := this.moduleHero.hero.createMultiHero(session.GetUserId(), heroCfgIds...); err != nil {
code = pb.ErrorCode_HeroCreate code = pb.ErrorCode_HeroCreate
return return
} }
heroes, err := this.moduleHero.modelHero.getHeroList(session.GetUserId()) heroes, err := this.moduleHero.hero.getHeroList(session.GetUserId())
if err != nil { if err != nil {
log.Errorf("%v", err) log.Errorf("%v", err)
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError

View File

@ -9,7 +9,7 @@ import (
//参数校验 //参数校验
func (this *apiComp) InfoCheck(session comm.IUserSession, req *pb.HeroInfoReq) (result map[string]interface{}, code comm.ErrorCode) { func (this *apiComp) InfoCheck(session comm.IUserSession, req *pb.HeroInfoReq) (result map[string]interface{}, code comm.ErrorCode) {
result = map[string]interface{}{} result = map[string]interface{}{}
hero := this.moduleHero.modelHero.getOneHero(session.GetUserId(), req.HeroId) hero := this.moduleHero.hero.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}
} }

View File

@ -22,7 +22,7 @@ func (this *apiComp) List(session comm.IUserSession, result map[string]interface
utils.TraceFunc(session.GetUserId(), string(this.moduleHero.GetType()), HeroSubTypeList, req, rsp) utils.TraceFunc(session.GetUserId(), string(this.moduleHero.GetType()), HeroSubTypeList, req, rsp)
}() }()
list, err := this.moduleHero.modelHero.getHeroList(session.GetUserId()) list, err := this.moduleHero.hero.getHeroList(session.GetUserId())
if err != nil { if err != nil {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return

View File

@ -118,7 +118,7 @@ func (this *apiComp) Resonance(session comm.IUserSession, agrs map[string]interf
_heroMap := map[string]interface{}{ _heroMap := map[string]interface{}{
"resonateNum": _hero.ResonateNum + resonConfig.Energy, "resonateNum": _hero.ResonateNum + resonConfig.Energy,
} }
err := this.moduleHero.modelHero.modifyHeroData(session.GetUserId(), req.HeroObjID, _heroMap) // 修改英雄信息 err := this.moduleHero.hero.modifyHeroData(session.GetUserId(), req.HeroObjID, _heroMap) // 修改英雄信息
if err != nil { if err != nil {
log.Errorf("update hero skill failed:%v", err) log.Errorf("update hero skill failed:%v", err)
} }
@ -131,11 +131,11 @@ func (this *apiComp) Resonance(session comm.IUserSession, agrs map[string]interf
return return
} }
for i := 0; i < int(v.N); i++ { // 有多少张加多少次 for i := 0; i < int(v.N); i++ { // 有多少张加多少次
this.moduleHero.modelHero.createOneHero(session.GetUserId(), int32(value)) this.moduleHero.hero.createOneHero(session.GetUserId(), int32(value))
} }
} }
} }
err = this.moduleHero.modelHero.PushHeroProperty(session, _hero.Id) // 推送属性变化 err = this.moduleHero.hero.PushHeroProperty(session, _hero.Id) // 推送属性变化
if err != nil { if err != nil {
log.Errorf("PushHeroProperty err!") log.Errorf("PushHeroProperty err!")
} }

View File

@ -84,11 +84,11 @@ func (this *apiComp) ResonanceReset(session comm.IUserSession, agrs map[string]i
"Energy": _hero.Energy, "Energy": _hero.Energy,
} }
err := this.moduleHero.modelHero.modifyHeroData(session.GetUserId(), req.HeroObjID, _heroMap) // 修改英雄信息 err := this.moduleHero.hero.modifyHeroData(session.GetUserId(), req.HeroObjID, _heroMap) // 修改英雄信息
if err != nil { if err != nil {
log.Errorf("update hero skill failed:%v", err) log.Errorf("update hero skill failed:%v", err)
} }
err = this.moduleHero.modelHero.PushHeroProperty(session, _hero.Id) // 推送属性变化 err = this.moduleHero.hero.PushHeroProperty(session, _hero.Id) // 推送属性变化
if err != nil { if err != nil {
log.Errorf("PushHeroProperty err!") log.Errorf("PushHeroProperty err!")
} }

View File

@ -47,13 +47,13 @@ func (this *apiComp) ResonanceUseEnergy(session comm.IUserSession, agrs map[stri
"Energy": _hero.Energy, "Energy": _hero.Energy,
} }
err := this.moduleHero.modelHero.modifyHeroData(session.GetUserId(), req.HeroObjID, _heroMap) // 修改英雄信息 err := this.moduleHero.hero.modifyHeroData(session.GetUserId(), req.HeroObjID, _heroMap) // 修改英雄信息
if err != nil { if err != nil {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
log.Errorf("update hero skill failed:%v", err) log.Errorf("update hero skill failed:%v", err)
} }
err = this.moduleHero.modelHero.PushHeroProperty(session, _hero.Id) // 推送属性变化 err = this.moduleHero.hero.PushHeroProperty(session, _hero.Id) // 推送属性变化
if err != nil { if err != nil {
log.Errorf("PushHeroProperty err!") log.Errorf("PushHeroProperty err!")
} }

View File

@ -126,7 +126,7 @@ func (this *apiComp) StrengthenUpSkill(session comm.IUserSession, agrs map[strin
_heroMap := map[string]interface{}{ _heroMap := map[string]interface{}{
"normalSkill": _hero.NormalSkill, "normalSkill": _hero.NormalSkill,
} }
err = this.moduleHero.modelHero.modifyHeroData(session.GetUserId(), req.HeroObjID, _heroMap) // 修改英雄信息 err = this.moduleHero.hero.modifyHeroData(session.GetUserId(), req.HeroObjID, _heroMap) // 修改英雄信息
if err != nil { if err != nil {
log.Errorf("update hero skill failed:%v", err) log.Errorf("update hero skill failed:%v", err)
} }
@ -136,7 +136,7 @@ func (this *apiComp) StrengthenUpSkill(session comm.IUserSession, agrs map[strin
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
return return
} }
err = this.moduleHero.modelHero.PushHeroProperty(session, _hero.Id) // 推送属性变化 err = this.moduleHero.hero.PushHeroProperty(session, _hero.Id) // 推送属性变化
if err != nil { if err != nil {
log.Errorf("PushHeroProperty err!") log.Errorf("PushHeroProperty err!")
} }

View File

@ -148,12 +148,12 @@ func (this *apiComp) StrengthenUpStar(session comm.IUserSession, agrs map[string
"star": _hero.Star, "star": _hero.Star,
} }
// 保存数据 // 保存数据
err := this.moduleHero.modelHero.modifyHeroData(session.GetUserId(), req.HeroObjID, _heroMap) err := this.moduleHero.hero.modifyHeroData(session.GetUserId(), req.HeroObjID, _heroMap)
if err != nil { if err != nil {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
log.Errorf("update hero skill failed:%v", err) log.Errorf("update hero skill failed:%v", err)
} }
err = this.moduleHero.modelHero.PushHeroProperty(session, _hero.Id) // 推送属性变化 err = this.moduleHero.hero.PushHeroProperty(session, _hero.Id) // 推送属性变化
if err != nil { if err != nil {
log.Errorf("PushHeroProperty err!") log.Errorf("PushHeroProperty err!")
} }

View File

@ -154,13 +154,13 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, agrs map[string]i
return return
} }
// 删除经验卡 // 删除经验卡
err := this.moduleHero.modelHero.consumeOneHeroCard(session.GetUserId(), req.ExpCardID, req.Amount) err := this.moduleHero.hero.consumeOneHeroCard(session.GetUserId(), req.ExpCardID, req.Amount)
if err != nil { if err != nil {
log.Errorf("delete err failed err:%T!", err) log.Errorf("delete err failed err:%T!", err)
return return
} }
err = this.moduleHero.modelHero.PushHeroProperty(session, _hero.Id) // 推送属性变化 err = this.moduleHero.hero.PushHeroProperty(session, _hero.Id) // 推送属性变化
if err != nil { if err != nil {
log.Errorf("PushHeroProperty err!") log.Errorf("PushHeroProperty err!")
} }

View File

@ -70,23 +70,23 @@ func TestMain(m *testing.M) {
//创建一个英雄s //创建一个英雄s
func TestCreateOneHero(t *testing.T) { func TestCreateOneHero(t *testing.T) {
err := module.modelHero.createOneHero("u1", 25001) err := module.hero.createOneHero("u1", 25001)
fmt.Println(err) fmt.Println(err)
} }
//获取玩家英雄 //获取玩家英雄
func TestGetOneHero(t *testing.T) { func TestGetOneHero(t *testing.T) {
d := module.modelHero.getOneHero("u1", "62b534bebf4745d4117acabe") d := module.hero.getOneHero("u1", "62b534bebf4745d4117acabe")
fmt.Printf("%v", d) fmt.Printf("%v", d)
} }
func TestPropertyCompute(t *testing.T) { func TestPropertyCompute(t *testing.T) {
m := module.modelHero.PropertyCompute("u1", "62b534bebf4745d4117acabe") m := module.hero.PropertyCompute("u1", "62b534bebf4745d4117acabe")
fmt.Println(m) fmt.Println(m)
} }
func TestHeroList(t *testing.T) { func TestHeroList(t *testing.T) {
heroes, err := module.modelHero.getHeroList("u1") heroes, err := module.hero.getHeroList("u1")
fmt.Printf("%v %v", heroes, err) fmt.Printf("%v %v", heroes, err)
} }
@ -95,6 +95,6 @@ func TestModify(t *testing.T) {
"lv": 2, "lv": 2,
"exp": 1000, "exp": 1000,
} }
err := module.modelHero.modifyHeroData("u1", "62b534bebf4745d4117acabe", data) err := module.hero.modifyHeroData("u1", "62b534bebf4745d4117acabe", data)
fmt.Printf("%v ", err) fmt.Printf("%v ", err)
} }

View File

@ -57,7 +57,7 @@ func (this *ModelHero) initHero(uid string, heroCfgId int32) *pb.DBHero {
func (this *ModelHero) createOneHero(uid string, heroCfgId int32) (err error) { func (this *ModelHero) createOneHero(uid string, heroCfgId int32) (err error) {
hero := this.initHero(uid, heroCfgId) hero := this.initHero(uid, heroCfgId)
if hero != nil { if hero != nil {
if err = this.moduleHero.modelHero.AddList(uid, hero.Id, hero); err != nil { if err = this.moduleHero.hero.AddList(uid, hero.Id, hero); err != nil {
log.Errorf("%v", err) log.Errorf("%v", err)
return return
} }
@ -67,7 +67,7 @@ func (this *ModelHero) createOneHero(uid string, heroCfgId int32) (err error) {
//创建多个指定的英雄 heroCfgIds可填入多个英雄ID //创建多个指定的英雄 heroCfgIds可填入多个英雄ID
func (this *ModelHero) createMultiHero(uid string, heroCfgIds ...int32) error { func (this *ModelHero) createMultiHero(uid string, heroCfgIds ...int32) error {
heroes, err := this.moduleHero.modelHero.getHeroList(uid) heroes, err := this.moduleHero.hero.getHeroList(uid)
if err != nil { if err != nil {
return err return err
} }
@ -111,7 +111,7 @@ func (this *ModelHero) createMultiHero(uid string, heroCfgIds ...int32) error {
//获取一个英雄 //获取一个英雄
func (this *ModelHero) getOneHero(uid, heroId string) *pb.DBHero { func (this *ModelHero) getOneHero(uid, heroId string) *pb.DBHero {
hero := &pb.DBHero{} hero := &pb.DBHero{}
err := this.moduleHero.modelHero.GetListObj(uid, heroId, hero) err := this.moduleHero.hero.GetListObj(uid, heroId, hero)
if err != nil { if err != nil {
return nil return nil
} }
@ -121,7 +121,7 @@ func (this *ModelHero) getOneHero(uid, heroId string) *pb.DBHero {
//消耗一张英雄卡 //消耗一张英雄卡
func (this *ModelHero) consumeOneHeroCard(uid, heroId string, count int32) (err error) { func (this *ModelHero) consumeOneHeroCard(uid, heroId string, count int32) (err error) {
for i := 0; i < int(count); i++ { for i := 0; i < int(count); i++ {
if err := this.moduleHero.modelHero.DelListlds(uid, heroId); err != nil { if err := this.moduleHero.hero.DelListlds(uid, heroId); err != nil {
log.Errorf("%v", err) log.Errorf("%v", err)
break break
} }
@ -131,7 +131,7 @@ func (this *ModelHero) consumeOneHeroCard(uid, heroId string, count int32) (err
//更新英雄数据 //更新英雄数据
func (this *ModelHero) modifyHeroData(uid, heroId string, data map[string]interface{}) error { func (this *ModelHero) modifyHeroData(uid, heroId string, data map[string]interface{}) error {
return this.moduleHero.modelHero.ChangeList(uid, heroId, data) return this.moduleHero.hero.ChangeList(uid, heroId, data)
} }
//获取玩家的英雄列表 //获取玩家的英雄列表

View File

@ -16,7 +16,7 @@ type Hero struct {
modules.ModuleBase modules.ModuleBase
api *apiComp api *apiComp
configure *configureComp configure *configureComp
modelHero *ModelHero hero *ModelHero
items comm.IItems items comm.IItems
} }
@ -35,13 +35,13 @@ 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 = this.RegisterComp(new(apiComp)).(*apiComp) this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.modelHero = this.RegisterComp(new(ModelHero)).(*ModelHero) this.hero = this.RegisterComp(new(ModelHero)).(*ModelHero)
this.configure = this.RegisterComp(new(configureComp)).(*configureComp) this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
} }
//创建新英雄 //创建新英雄
func (this *Hero) CreateHero(uid string, heroCfgId ...int32) error { func (this *Hero) CreateHero(uid string, heroCfgId ...int32) error {
return this.modelHero.createMultiHero(uid, heroCfgId...) return this.hero.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.modelHero.consumeOneHeroCard(v.Uid, v.Id, count) err := this.hero.consumeOneHeroCard(v.Uid, v.Id, count)
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.DBHero, pb.ErrorCode) { func (this *Hero) GetHero(uid, heroId string) (*pb.DBHero, pb.ErrorCode) {
hero := this.modelHero.getOneHero(uid, heroId) hero := this.hero.getOneHero(uid, heroId)
if hero == nil { if hero == nil {
return nil, pb.ErrorCode_HeroNoExist return nil, pb.ErrorCode_HeroNoExist
} }
@ -91,14 +91,14 @@ func (this *Hero) UpdateEquipment(hero *pb.DBHero, equip []*pb.DB_Equipment) (co
} }
} }
this.modelHero.mergeMainProperty(hero.Uid, hero.Id, property) this.hero.mergeMainProperty(hero.Uid, hero.Id, property)
this.modelHero.mergeAddProperty(hero.Uid, hero.Id, addProperty) this.hero.mergeAddProperty(hero.Uid, hero.Id, addProperty)
return this.modelHero.setEquipment(hero.Uid, hero.Id, equipIds) return this.hero.setEquipment(hero.Uid, hero.Id, equipIds)
} }
//英雄列表 //英雄列表
func (this *Hero) GetHeroList(uid string) []*pb.DBHero { func (this *Hero) GetHeroList(uid string) []*pb.DBHero {
list, err := this.modelHero.getHeroList(uid) list, err := this.hero.getHeroList(uid)
if err != nil { if err != nil {
return nil return nil
} }
@ -166,7 +166,7 @@ func (this *Hero) AddCardExp(uid string, heroId string, exp int32) (code pb.Erro
"exp": curExp, "exp": curExp,
} }
if err := this.modelHero.modifyHeroData(uid, heroId, update); err != nil { if err := this.hero.modifyHeroData(uid, heroId, update); err != nil {
code = pb.ErrorCode_DBError code = pb.ErrorCode_DBError
} // 修改英雄数据 } // 修改英雄数据
} else { } else {