package reputation import ( "go_dreamfactory/comm" "go_dreamfactory/pb" ) // 天赋树升级 func (this *apiComp) UpgradeCheck(session comm.IUserSession, req *pb.ReputationUpgradeReq) (errdata *pb.ErrorData) { return } func (this *apiComp) Upgrade(session comm.IUserSession, req *pb.ReputationUpgradeReq) (errdata *pb.ErrorData) { uid := session.GetUserId() rsp := &pb.ReputationUpgradeResp{} reputation := this.module.modelReputation.getDBReputation(uid) if reputation == nil { code = pb.ErrorCode_DataNotFound return } camp, ok := reputation.Camps[req.RaceType] if !ok { reputation.Camps[req.RaceType] = &pb.Camp{} } var nodeLv int32 if len(camp.Nodes) == 0 { nodeLv = 1 } else { for _, n := range camp.Nodes { if n.Nid == req.NodeId { nodeLv = n.Lv + 1 break } } } talentCfg := this.module.configure.getTalentNodeCfgBy(req.NodeId, nodeLv) if talentCfg == nil { code = pb.ErrorCode_ConfigNoFound return } if code = this.module.CheckRes(session, talentCfg.IconCos); errdata != nil { return } if camp != nil { if len(camp.Nodes) == 0 { //消耗 if c := this.module.ConsumeRes(session, talentCfg.IconCos, true); c == pb.ErrorCode_Success { camp.Nodes = append(camp.Nodes, &pb.TalentNode{ Nid: req.NodeId, Lv: 1, Status: 1, }) camp.CampAttr = this.module.modelReputation.computeAttr(camp.CampAttr, talentCfg.Attribute) } } else { for _, v := range camp.Nodes { //判断是否满级 if req.NodeId == v.Nid && v.Status == 2 { code = pb.ErrorCode_ReputationTalentFull return } else if req.NodeId == v.Nid { if !this.module.modelReputation.isReachPreNode(reputation, req.RaceType, talentCfg.PreNode, talentCfg.PreNodeLv) { code = pb.ErrorCode_ReputationNoPreNodeLv return } //消耗 if c := this.module.ConsumeRes(session, talentCfg.IconCos, true); c == pb.ErrorCode_Success { v.Lv++ camp.CampAttr = this.module.modelReputation.computeAttr(camp.CampAttr, talentCfg.Attribute) if talentCfg.NodeLv == v.Lv { v.Status = 2 } else { v.Status = 1 } } break } } } update := map[string]interface{}{ "camps": reputation.Camps, } this.module.modelReputation.updateDBReputation(uid, update) } session.SendMsg(string(this.module.GetType()), "upgrade", rsp) return }