package hero import ( "fmt" "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" "go_dreamfactory/utils" "strconv" ) // 参数校验 func (this *apiComp) TalentLearnCheck(session comm.IUserSession, req *pb.HeroTalentLearnReq) (errdata *pb.ErrorData) { if req.TalentID <= 0 { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), } } return } // 天赋学习 func (this *apiComp) TalentLearn(session comm.IUserSession, req *pb.HeroTalentLearnReq) (errdata *pb.ErrorData) { var ( talent *pb.DBHeroTalent err error chanegCard []*pb.DBHero // 推送属性变化 res []*cfg.Gameatn // 学习天赋需要消耗的道具 hero *pb.DBHero ) chanegCard = make([]*pb.DBHero, 0) if errdata = this.TalentLearnCheck(session, req); errdata != nil { return } if req.ObjId != "" { if talent, err = this.module.modelTalent.GetHerotalentByObjId(session.GetUserId(), req.ObjId); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_SystemError, Title: pb.ErrorCode_SystemError.ToString(), Message: err.Error(), } return } this.module.Debugf("TalentLearn:%v", talent) } else { if req.Heroid == "" { // 英雄id不能为空 errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), } return } // 数据校验 if list, err := this.module.modelTalent.GetHerotalent(session.GetUserId()); err == nil { for _, v := range list { if v.HeroId == req.Heroid { talent = v break } } } if talent == nil { // 创建一条数据 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 } } } talentConf, err := this.module.configure.GetHeroTalent(req.TalentID) if err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } return } hero = this.module.QueryHeroByConfId(session.GetUserId(), talent.HeroId) if hero == nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_HeroNoExist, Title: pb.ErrorCode_HeroNoExist.ToString(), } 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 } // 校验 if len(talentConf.Before) == 1 && talentConf.Before[0] == 0 { // 前置解锁技能为0 if talent.Talent == nil { talent.Talent = make(map[int32]int32) } if _, ok := talent.Talent[req.TalentID]; ok { errdata = &pb.ErrorData{ Code: pb.ErrorCode_TalentRepeatLearn, // 重复激活 Title: pb.ErrorCode_TalentRepeatLearn.ToString(), } return } } else { for _, v := range talentConf.Before { if _, ok := talent.Talent[v]; !ok { errdata = &pb.ErrorData{ Code: pb.ErrorCode_TalentUnLockerBefore, // 前置技能不满足 Title: pb.ErrorCode_TalentUnLockerBefore.ToString(), } return } } } res = append(res, talentConf.Thing...) // 消耗指定的天赋点数 t := this.module.configure.GetHeroTalentBoxItem(talent.HeroId) if t != "" && talentConf.Point > 0 { curItemCount := int32(this.module.ModuleItems.QueryItemAmount(session.GetUserId(), t)) if curItemCount < talentConf.Point { // 如果数量不够 则取找其他物品替代 leftCount := talentConf.Point - curItemCount // 需要其他物品的数量 generaltp := this.module.ModuleTools.GetGlobalConf().Generaltp fp := &cfg.Gameatn{ A: generaltp.A, T: generaltp.T, N: leftCount, } if errdata = this.module.CheckRes(session, []*cfg.Gameatn{fp}); errdata != nil { return } res = append(res, fp) } else { point := &cfg.Gameatn{ A: "item", T: t, N: talentConf.Point, } res = append(res, point) } } if errdata = this.module.ConsumeRes(session, res, true); errdata != nil { return } update := make(map[string]interface{}, 0) if talentConf.Skill != 0 { skillMaxLv := this.module.configure.GetHeroSkillMaxLvConfig(uint32(talentConf.Skill)) hero.Talentskill = append(hero.Talentskill, &pb.SkillData{ SkillID: talentConf.Skill, SkillLv: skillMaxLv, }) update["talentskill"] = hero.Talentskill } // 校验通过可以加 talent.Talent[req.TalentID] = 1 update["talent"] = talent.Talent if err = this.module.modelTalent.ChangeHeroTalent(talent, update); err != nil { this.module.Errorf("update failed :%v", err) } // 同步修改属性 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{ Telnet: talent, TalentID: req.TalentID, // 返回刚学习过的天赋ID }) // 查询英雄相关信息 if heroObj := this.module.QueryHeroByConfId(session.GetUserId(), talent.HeroId); heroObj != nil { var tasks []*pb.BuriedParam tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype123, heroObj.HeroID, heroObj.Star)) tasks = append(tasks, comm.GetBuriedParam(comm.Rtype39, 1)) //累计英雄共鸣xx次 tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype124, heroObj.HeroID)) tasks = append(tasks, comm.GetBuriedParam(comm.Rtype123, 1, int32(len(talent.Talent)), heroObj.Star)) tasks = append(tasks, comm.GetBuriedParam(comm.Rtype124, 1)) tasks = append(tasks, comm.GetBuriedParam(comm.Rtype125, 1, utils.ToInt32(heroObj.HeroID))) cfg, err := this.module.configure.GetHeroConfig(heroObj.HeroID) if err == nil { tasks = append(tasks, comm.GetBuriedParam(comm.Rtype126, 1, cfg.Race)) } tasks = append(tasks, comm.GetBuriedParam(comm.Rtype127, 1, heroObj.Star)) tasks = append(tasks, comm.GetBuriedParam(comm.Rtype40, 1, int32(len(talent.Talent)))) _, err = this.module.configure.GetHeroAwakenConfig(heroObj.HeroID, heroObj.JuexingLv+1) if err != nil { // 达到满级觉醒 if heroObj.Lv == this.module.configure.GetHeroMaxLv(heroObj.Star) { if this.module.configure.GetHeroTalentMaxLv(heroObj.HeroID) == int32(len(talent.Talent)) { tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype37, heroObj.HeroID, cfg.Color)) tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype38, heroObj.HeroID)) iHeroId, _ := strconv.Atoi(heroObj.HeroID) tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype243, heroObj.HeroID, int32(iHeroId))) } } } // 满回响 if this.module.configure.GetHeroTalentMaxLv(heroObj.HeroID) == int32(len(talent.Talent)) { tasks = append(tasks, comm.GetBuriedParam(comm.Rtype128, 1, cfg.Race)) if user, err := this.module.GetUserForSession(session); err == nil { this.chat.SendSysChatToWorld(session, comm.ChatSystem10, heroObj, heroObj.Star, 0, user.Name, heroObj.HeroID) } else { this.module.Errorf("no found userdata uid:%s", session.GetUserId()) } } tasks = append(tasks, comm.GetBuriedParam(comm.Rtype199, 1)) go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { this.module.ModuleBuried.TriggerBuried(session, tasks...) this.module.WriteUserLog(session.GetUserId(), req, comm.GMResDelType, "HeroTalentLearnReq", res) }) } return }