package hero import ( "fmt" "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" ) func (this *apiComp) DrawCardCheck(session comm.IUserSession, req *pb.HeroDrawCardReq) (errdata *pb.ErrorData) { if req.DrawType < 0 || (req.DrawCount != 1 && req.DrawCount != 10) { // 只能是单抽或10抽 errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), } } return } //抽卡 func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq) (errdata *pb.ErrorData) { var ( szCards []string // 最终抽到的卡牌 drawCount int32 // 抽卡次数 szStar []int32 //星级 costRes []*cfg.Gameatn // 消耗 star4Count int32 // 10连抽4星数量 star5Count int32 // 10连抽5星数量 cfgGlobal *cfg.GameGlobalData // 全局配置 heroRecord *pb.DBHeroRecord atno []*pb.UserAtno // 最终获得的资源 strPool []string // 10连跨多个卡池情况 update map[string]interface{} normalDraw bool // 是否是普通抽 drawConf *cfg.GameDrawPoolData err error IsBaodiPool bool // 是否是保底卡池 appointmap map[int32]string // 指定次数抽卡到指定卡池 ) appointmap = make(map[int32]string) szCards = make([]string, 0) heroRecord, _ = this.module.modelRecord.GetHeroRecord(session.GetUserId()) if heroRecord.Baodi4 == nil { heroRecord.Baodi4 = make(map[int32]int32) } if heroRecord.Baodi5 == nil { heroRecord.Baodi5 = make(map[int32]int32) } if heroRecord.Count == nil { heroRecord.Count = make(map[int32]int32) } // 准备数据 ///////////////////////////////////// drawConf, err = this.module.configure.GetHeroDrawConfigByType(req.DrawType + comm.DrawCardType0) // 获取新的抽卡配置 if err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), Message: err.Error(), } return } for _, v := range drawConf.RecruitmentType { appointmap[v.K] = v.S // 指定次抽数据 } //////////////////////////////////////////////////////// update = make(map[string]interface{}) cfgGlobal = this.module.ModuleTools.GetGlobalConf() // 读取抽卡配置文件 if cfgGlobal == nil { return } // 每日抽卡上限校验 if cfgGlobal.DrawToplimit < heroRecord.Daycount { errdata = &pb.ErrorData{ Code: pb.ErrorCode_HeroDrwaMax, Title: pb.ErrorCode_HeroDrwaMax.ToString(), Message: fmt.Sprintf("单日抽卡达到上限,抽卡次数:%d", cfgGlobal.DrawToplimit), } return } if errdata = this.DrawCardCheck(session, req); errdata != nil { return } drawCount = heroRecord.Count[req.DrawType] // 获取当前阵容抽卡次数 if true { // 普通卡池抽卡 ////// 获取消耗 star if req.DrawCount == 1 { costRes = drawConf.ConsumeA // 单抽消耗 } else { costRes = drawConf.ConsumeB // 十连消耗 } if errdata = this.module.CheckRes(session, costRes); errdata != nil { // 消耗数量不足直接返回 return } // 校验是否达到保底卡池 if drawConf.Protect >= drawCount { IsBaodiPool = true } ///// 获取消耗 end for i := 1; i <= int(req.DrawCount); i++ { // 一张一张的抽 drawCount++ if v, ok := appointmap[drawCount]; ok { // 优先校验是否是指定抽 strPool = append(strPool, v) //找到了 continue } Is5Star := false starWeight := []int32{drawConf.Star3w, drawConf.Star4w, drawConf.Star5w} // 随机获取三星 if drawConf.Permission != -1 && heroRecord.Baodi5[req.DrawType] > 0 { // 橙权递增 starWeight[2] += this.module.configure.GetHeroDrawWeightConfigById(drawConf.Permission, heroRecord.Baodi5[req.DrawType]) } starIndex := comm.GetRandW(starWeight) // 3 4 5 星索引 if IsBaodiPool { if starIndex == 0 { strPool = append(strPool, drawConf.P3pool) } else if starIndex == 1 { star4Count++ heroRecord.Baodi4[req.DrawType] = 0 strPool = append(strPool, drawConf.P4pool) } else if starIndex == 2 { star5Count++ heroRecord.Baodi5[req.DrawType] = 0 strPool = append(strPool, drawConf.P5pool) Is5Star = true } } else { if starIndex == 0 { strPool = append(strPool, drawConf.N3pool) } else if starIndex == 1 { star4Count++ heroRecord.Baodi4[req.DrawType] = 0 strPool = append(strPool, drawConf.N4pool) } else if starIndex == 2 { star5Count++ heroRecord.Baodi5[req.DrawType] = 0 strPool = append(strPool, drawConf.N5pool) Is5Star = true } } // 判断是否必出5星 if heroRecord.Baodi5[req.DrawType] >= drawConf.Baidi5 && !Is5Star { heroRecord.Baodi5[req.DrawType] = 0 star5Count++ if IsBaodiPool { strPool[len(strPool)-1] = drawConf.P5pool } else { strPool[len(strPool)-1] = drawConf.N5pool } Is5Star = true continue } // 判断是否必出4星 if heroRecord.Baodi4[req.DrawType] >= drawConf.Baodi4 { heroRecord.Baodi4[req.DrawType] = 0 star4Count++ if IsBaodiPool { strPool[len(strPool)-1] = drawConf.P4pool } else { strPool[len(strPool)-1] = drawConf.N4pool } continue } heroRecord.Baodi5[req.DrawType]++ heroRecord.Baodi4[req.DrawType]++ if req.DrawType == 10 { if star4Count >= cfgGlobal.Draw10Star4Max { // 10连抽最大4星数量 if IsBaodiPool { strPool[len(strPool)-1] = drawConf.P3pool } else { strPool[len(strPool)-1] = drawConf.N3pool } } if star5Count >= cfgGlobal.Draw10Star5Max { // 10连抽最大5星数量 if IsBaodiPool { strPool[len(strPool)-1] = drawConf.P3pool } else { strPool[len(strPool)-1] = drawConf.N3pool } } } //抽出5星英雄后A次抽奖内不会再抽到5星英雄(普通卡池+阵营卡池) if heroRecord.Race[req.DrawType] >= cfgGlobal.DrawCardContinuousRestrictionStar5 && Is5Star { if IsBaodiPool { strPool[len(strPool)-1] = drawConf.P3pool } else { strPool[len(strPool)-1] = drawConf.N3pool } Is5Star = false } } } // 通过卡池获得最终的英雄 for _, v := range strPool { card, err := this.module.configure.GetHeroByPool(v) if err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } return } szCards = append(szCards, card) } // 消耗道具 if errdata = this.module.ConsumeRes(session, costRes, true); errdata != nil { return } heroRecord.Totalcount += req.DrawCount heroRecord.Daycount += req.DrawCount heroRecord.Count[req.DrawType] = drawCount update["drawcount"] = drawCount update["count"] = heroRecord.Count update["totalcount"] = heroRecord.Totalcount update["daycount"] = heroRecord.Daycount update["baodi4"] = heroRecord.Baodi4 update["baodi5"] = heroRecord.Baodi5 this.module.modelRecord.ChangeHeroRecord(session.GetUserId(), update) rsp := &pb.HeroDrawCardResp{ Data: []*pb.AtnoData{}, } for _, heroId := range szCards { if errdata, atno = this.module.DispenseAtno(session, []*cfg.Gameatn{{ A: "hero", T: heroId, N: 1, }}, true); errdata == nil { rsp.Data = append(rsp.Data, &pb.AtnoData{Atno: atno}) for _, v := range atno { if v.A == "hero" && v.N == 1 { if user := this.module.ModuleUser.GetUser(session.GetUserId()); user != nil { // 广播 首次获得英雄 this.chat.SendSysChatToWorld(comm.ChatSystem13, nil, 0, 0, user.Name, v.T) } } } } else { return } } session.SendMsg(string(this.module.GetType()), DrawCard, rsp) if req.DrawType == 0 { normalDraw = true } // 任务统计 this.module.SendTaskMsg(session, szStar, req.DrawCount, normalDraw) return }