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 }