From e0b45c9c9cc96d54831515338464b3f02b36071d Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Thu, 2 Nov 2023 11:03:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=A1=A5=E5=85=85=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E5=8D=A1=E6=B1=A0=E9=9A=8F=E6=9C=BA=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E6=95=B0=E9=87=8F=E7=9A=84=E8=8B=B1=E9=9B=84?= =?UTF-8?q?=E5=8D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/imodule.go | 3 +++ modules/hero/configure_comp.go | 21 +++++++++++++++++++++ modules/hero/module.go | 19 +++++++++++++++++++ 3 files changed, 43 insertions(+) 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 +}