From d49aae3ab7c53db9ee8932c0eba7db6e5ee41cdd Mon Sep 17 00:00:00 2001 From: zhaocy Date: Tue, 19 Jul 2022 10:47:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=8B=B1=E9=9B=84=E5=8F=A0?= =?UTF-8?q?=E5=8A=A0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/hero/model_hero.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/modules/hero/model_hero.go b/modules/hero/model_hero.go index 1bedbe713..210d35f24 100644 --- a/modules/hero/model_hero.go +++ b/modules/hero/model_hero.go @@ -96,23 +96,31 @@ func (this *ModelHero) createOneHero(uid string, heroCfgId int32) (hero *pb.DBHe return } +//初始化可叠加的英雄 +func (this *ModelHero) initHeroOverlying(uid string, heroCfgId, count int32) (hero *pb.DBHero, err error) { + hero = this.initHero(uid, heroCfgId) + if hero != nil { + hero.SameCount += count + if err = this.moduleHero.modelHero.AddList(uid, hero.Id, hero); err != nil { + this.moduleHero.Errorf("%v", err) + return + } + } + return +} + //叠加英雄 count叠加数量 func (this *ModelHero) createHeroOverlying(uid string, heroCfgId, count int32) (hero *pb.DBHero, err error) { heroes := this.moduleHero.modelHero.getHeroList(uid) if len(heroes) == 0 { - hero = this.initHero(uid, heroCfgId) - if hero != nil { - hero.SameCount = count - if err = this.moduleHero.modelHero.AddList(uid, hero.Id, hero); err != nil { - this.moduleHero.Errorf("%v", err) - return - } - } + return this.initHeroOverlying(uid, heroCfgId, count) } else { + var isExist bool for _, h := range heroes { if h.HeroID == heroCfgId && h.IsOverlying { - h.SameCount++ + isExist = true + h.SameCount += count data := map[string]interface{}{ "sameCount": h.SameCount, //叠加数 } @@ -121,8 +129,10 @@ func (this *ModelHero) createHeroOverlying(uid string, heroCfgId, count int32) ( } } } + if !isExist { + return this.initHeroOverlying(uid, heroCfgId, count) + } } - return }