接口补充通过卡池随机获取指定数量的英雄卡
This commit is contained in:
parent
964de6c126
commit
e0b45c9c9c
@ -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)
|
||||
}
|
||||
|
||||
//玩家
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user