From d87f822e2faee7978a97b4e1ca3f00a43f4cbc02 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Mon, 16 Jan 2023 10:27:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E4=BA=9B=E6=8E=A5=E5=8F=A3=E4=B8=8D?= =?UTF-8?q?=E6=8F=90=E4=BE=9B=E5=AF=B9=E5=A4=96=E4=BD=BF=E7=94=A8=E6=96=B9?= =?UTF-8?q?=E6=B3=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 | 25 +++++++++++++++++++++++-- modules/hero/api_fusion.go | 13 ++++++++----- modules/hero/module.go | 4 ++-- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/comm/imodule.go b/comm/imodule.go index 8a6b89724..c996d9edc 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -48,8 +48,6 @@ type ( //查询用户卡片数量 QueryHeroAmount(uId string, heroCfgId string) (amount uint32) - //创建指定数量 - CreateRepeatHero(session IUserSession, heroCfgId string, num int32) (hero *pb.DBHero, code pb.ErrorCode) // 批量创建英雄 CreateRepeatHeros(session IUserSession, heros map[string]int32, bPush bool) (hero *pb.DBHero, code pb.ErrorCode) // 获取英雄 diff --git a/modules/hero/api_drawCard.go b/modules/hero/api_drawCard.go index dd287e780..51a6bd3d1 100644 --- a/modules/hero/api_drawCard.go +++ b/modules/hero/api_drawCard.go @@ -276,12 +276,33 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq update["totalcount"] = heroRecord.Totalcount update["daycount"] = heroRecord.Daycount this.module.modelRecord.ChangeHeroRecord(session.GetUserId(), update) + szNewCards := make([]*cfg.Gameatn, 0) for _, heroId := range szCards { - + bFind := false _mapAddHero[heroId]++ + for _, v := range szNewCards { + if v.T == heroId { + v.N++ + bFind = true + break + } + } + if !bFind { + res := &cfg.Gameatn{ + A: "hero", + T: heroId, + N: 1, + } + szNewCards = append(szNewCards, res) + } } - _, code = this.module.CreateRepeatHeros(session, _mapAddHero, true) + // 获得新卡 + if code = this.module.DispenseRes(session, szNewCards, true); code != pb.ErrorCode_Success { + + this.module.Errorf("err:%v,create heros:%v,uid,%s", code, szNewCards, session.GetUserId()) + code = pb.ErrorCode_HeroCreate // 创建新英雄失败 + } ///英雄招募 【玩家名称】在招募中获得了【英雄名称】! this.module.SendChatMsg(session, _mapAddHero, szCards) diff --git a/modules/hero/api_fusion.go b/modules/hero/api_fusion.go index 0e87064e0..665c8bce2 100644 --- a/modules/hero/api_fusion.go +++ b/modules/hero/api_fusion.go @@ -3,6 +3,7 @@ package hero import ( "go_dreamfactory/comm" "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" "go_dreamfactory/utils" "google.golang.org/protobuf/proto" @@ -74,12 +75,14 @@ func (this *apiComp) Fusion(session comm.IUserSession, req *pb.HeroFusionReq) (c } // 获得新卡 - var new map[string]int32 - new = make(map[string]int32) - new[conf.Hero] = 1 - if _, err := this.module.CreateRepeatHeros(session, new, false); err != pb.ErrorCode_Success { + res := &cfg.Gameatn{ + A: "hero", + T: conf.Hero, + N: 1, + } + if code = this.module.DispenseRes(session, []*cfg.Gameatn{res}, false); code != pb.ErrorCode_Success { - this.module.Errorf("err:%v,create hero:%s,uid,%ss", err, conf.Hero, session.GetUserId()) + this.module.Errorf("err:%v,create hero:%s,uid,%ss", code, conf.Hero, session.GetUserId()) code = pb.ErrorCode_HeroCreate // 创建新英雄失败 } session.SendMsg(string(this.module.GetType()), HeroFusionResp, &pb.HeroFusionResp{Heroid: conf.Hero}) diff --git a/modules/hero/module.go b/modules/hero/module.go index 92125aad2..e771e443e 100644 --- a/modules/hero/module.go +++ b/modules/hero/module.go @@ -76,7 +76,7 @@ func (this *Hero) Start() (err error) { } //创建单个叠加英雄 -func (this *Hero) CreateRepeatHero(session comm.IUserSession, heroCfgId string, num int32) (hero *pb.DBHero, code pb.ErrorCode) { +func (this *Hero) createRepeatHero(session comm.IUserSession, heroCfgId string, num int32) (hero *pb.DBHero, code pb.ErrorCode) { var err error hero, err = this.modelHero.createHeroOverlying(session.GetUserId(), heroCfgId, num) if err == nil { @@ -272,7 +272,7 @@ func (this *Hero) CreateRepeatHeros(session comm.IUserSession, heros map[string] if num == 0 { // 数量为0 不做处理 continue } - if hero, code = this.CreateRepeatHero(session, heroCfgId, num); code != pb.ErrorCode_Success { + if hero, code = this.createRepeatHero(session, heroCfgId, num); code != pb.ErrorCode_Success { this.Errorf("create hero %s failed", heroCfgId) return }