diff --git a/comm/imodule.go b/comm/imodule.go index 18debe6f0..3d09412ba 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -153,6 +153,9 @@ type ( CheckPeachReward(session IUserSession, ctime int64) CreateOneHero(session IUserSession, heroCfgId string) (hero *pb.DBHero, atno []*pb.UserAtno, errdata *pb.ErrorData) + + // 通过卡池随机获取指定数量的英雄卡 + GetRandomCardByCardPool(cardPool string, count int32) (cards []string, err error) } //玩家 diff --git a/modules/hero/configure_comp.go b/modules/hero/configure_comp.go index 6259bd662..d3047e27a 100644 --- a/modules/hero/configure_comp.go +++ b/modules/hero/configure_comp.go @@ -558,3 +558,24 @@ func (this *configureComp) GetAllDrawRewardConf() (data map[int32]*cfg.GamedrawR } return } +func (this *configureComp) GetHeroByPoolExcept(pool string, cards map[string]struct{}) (hid string, err error) { + this.hlock.RLock() + defer this.hlock.RUnlock() + if v, ok := this.cardPool[pool]; ok { + + var sz []int32 + for _, v1 := range v { + if _, ok := cards[v1.Id]; !ok { + sz = append(sz, v1.Weight) + } + } + if len(sz) == 0 { // 异常报错提醒 + err = comm.NewNotFoundConfErr(moduleName, hero_cardpool, pool) + return + } + hid = v[comm.GetRandW(sz)].Id + return + } + err = comm.NewNotFoundConfErr(moduleName, hero_cardpool, pool) + return +} diff --git a/modules/hero/module.go b/modules/hero/module.go index 09f0af311..889fe1df5 100644 --- a/modules/hero/module.go +++ b/modules/hero/module.go @@ -1037,3 +1037,22 @@ func (this *Hero) CreateOneHero(session comm.IUserSession, heroCfgId string) (he } return } + +func (this *Hero) GetRandomCardByCardPool(cardPool string, count int32) (cards []string, err error) { + + var ( + hid string + sz map[string]struct{} + ) + for i := 0; i < int(count); i++ { + hid, err = this.configure.GetHeroByPoolExcept(cardPool, sz) + if err != nil { + return + } + sz[hid] = struct{}{} + } + for k := range sz { + cards = append(cards, k) + } + return +}