From e8212f4f7c8ebbc9868055279cfb4e97a9a04fea Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Fri, 15 Dec 2023 18:32:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=8D=A1=E7=89=87=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/hero/api_drawCard.go | 83 ++++++++++++-------------- modules/hero/model_hero.go | 111 +++++++++++++++++++++++++++++++---- modules/hero/module.go | 46 ++++++++++++++- 3 files changed, 180 insertions(+), 60 deletions(-) diff --git a/modules/hero/api_drawCard.go b/modules/hero/api_drawCard.go index 078ecccd7..70c720be0 100644 --- a/modules/hero/api_drawCard.go +++ b/modules/hero/api_drawCard.go @@ -243,50 +243,40 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq update["daycount"] = heroRecord.Daycount update["baodi4"] = heroRecord.Baodi4 update["baodi5"] = heroRecord.Baodi5 - + var tmp4 *cfg.Gameatn + tmp4 = this.module.ModuleTools.GetGlobalConf().RewardStar4 + var tmp5 *cfg.Gameatn + tmp5 = this.module.ModuleTools.GetGlobalConf().RewardStar5 for _, heroId := range szCards { - var ( - hero *pb.DBHero - HeroConf *cfg.GameHeroData - ) - if HeroConf, err = this.module.configure.GetHeroConfig(heroId); err == nil { - szStar = append(szStar, HeroConf.Star) // 获得许愿石 - var tmp *cfg.Gameatn - if HeroConf.Star == 4 { - tmp = this.module.ModuleTools.GetGlobalConf().RewardStar4 - reward = append(reward, tmp) - } else if HeroConf.Star == 5 { - tmp = this.module.ModuleTools.GetGlobalConf().RewardStar5 - reward = append(reward, tmp) - - if req.DrawType == comm.DrawCardType5 { // 限时招募 - if heroRecord.LimitHero == "" { - if conf := this.module.configure.GetApportHeroReplaceConfig(); conf != nil { - heroRecord.LimitHero = conf.InitHero - update["limitHero"] = heroRecord.LimitHero - } - } - heroId = heroRecord.LimitHero // 替换成心愿英雄 - } + HeroConf, _ := this.module.configure.GetHeroConfig(heroId) + szStar = append(szStar, HeroConf.Star) // 获得许愿石 + if HeroConf.Star == 4 { + if rsp.Wish == nil { + rsp.Wish = &pb.UserAtno{A: tmp4.A, T: tmp4.T, N: tmp4.N} + } else { + rsp.Wish.N += tmp4.N } - if tmp != nil { - if rsp.Wish == nil { - rsp.Wish = &pb.UserAtno{ - A: tmp.A, - T: tmp.T, - N: tmp.N, + reward = append(reward, tmp4) + } else if HeroConf.Star == 5 { + if rsp.Wish == nil { + rsp.Wish = &pb.UserAtno{A: tmp5.A, T: tmp5.T, N: tmp5.N} + } else { + rsp.Wish.N += tmp5.N + } + reward = append(reward, tmp5) + if req.DrawType == comm.DrawCardType5 { // 限时招募 + if heroRecord.LimitHero == "" { + if conf := this.module.configure.GetApportHeroReplaceConfig(); conf != nil { + heroRecord.LimitHero = conf.InitHero + update["limitHero"] = heroRecord.LimitHero } - } else { - rsp.Wish.N += tmp.N } + heroId = heroRecord.LimitHero // 替换成心愿英雄 } } - var atno []*pb.UserAtno - if req.DrawType == 1 { - - if hero, atno, err = this.module.modelHero.imitateHero(session, heroId); err == nil { + if _, atno, err = this.module.modelHero.imitateHero(session, heroId); err == nil { rsp.Data = append(rsp.Data, &pb.AtnoData{Atno: atno}) } else { errdata = &pb.ErrorData{ @@ -297,6 +287,7 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq return } } else { + hero := &pb.DBHero{} if hero, atno, errdata = this.module.CreateOneHero(session, heroId); errdata == nil { for _, v := range atno { if v.A == "hero" && v.T == heroId && v.N == 1 { @@ -305,11 +296,15 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq } } } - rsp.Data = append(rsp.Data, &pb.AtnoData{Atno: atno}) } } } + // if req.DrawType != 1 { + // if _, rsp.Data, errdata = this.module.DrawCardHero(session, szCards); errdata != nil { + // return + // } + // } if req.DrawType == 1 { heroRecord.Selectcount += 1 // 抽卡次数+1 @@ -328,8 +323,8 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq if req.DrawType != 1 { // 任务统计 - this.module.SendTaskMsg(session, szStar, req.DrawCount, req.DrawType, szCards) go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { + this.module.SendTaskMsg(session, szStar, req.DrawCount, req.DrawType, szCards) this.module.WriteUserLog(session.GetUserId(), req, comm.GMResAddType, "HeroDrawCardReq", atno) this.module.WriteUserLog(session.GetUserId(), req, comm.GMResDelType, "HeroDrawCardReq", costRes) }) @@ -395,17 +390,17 @@ func (this *apiComp) wishDrawCard(session comm.IUserSession, heroRecord *pb.DBHe if hero, atno, errdata = this.module.CreateOneHero(session, heroRecord.WishHero); errdata == nil { for _, v := range atno { if v.A == "hero" && v.T == heroRecord.WishHero && v.N == 1 { - if user, err := this.module.ModuleUser.GetUser(session.GetUserId()); err == nil { // 广播 首次获得英雄 - if HeroConf, err := this.module.configure.GetHeroConfig(heroRecord.WishHero); err == nil { - this.chat.SendSysChatToWorld(comm.ChatSystem13, hero, HeroConf.Star, 0, user.Name, v.T) + go func() { + if user, err := this.module.ModuleUser.GetUser(session.GetUserId()); err == nil { // 广播 首次获得英雄 + if HeroConf, err := this.module.configure.GetHeroConfig(heroRecord.WishHero); err == nil { + this.chat.SendSysChatToWorld(comm.ChatSystem13, hero, HeroConf.Star, 0, user.Name, v.T) + } } - } + }() } } rsp.Data = append(rsp.Data, &pb.AtnoData{Atno: atno}) - } else { - return } if errdata = this.module.ConsumeRes(session, costRes, true); errdata != nil { diff --git a/modules/hero/model_hero.go b/modules/hero/model_hero.go index de6e549bd..150d4301c 100644 --- a/modules/hero/model_hero.go +++ b/modules/hero/model_hero.go @@ -243,19 +243,6 @@ func (this *ModelHero) setEquipProperty(hero *pb.DBHero, equip []*pb.DB_Equipmen } } - //for k, v := range addProperty { - //addProperty[k] += v - // switch k { - // case comm.AtkPro: - // addProperty[comm.Atk] += int32(math.Floor((float64(v) / 1000) * float64(hero.Property[comm.Atk]))) - // case comm.DefPro: - // addProperty[comm.Def] += int32(math.Floor((float64(v) / 1000) * float64(hero.Property[comm.Def]))) - // case comm.HpPro: - // addProperty[comm.Hp] += int32(math.Floor((float64(v) / 1000) * float64(hero.Property[comm.Hp]))) - // case comm.SpeedPro: - // addProperty[comm.Speed] += int32(math.Floor((float64(v) / 1000) * float64(hero.Property[comm.Speed]))) - // } - //} this.mergeAddProperty(hero.Uid, hero, addProperty, equipSkill) } @@ -1030,3 +1017,101 @@ func (this *ModelHero) imitateHero(session comm.IUserSession, heroCfgId string) return } + +func (this *ModelHero) drawcardcreateHero(session comm.IUserSession, ids []string) (hs []*pb.DBHero, szAtno []*pb.AtnoData, err error) { + heros := make([]*pb.DBHero, 0) + uid := session.GetUserId() + rst, _ := this.module.ModuleUser.GetUserExpand(session.GetUserId()) + list := this.module.ModuleTools.GetGlobalConf().Moonshopmoney // 3星卡技能满了后1个碎片转化的货币数量3星/4星/5星 + if err = this.GetList(uid, &heros); err != nil { + this.module.Errorf("err:%v", err) + } + for _, heroCfgId := range ids { + hero := &pb.DBHero{} + res := make([]*cfg.Gameatn, 0) + heroCfg, _ := this.module.configure.GetHeroConfig(heroCfgId) + + for _, obj := range heros { + if obj.HeroID == heroCfgId { + hero = obj + hs = append(hs, nil) + break + } + } + + if hero.Id == "" { // 没有当前英雄 + if hero, err = this.initHeroOverlying(uid, heroCfgId, 1); err == nil { + hs = append(hs, hero) + heros = append(heros, hero) + } else { + return + } + } + + // 转碎片处理 + bAdd := false + //守护之星 获得 + if heroCfg.Herofragnum > 0 { + if v, ok := rst.Herofrag[hero.HeroID]; !ok { + rst.Herofrag[hero.HeroID] = 1 + bAdd = true + } else if heroCfg.Herofragnum > v { + rst.Herofrag[hero.HeroID] += 1 + bAdd = true + } + } + if bAdd { + res = append(res, heroCfg.Herofrag...) + } else { + for pos, v := range list { + if int32(pos)+3 == heroCfg.Star && v > 0 { + res = append(res, &cfg.Gameatn{ + A: "attr", + T: "moongold", + N: v, + }) + break + } + } + } + bAdd = false // 初始化 + // expitem 获得 + if heroCfg.Expitemnum > 0 { + if v, ok := rst.Expitem[hero.HeroID]; ok { + if heroCfg.Expitemnum > v { + rst.Expitem[hero.HeroID] += 1 + bAdd = true + } + } else { + rst.Expitem[hero.HeroID] = 1 + bAdd = true + } + } + if bAdd { + res = append(res, heroCfg.Expitem...) + } + + _, atno := this.module.DispenseAtno(session, res, true) + + atno = append(atno, &pb.UserAtno{ + A: "hero", + T: hero.HeroID, + N: 1, + O: hero.Id, + }) + + szAtno = append(szAtno, &pb.AtnoData{ + Atno: atno, + }) + go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { + this.module.WriteUserLog(session.GetUserId(), heroCfgId, comm.GMResAddType, "create hero", atno) + }) + } + + this.module.ModuleUser.ChangeUserExpand(session.GetUserId(), map[string]interface{}{ + "herofrag": rst.Herofrag, + "expitem": rst.Expitem, + }) + + return +} diff --git a/modules/hero/module.go b/modules/hero/module.go index 0fecb1e95..fee6f8d32 100644 --- a/modules/hero/module.go +++ b/modules/hero/module.go @@ -113,8 +113,7 @@ func (this *Hero) createRepeatHero(session comm.IUserSession, heroCfgId string, break } } - } - if err != nil { + } else { errdata = &pb.ErrorData{ Code: pb.ErrorCode_HeroCreate, Title: pb.ErrorCode_HeroCreate.ToString(), @@ -557,7 +556,7 @@ func (this *Hero) SendTaskMsg(session comm.IUserSession, szStar []int32, drawCou tasks = append(tasks, comm.GetBuriedParam(comm.Rtype246, colorCount)) } tasks = append(tasks, comm.GetBuriedParam(comm.Rtype89, drawCount)) - go this.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { + go this.AsynHandleSession(session, func(session comm.IUserSession) { this.ModuleBuried.TriggerBuried(session, tasks...) }) } @@ -1022,3 +1021,44 @@ func (this *Hero) GetRandomCardByCardPool(uid string, count int32) (cards []stri err = this.modelRecord.ChangeHeroRecord(uid, update) return } + +func (this *Hero) DrawCardHero(session comm.IUserSession, heroCfgId []string) (hero []*pb.DBHero, szAtno []*pb.AtnoData, errdata *pb.ErrorData) { + var ( + szAddHero []string + tasks []*pb.BuriedParam + err error + ) + if hero, szAtno, err = this.modelHero.drawcardcreateHero(session, heroCfgId); err != nil { + return + } + + for _, id := range heroCfgId { + if cfg, err := this.configure.GetHeroConfig(id); err == nil { + tasks = append(tasks, comm.GetBuriedParam(comm.Rtype1, 1, utils.ToInt32(id))) + tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype30, id, cfg.Color)) + tasks = append(tasks, comm.GetBuriedParam(comm.Rtype31, 1, cfg.Color)) + } else { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ConfigNoFound, + Title: pb.ErrorCode_ConfigNoFound.ToString(), + Message: err.Error(), + } + } + } + + go this.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { + this.ModuleBuried.TriggerBuried(session, tasks...) + }) + for _, obj := range hero { + if obj != nil { + szAddHero = append(szAddHero, obj.HeroID) + } + } + if db.IsCross() { + go this.moduleFetter.SendRpcAddHero(session.GetUserId(), szAddHero, session.GetServiecTag()) + } else { + go this.moduleFetter.AddHerosFetterData(session.GetUserId(), szAddHero) // 异步调用 + } + + return +}