From 0077b2fdd5875cfbeff623d6dc70a5e42ec67ab1 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Sat, 31 Dec 2022 19:19:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8A=BD=E5=8D=A1=E8=A7=84?= =?UTF-8?q?=E5=88=99=20+=20=E6=8A=BD=E5=8D=A1=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/hero/api_drawCard.go | 87 ++++++++++++++++-------------------- modules/hero/module.go | 54 ++++++++++++++++++++++ 2 files changed, 92 insertions(+), 49 deletions(-) diff --git a/modules/hero/api_drawCard.go b/modules/hero/api_drawCard.go index 53ef01cc6..77f1e51a7 100644 --- a/modules/hero/api_drawCard.go +++ b/modules/hero/api_drawCard.go @@ -1,9 +1,11 @@ package hero import ( + "crypto/rand" "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" + "math/big" "google.golang.org/protobuf/proto" ) @@ -30,7 +32,10 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq pool string _mapAddHero map[string]int32 strPool []string // 10连跨多个卡池情况 + update map[string]interface{} + normalDraw bool // 是否是普通抽 ) + update = make(map[string]interface{}) _mapAddHero = make(map[string]int32, 0) cfgDraw = this.module.configure.GetGlobalConf() // 读取抽卡配置文件 if cfgDraw == nil { @@ -41,12 +46,12 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq return } szCards = make([]string, 0) - rsp := &pb.HeroDrawCardResp{} heroRecord, _ = this.module.modelRecord.GetHeroRecord(session.GetUserId()) drawCount = heroRecord.Drawcount if req.DrawType == 0 { // 普通卡池抽卡 + normalDraw = true // 获取普通抽卡池 if req.DrawCount == 1 { costAtn = cfgDraw.BasePoolCost @@ -79,6 +84,28 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq sz = append(sz, cfgDraw.BasePoolStar5) } starIndex := this.module.modelHero.GetRandW(sz) + // 特殊规则 DrawCard_5StarsInRange 第2-30次抽奖必出一个5星英雄(普通卡池) + inRangeConf := this.module.configure.GetGlobalConf().DrawCard5StarsInRange + if len(inRangeConf) == 3 { + iStart := inRangeConf[0] // 抽卡开始 + iEnd := inRangeConf[1] // 抽卡结束 + star := inRangeConf[2] + if heroRecord.Inevitable == 0 && heroRecord.Drawcount > iStart && heroRecord.Drawcount < iEnd && iEnd >= iStart { + n, _ := rand.Int(rand.Reader, big.NewInt(int64(iEnd-iStart))) + if n.Int64() < 1 { // 抽中 + starIndex = star - 3 + heroRecord.Inevitable = heroRecord.Drawcount + update["inevitable"] = heroRecord.Drawcount + } + } + // 保底情况 + if heroRecord.Drawcount == iEnd && heroRecord.Inevitable == 0 { + starIndex = star - 3 + heroRecord.Inevitable = heroRecord.Drawcount + update["inevitable"] = heroRecord.Drawcount + } + } + heroRecord.Star4++ // 4星保底数量+1 heroRecord.Star5++ // 5星保底数量+1 if starIndex == 1 { @@ -212,18 +239,19 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq } } - if req.DrawType == 0 { - update := map[string]interface{}{} - update["star4"] = heroRecord.Star4 - update["star5"] = heroRecord.Star5 - update["drawcount"] = drawCount - this.module.modelRecord.ChangeHeroRecord(session.GetUserId(), update) - } // 消耗道具 code = this.module.ConsumeRes(session, costRes, true) if code != pb.ErrorCode_Success { return } + heroRecord.Totalcount += req.DrawCount + heroRecord.Daycount += req.DrawCount + update["star4"] = heroRecord.Star4 + update["star5"] = heroRecord.Star5 + update["drawcount"] = drawCount + update["totalcount"] = heroRecord.Totalcount + update["daycount"] = heroRecord.Daycount + this.module.modelRecord.ChangeHeroRecord(session.GetUserId(), update) for _, heroId := range szCards { _mapAddHero[heroId]++ @@ -231,48 +259,9 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq _, code = this.module.CreateRepeatHeros(session, _mapAddHero, true) ///英雄招募 【玩家名称】在招募中获得了【英雄名称】! - for hid := range _mapAddHero { - if user := this.module.ModuleUser.GetUser(session.GetUserId()); user != nil { - this.chat.SendSysChatToWorld(comm.ChatSystem13, nil, 0, 0, user.Name, hid) - } else { - this.module.Errorf("no found userdata uid:%s", session.GetUserId()) - } - } - rsp.Heroes = szCards - session.SendMsg(string(this.module.GetType()), DrawCard, rsp) + this.module.SendChatMsg(session, _mapAddHero, szCards) // 任务统计 - if req.DrawType == 0 { //普通招募 - if drawCount == 10 { - sz := make(map[int32]int32, 0) - for _, star := range szStar { - sz[star]++ - } - for k := range sz { - this.module.ModuleRtask.SendToRtask(session, comm.Rtype17, 1, k) - } - } - //this.module.ModuleRtask.SendToRtask(session, comm.Rtype14, req.DrawCount) - this.module.ModuleRtask.SendToRtask(session, comm.Rtype18, req.DrawCount) - this.module.ModuleRtask.SendToRtask(session, comm.Rtype141, req.DrawCount) - this.module.ModuleRtask.SendToRtask(session, comm.Rtype143, req.DrawCount) - this.module.ModuleRtask.SendToRtask(session, comm.Rtype145, req.DrawCount) - } else { // 阵营招募 - //this.module.ModuleRtask.SendToRtask(session, comm.Rtype15, req.DrawCount) - this.module.ModuleRtask.SendToRtask(session, comm.Rtype19, req.DrawCount) - this.module.ModuleRtask.SendToRtask(session, comm.Rtype142, req.DrawCount) - this.module.ModuleRtask.SendToRtask(session, comm.Rtype144, req.DrawCount) - this.module.ModuleRtask.SendToRtask(session, comm.Rtype146, req.DrawCount) - if drawCount == 10 { - this.module.ModuleRtask.SendToRtask(session, comm.Rtype91, 1) // 阵营10连 - } - } - for _, star := range szStar { - this.module.ModuleRtask.SendToRtask(session, comm.Rtype16, star, 1) - } - if drawCount == 10 { - this.module.ModuleRtask.SendToRtask(session, comm.Rtype90, 1) - } - this.module.ModuleRtask.SendToRtask(session, comm.Rtype89, req.DrawCount) + this.module.SendTaskMsg(session, szStar, req.DrawCount, normalDraw) return } diff --git a/modules/hero/module.go b/modules/hero/module.go index 8fd5dc640..3ddca05b5 100644 --- a/modules/hero/module.go +++ b/modules/hero/module.go @@ -30,6 +30,7 @@ type Hero struct { moduleFetter comm.IHeroFetter service core.IService moduleHoroscope comm.IHoroscope + chat comm.IChat } //模块名 @@ -65,6 +66,10 @@ func (this *Hero) Start() (err error) { } this.moduleHoroscope = module.(comm.IHoroscope) + if module, err = this.service.GetModule(comm.ModuleChat); err != nil { + return + } + this.chat = module.(comm.IChat) err = this.ModuleBase.Start() event.RegisterGO(comm.EventUserOffline, this.EventUserOffline) return @@ -738,3 +743,52 @@ func (this *Hero) GetAllMaxHero(session comm.IUserSession) (code pb.ErrorCode) { } return } + +func (this *Hero) SendChatMsg(session comm.IUserSession, _mapAddHero map[string]int32, cards []string) { + rsp := &pb.HeroDrawCardResp{} + ///英雄招募 【玩家名称】在招募中获得了【英雄名称】! + for hid := range _mapAddHero { + if user := this.ModuleUser.GetUser(session.GetUserId()); user != nil { + + this.chat.SendSysChatToWorld(comm.ChatSystem13, nil, 0, 0, user.Name, hid) + } else { + this.Errorf("no found userdata uid:%s", session.GetUserId()) + } + } + rsp.Heroes = cards + session.SendMsg(string(this.GetType()), DrawCard, rsp) +} + +func (this *Hero) SendTaskMsg(session comm.IUserSession, szStar []int32, drawCount int32, itype bool) { + // 任务统计 + if itype { //普通招募 + if drawCount == 10 { + sz := make(map[int32]int32, 0) + for _, star := range szStar { + sz[star]++ + } + for k := range sz { + this.ModuleRtask.SendToRtask(session, comm.Rtype17, 1, k) + } + } + this.ModuleRtask.SendToRtask(session, comm.Rtype18, drawCount) + this.ModuleRtask.SendToRtask(session, comm.Rtype141, drawCount) + this.ModuleRtask.SendToRtask(session, comm.Rtype143, drawCount) + this.ModuleRtask.SendToRtask(session, comm.Rtype145, drawCount) + } else { // 阵营招募 + this.ModuleRtask.SendToRtask(session, comm.Rtype19, drawCount) + this.ModuleRtask.SendToRtask(session, comm.Rtype142, drawCount) + this.ModuleRtask.SendToRtask(session, comm.Rtype144, drawCount) + this.ModuleRtask.SendToRtask(session, comm.Rtype146, drawCount) + if drawCount == 10 { + this.ModuleRtask.SendToRtask(session, comm.Rtype91, 1) // 阵营10连 + } + } + for _, star := range szStar { + this.ModuleRtask.SendToRtask(session, comm.Rtype16, star, 1) + } + if drawCount == 10 { + this.ModuleRtask.SendToRtask(session, comm.Rtype90, 1) + } + this.ModuleRtask.SendToRtask(session, comm.Rtype89, drawCount) +}