From 5066b599111995361c66a78058d4d9f7621b5d40 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Wed, 11 Oct 2023 13:50:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8B=B1=E9=9B=84=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/imodule.go | 2 +- modules/hero/api_drawCard.go | 4 +- modules/hero/model_hero.go | 11 ++---- modules/hero/module.go | 74 +++++++++++++++--------------------- 4 files changed, 38 insertions(+), 53 deletions(-) diff --git a/comm/imodule.go b/comm/imodule.go index 8b762a8b4..bd9e725fd 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -152,7 +152,7 @@ type ( // 检查圣桃树奖励是否发放 CheckPeachReward(session IUserSession, ctime int64) - CreateOneHero(session IUserSession, heroCfgId string, bPush bool) (hero *pb.DBHero, atno []*pb.UserAtno, errdata *pb.ErrorData) + CreateOneHero(session IUserSession, heroCfgId string) (hero *pb.DBHero, atno []*pb.UserAtno, errdata *pb.ErrorData) } //玩家 diff --git a/modules/hero/api_drawCard.go b/modules/hero/api_drawCard.go index c5bc42e93..4a53b9801 100644 --- a/modules/hero/api_drawCard.go +++ b/modules/hero/api_drawCard.go @@ -104,7 +104,7 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq var hero *pb.DBHero firstGet[heroRecord.WishHero] = false - if hero, atno, errdata = this.module.ModuleHero.CreateOneHero(session, heroRecord.WishHero, true); errdata == nil { + if hero, atno, errdata = this.module.ModuleHero.CreateOneHero(session, heroRecord.WishHero); errdata == nil { for _, v := range atno { if v.A == "hero" && v.T == heroRecord.WishHero && v.N == 1 { firstGet[heroRecord.WishHero] = true @@ -347,7 +347,7 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq firstGet[heroId] = false var atno []*pb.UserAtno - if hero, atno, errdata = this.module.ModuleHero.CreateOneHero(session, heroId, true); errdata == nil { + if hero, atno, errdata = this.module.ModuleHero.CreateOneHero(session, heroId); errdata == nil { for _, v := range atno { if v.A == "hero" && v.T == heroId && v.N == 1 { firstGet[heroId] = true diff --git a/modules/hero/model_hero.go b/modules/hero/model_hero.go index d6bdc5b4c..0f65a0383 100644 --- a/modules/hero/model_hero.go +++ b/modules/hero/model_hero.go @@ -721,15 +721,14 @@ func (this *ModelHero) resetTalentProperty(hero *pb.DBHero) { } } } - } // 创建一条英雄信息,如果有这个英雄 则转换成对应的碎片 -func (this *ModelHero) createHero(session comm.IUserSession, heroCfgId string, count int32) (hero *pb.DBHero, bFirst bool, atno []*pb.UserAtno, err error) { +func (this *ModelHero) createHero(session comm.IUserSession, heroCfgId string, count int32) (hero *pb.DBHero, atno []*pb.UserAtno, err error) { heros := make([]*pb.DBHero, 0) uid := session.GetUserId() heroCfg, _ := this.module.configure.GetHeroConfig(heroCfgId) - + bFirst := true if heroCfg == nil { err = errors.New("not found hero configID") this.module.Errorf("not found hero configID:%s", heroCfgId) @@ -750,7 +749,7 @@ func (this *ModelHero) createHero(session comm.IUserSession, heroCfgId string, c this.module.Errorf("err:%v", err) } } - bFirst = true + for _, obj := range heros { if obj.HeroID == heroCfgId { hero = obj @@ -764,6 +763,7 @@ func (this *ModelHero) createHero(session comm.IUserSession, heroCfgId string, c break } } + if bFirst { // 没有当前英雄 count -= 1 hero, err = this.initHeroOverlying(uid, heroCfgId, 1) @@ -805,7 +805,6 @@ func (this *ModelHero) createHero(session comm.IUserSession, heroCfgId string, c } } if bAdd { - res = append(res, heroCfg.Herofrag...) for _, v := range heroCfg.Herofrag { atno = append(atno, &pb.UserAtno{ @@ -858,9 +857,7 @@ func (this *ModelHero) createHero(session comm.IUserSession, heroCfgId string, c N: v.N, }) } - } - } if bChange { this.module.ModuleUser.ChangeUserExpand(session.GetUserId(), map[string]interface{}{ diff --git a/modules/hero/module.go b/modules/hero/module.go index b84a54e4b..09f0af311 100644 --- a/modules/hero/module.go +++ b/modules/hero/module.go @@ -94,7 +94,7 @@ func (this *Hero) Start() (err error) { } // 创建单个叠加英雄 -func (this *Hero) createRepeatHero(session comm.IUserSession, heroCfgId string, num int32) (hero *pb.DBHero, bFirst bool, atno []*pb.UserAtno, errdata *pb.ErrorData) { +func (this *Hero) createRepeatHero(session comm.IUserSession, heroCfgId string, num int32) (hero *pb.DBHero, atno []*pb.UserAtno, errdata *pb.ErrorData) { var ( err error tasks []*pb.BuriedParam @@ -107,11 +107,14 @@ func (this *Hero) createRepeatHero(session comm.IUserSession, heroCfgId string, Message: err.Error(), } } - hero, bFirst, atno, err = this.modelHero.createHero(session, heroCfgId, num) - if err == nil && bFirst { - - tasks = append(tasks, comm.GetBuriedParam(comm.Rtype228, cfg.Star)) - return + hero, atno, err = this.modelHero.createHero(session, heroCfgId, num) + if err == nil { + for _, v := range atno { + if v.A == "hero" && v.N == 1 { + tasks = append(tasks, comm.GetBuriedParam(comm.Rtype228, cfg.Star)) + break + } + } } if err != nil { errdata = &pb.ErrorData{ @@ -212,24 +215,24 @@ func (this *Hero) EventUserOffline(uid, sessionid string) { // 批量创建多个英雄 func (this *Hero) CreateRepeatHeros(session comm.IUserSession, heros map[string]int32, bPush bool) (atno []*pb.UserAtno, errdata *pb.ErrorData) { var ( - changeList []*pb.DBHero - firstGet []string - bFirst bool - hero *pb.DBHero szAddHero []string + changeList []*pb.DBHero + hero *pb.DBHero ) for heroCfgId, num := range heros { if num == 0 { // 数量为0 不做处理 continue } - if hero, bFirst, atno, errdata = this.createRepeatHero(session, heroCfgId, num); errdata != nil { + if hero, atno, errdata = this.createRepeatHero(session, heroCfgId, num); errdata != nil { this.Errorf("create hero %s failed", heroCfgId) continue } szAddHero = append(szAddHero, heroCfgId) - if bFirst { - firstGet = append(firstGet, heroCfgId) - changeList = append(changeList, hero) + for _, v := range atno { + if v.A == "hero" && v.N == 1 { + changeList = append(changeList, hero) + break + } } } if db.IsCross() { @@ -237,19 +240,9 @@ func (this *Hero) CreateRepeatHeros(session comm.IUserSession, heros map[string] } else { go this.moduleFetter.AddHerosFetterData(session.GetUserId(), szAddHero) } - if bPush { //推送 - if len(changeList) > 0 { - session.SendMsg("hero", "change", &pb.HeroChangePush{List: changeList}) - } - - // 首次获得英雄 则推送 - if len(firstGet) > 0 { - session.SendMsg("hero", "firstget", &pb.HeroFirstGetPush{ - HeroId: firstGet, - }) - } + if len(changeList) > 0 { + session.SendMsg("hero", "change", &pb.HeroChangePush{List: changeList}) } - return } @@ -1016,36 +1009,31 @@ func (this *Hero) AddHerosExp(session comm.IUserSession, heroObjs []string, exp } // 获得一个英雄 -func (this *Hero) CreateOneHero(session comm.IUserSession, heroCfgId string, bPush bool) (hero *pb.DBHero, atno []*pb.UserAtno, errdata *pb.ErrorData) { +func (this *Hero) CreateOneHero(session comm.IUserSession, heroCfgId string) (hero *pb.DBHero, atno []*pb.UserAtno, errdata *pb.ErrorData) { var ( - //hero *pb.DBHero - firstGet []string - bFirst bool - szAddHero []string + szAddHero []string + changeList []*pb.DBHero ) - if hero, bFirst, atno, errdata = this.createRepeatHero(session, heroCfgId, 1); errdata != nil { + if hero, atno, errdata = this.createRepeatHero(session, heroCfgId, 1); errdata != nil { this.Errorf("create hero %s failed", heroCfgId) return } szAddHero = append(szAddHero, heroCfgId) - if bFirst { - firstGet = append(firstGet, heroCfgId) - } + if db.IsCross() { go this.moduleFetter.SendRpcAddHero(session.GetUserId(), szAddHero, session.GetServiecTag()) } else { go this.moduleFetter.AddHerosFetterData(session.GetUserId(), szAddHero) // 异步调用 } - if bPush { //推送 - session.SendMsg("hero", "change", &pb.HeroChangePush{List: []*pb.DBHero{hero}}) - // 首次获得英雄 则推送 - if len(firstGet) > 0 { - session.SendMsg("hero", "firstget", &pb.HeroFirstGetPush{ - HeroId: firstGet, - }) + for _, v := range atno { + if v.A == "hero" && v.N == 1 { + changeList = append(changeList, hero) + break } } - + if len(changeList) > 0 { + session.SendMsg("hero", "change", &pb.HeroChangePush{List: changeList}) + } return }