From dca0850ff336755c68993fa6a1cb436071d59d9e Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Thu, 15 Jun 2023 11:10:16 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8B=B1=E9=9B=84=20=E5=A4=A9=E8=B5=8B?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8B=B1=E9=9B=84=E7=AD=89=E7=BA=A7=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/hero/api_talentlearn.go | 48 +++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/modules/hero/api_talentlearn.go b/modules/hero/api_talentlearn.go index d2d7e68e9..fb55b9aa8 100644 --- a/modules/hero/api_talentlearn.go +++ b/modules/hero/api_talentlearn.go @@ -26,6 +26,7 @@ func (this *apiComp) TalentLearn(session comm.IUserSession, req *pb.HeroTalentLe err error chanegCard []*pb.DBHero // 推送属性变化 res []*cfg.Gameatn // 学习天赋需要消耗的道具 + hero *pb.DBHero ) chanegCard = make([]*pb.DBHero, 0) @@ -41,8 +42,7 @@ func (this *apiComp) TalentLearn(session comm.IUserSession, req *pb.HeroTalentLe } return } - this.module.Debugf("%v", talent) - + this.module.Debugf("TalentLearn:%v", talent) } else { if req.Heroid == "" { // 英雄id不能为空 errdata = &pb.ErrorData{ @@ -66,6 +66,12 @@ func (this *apiComp) TalentLearn(session comm.IUserSession, req *pb.HeroTalentLe talent, err = this.module.modelTalent.CreateHeroTalent(session.GetUserId(), req.Heroid) if err != nil { this.module.Errorf("create talent data failed:%v", err) + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Title: pb.ErrorCode_DBError.ToString(), + Message: err.Error(), + } + return } } } @@ -79,18 +85,25 @@ func (this *apiComp) TalentLearn(session comm.IUserSession, req *pb.HeroTalentLe } return } - user := this.module.ModuleUser.GetUser(session.GetUserId()) - if user != nil { - // 校验玩家等级 - if talentConf.Condition > user.Lv { // 等级不满足 - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_UserLvNoEnough, - Title: pb.ErrorCode_UserLvNoEnough.ToString(), - Message: fmt.Sprintf("等级不满足要求:curLv = %d,lv = %d", user.Lv, talentConf.Condition), - } - - return + hero = this.module.QueryHeroByConfId(session.GetUserId(), talent.HeroId) + if hero == nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_HeroNoExist, + Title: pb.ErrorCode_HeroNoExist.ToString(), + Message: err.Error(), } + return + } + + // 校验玩家等级 + if talentConf.Condition > hero.Lv { // 等级不满足 + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_UserLvNoEnough, + Title: pb.ErrorCode_UserLvNoEnough.ToString(), + Message: fmt.Sprintf("英雄等级不满足要求:curLv = %d,lv = %d", hero.Lv, talentConf.Condition), + } + + return } // 校验 @@ -160,13 +173,8 @@ func (this *apiComp) TalentLearn(session comm.IUserSession, req *pb.HeroTalentLe } // 同步修改属性 - heroList := this.module.GetHeroList(session.GetUserId()) - for _, v := range heroList { - if v.HeroID == talent.HeroId { // 找到对应的英雄ID - this.module.modelHero.setTalentProperty(v, talentConf) - chanegCard = append(chanegCard, v) // 添加推送属性变化信息 - } - } + this.module.modelHero.setTalentProperty(hero, talentConf) + chanegCard = append(chanegCard, hero) // 添加推送属性变化信息 session.SendMsg(string(this.module.GetType()), "change", &pb.HeroChangePush{List: chanegCard}) session.SendMsg(string(this.module.GetType()), HeroTalentLearnResp, &pb.HeroTalentLearnResp{