diff --git a/comm/imodule.go b/comm/imodule.go index fc9ef5624..539b8fe35 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -152,7 +152,7 @@ type ( CreateOneHero(session IUserSession, heroCfgId string) (hero *pb.DBHero, atno []*pb.UserAtno, errdata *pb.ErrorData) // 通过卡池随机获取指定数量的英雄卡 - GetRandomCardByCardPool(cardPool string, count int32) (cards []string, err error) + GetRandomCardByCardPool(uid string, count int32) (cards []string, err error) } //玩家 diff --git a/modules/hero/module.go b/modules/hero/module.go index 4d29eeb8f..3b53dd46f 100644 --- a/modules/hero/module.go +++ b/modules/hero/module.go @@ -889,22 +889,123 @@ func (this *Hero) CreateOneHero(session comm.IUserSession, heroCfgId string) (he return } -func (this *Hero) GetRandomCardByCardPool(cardPool string, count int32) (cards []string, err error) { - +func (this *Hero) GetRandomCardByCardPool(uid string, count int32) (cards []string, err error) { var ( - hid string - sz map[string]struct{} + drawCount int32 // 抽卡次数 + star4Count int32 // 10连抽4星数量 + star5Count int32 // 10连抽5星数量 + heroRecord *pb.DBHeroRecord + strPool []string + update map[string]interface{} + drawConf *cfg.GameDrawPoolData + IsBaodiPool bool // 是否是保底卡池 + appointmap map[int32]string // 指定次数抽卡到指定卡池 + ) - sz = make(map[string]struct{}, count) - for i := 0; i < int(count); i++ { - hid, err = this.configure.GetHeroByPoolExcept(cardPool, sz) - if err != nil { - return + var drawType int32 + drawType = 9 + update = make(map[string]interface{}) + appointmap = make(map[int32]string) + if heroRecord, err = this.modelRecord.GetHeroRecord(uid); err != nil { + + return + } + drawConf, err = this.configure.GetHeroDrawConfigByType(drawType) // 获取新的抽卡配置 + if err != nil { + return + } + + for _, v := range drawConf.RecruitmentType { + appointmap[v.K] = v.S // 指定次抽数据 + } + + drawCount = heroRecord.Count[drawType] // 获取当前阵容抽卡次数 + if true { // 普通卡池抽卡 + // 校验是否达到保底卡池 + if drawConf.Protect >= drawCount { + IsBaodiPool = true + } + ///// 获取消耗 end + for i := 1; i <= int(count); i++ { // 一张一张的抽 + heroRecord.Race[drawType] += 1 + drawCount++ + heroRecord.Baodi5[drawType]++ + heroRecord.Baodi4[drawType]++ + 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[drawType] > 0 { // 橙权递增 + starWeight[2] += this.configure.GetHeroDrawWeightConfigById(drawConf.Permission, heroRecord.Baodi5[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[drawType] = 0 + strPool = append(strPool, drawConf.P4pool) + } else if starIndex == 2 { + star5Count++ + heroRecord.Baodi5[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[drawType] = 0 + strPool = append(strPool, drawConf.N4pool) + } else if starIndex == 2 { + star5Count++ + heroRecord.Baodi5[drawType] = 0 + strPool = append(strPool, drawConf.N5pool) + Is5Star = true + } + } + // 判断是否必出5星 + if heroRecord.Baodi5[drawType] >= drawConf.Baidi5 && !Is5Star { + heroRecord.Baodi5[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[drawType] >= drawConf.Baodi4 { + heroRecord.Baodi4[drawType] = 0 + star4Count++ + if IsBaodiPool { + strPool[len(strPool)-1] = drawConf.P4pool + } else { + strPool[len(strPool)-1] = drawConf.N4pool + } + continue + } } - sz[hid] = struct{}{} } - for k := range sz { - cards = append(cards, k) + // 通过卡池获得最终的英雄 + for _, v := range strPool { + if card, err := this.configure.GetHeroByPool(v); err == nil { + cards = append(cards, card) + } } + + heroRecord.Count[drawType] = drawCount + update["count"] = heroRecord.Count + update["race"] = heroRecord.Race + + update["baodi4"] = heroRecord.Baodi4 + update["baodi5"] = heroRecord.Baodi5 + err = this.modelRecord.ChangeHeroRecord(uid, update) return }