From 74c239a7212bb067fa4f3fe1ee201e5060366d47 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Tue, 29 Aug 2023 10:43:15 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8B=B1=E9=9B=84=E6=8E=A5=E5=8F=A3=E6=89=A9?= =?UTF-8?q?=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/imodule.go | 2 + modules/hero/api_drawCard.go | 89 ++++++++++++++++++++---------------- modules/hero/module.go | 35 ++++++++++++++ 3 files changed, 86 insertions(+), 40 deletions(-) diff --git a/comm/imodule.go b/comm/imodule.go index afbb3e41e..3987a7918 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -155,6 +155,8 @@ type ( // 检查圣桃树奖励是否发放 CheckPeachReward(session IUserSession, ctime int64) + + CreateOneHero(session IUserSession, heroCfgId string, bPush bool) (hero *pb.DBHero, atno []*pb.UserAtno, errdata *pb.ErrorData) } //玩家 diff --git a/modules/hero/api_drawCard.go b/modules/hero/api_drawCard.go index 163d03e9a..5c81986b3 100644 --- a/modules/hero/api_drawCard.go +++ b/modules/hero/api_drawCard.go @@ -21,25 +21,25 @@ func (this *apiComp) DrawCardCheck(session comm.IUserSession, req *pb.HeroDrawCa //抽卡 func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq) (errdata *pb.ErrorData) { var ( - szCards []string // 最终抽到的卡牌 - drawCount int32 // 抽卡次数 - szStar []int32 //星级 - costRes []*cfg.Gameatn // 消耗 - star4Count int32 // 10连抽4星数量 - star5Count int32 // 10连抽5星数量 - cfgGlobal *cfg.GameGlobalData // 全局配置 - heroRecord *pb.DBHeroRecord - atno []*pb.UserAtno // 最终获得的资源 - strPool []string // 10连跨多个卡池情况 - update map[string]interface{} - normalDraw bool // 是否是普通抽 - drawConf *cfg.GameDrawPoolData - err error - + szCards []string // 最终抽到的卡牌 + drawCount int32 // 抽卡次数 + szStar []int32 //星级 + costRes []*cfg.Gameatn // 消耗 + star4Count int32 // 10连抽4星数量 + star5Count int32 // 10连抽5星数量 + cfgGlobal *cfg.GameGlobalData // 全局配置 + heroRecord *pb.DBHeroRecord + strPool []string // 10连跨多个卡池情况 + update map[string]interface{} + normalDraw bool // 是否是普通抽 + drawConf *cfg.GameDrawPoolData + err error + atno []*pb.UserAtno IsBaodiPool bool // 是否是保底卡池 appointmap map[int32]string // 指定次数抽卡到指定卡池 // 首次获得英雄 firstGet map[string]bool + reward []*cfg.Gameatn // 许愿石奖励 ) update = make(map[string]interface{}) appointmap = make(map[int32]string) @@ -110,22 +110,22 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq } return } - if errdata, atno = this.module.DispenseAtno(session, []*cfg.Gameatn{{ - A: "hero", - T: heroRecord.WishHero, - N: 1, - }}, true); errdata == nil { - firstGet[heroRecord.WishHero] = true - rsp.Data = append(rsp.Data, &pb.AtnoData{Atno: atno}) + var hero *pb.DBHero + firstGet[heroRecord.WishHero] = false + + if hero, atno, errdata = this.module.ModuleHero.CreateOneHero(session, heroRecord.WishHero, true); errdata == nil { for _, v := range atno { - if v.A == "hero" && v.N == 1 { + if v.A == "hero" && v.T == heroRecord.WishHero && v.N == 1 { + firstGet[heroRecord.WishHero] = true if user := this.module.ModuleUser.GetUser(session.GetUserId()); user != nil { // 广播 首次获得英雄 - this.chat.SendSysChatToWorld(comm.ChatSystem13, nil, 0, 0, user.Name, v.T) + if HeroConf, err := this.module.configure.GetHeroConfig(heroRecord.WishHero); err == nil { + this.chat.SendSysChatToWorld(comm.ChatSystem13, hero, HeroConf.Star, 0, user.Name, v.T) + } } - } else if v.A == "hero" && v.N == 0 { - firstGet[v.T] = false } } + + rsp.Data = append(rsp.Data, &pb.AtnoData{Atno: atno}) } else { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, @@ -320,14 +320,18 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq update["baodi5"] = heroRecord.Baodi5 for _, heroId := range szCards { - var reward []*cfg.Gameatn - if c, err := this.module.configure.GetHeroConfig(heroId); err == nil { - szStar = append(szStar, c.Star) // 获得许愿石 + //var + 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 c.Star == 4 { + if HeroConf.Star == 4 { tmp = this.module.ModuleTools.GetGlobalConf().RewardStar4 reward = append(reward, tmp) - } else if c.Star == 5 { + } else if HeroConf.Star == 5 { tmp = this.module.ModuleTools.GetGlobalConf().RewardStar5 reward = append(reward, tmp) @@ -353,22 +357,27 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq } } } - reward = append(reward, &cfg.Gameatn{ - A: "hero", - T: heroId, - N: 1, - }) - firstGet[heroId] = true + + firstGet[heroId] = false var atno []*pb.UserAtno - if errdata, atno = this.module.DispenseAtno(session, reward, true); errdata == nil { + if hero, atno, errdata = this.module.ModuleHero.CreateOneHero(session, heroId, true); errdata == nil { for _, v := range atno { - if v.A == "hero" && v.T == heroId && v.N == 0 { - firstGet[heroId] = false + if v.A == "hero" && v.T == heroId && v.N == 1 { + firstGet[heroId] = true + if user := this.module.ModuleUser.GetUser(session.GetUserId()); user != nil { // 广播 首次获得英雄 + this.chat.SendSysChatToWorld(comm.ChatSystem13, hero, HeroConf.Star, 0, user.Name, v.T) + } } } rsp.Data = append(rsp.Data, &pb.AtnoData{Atno: atno}) } + + } + + // 发放许愿石奖励 + if errdata, _ = this.module.DispenseAtno(session, reward, true); errdata != nil { + return } rsp.FirstGet = firstGet this.module.modelRecord.ChangeHeroRecord(session.GetUserId(), update) diff --git a/modules/hero/module.go b/modules/hero/module.go index 2ea2aa467..7e33a7abd 100644 --- a/modules/hero/module.go +++ b/modules/hero/module.go @@ -1090,3 +1090,38 @@ func (this *Hero) AddHerosExp(session comm.IUserSession, heroObjs []string, exp session.SendMsg(string(this.GetType()), "change", &pb.HeroChangePush{List: _changeHero}) return } + +// 获得一个英雄 +func (this *Hero) CreateOneHero(session comm.IUserSession, heroCfgId string, bPush bool) (hero *pb.DBHero, atno []*pb.UserAtno, errdata *pb.ErrorData) { + var ( + //hero *pb.DBHero + firstGet []string + bFirst bool + szAddHero []string + ) + + if hero, bFirst, 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() { + this.moduleFetter.SendRpcAddHero(session.GetUserId(), szAddHero, session.GetServiecTag()) + } else { + 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, + }) + } + } + + return +}