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{