抽卡协议修改

This commit is contained in:
meixiongfeng 2022-08-15 17:11:45 +08:00
parent e845ed0adc
commit bc9fdabfc3

View File

@ -9,7 +9,7 @@ import (
) )
func (this *apiComp) DrawCardCheck(session comm.IUserSession, req *pb.HeroDrawCardReq) (code pb.ErrorCode) { func (this *apiComp) DrawCardCheck(session comm.IUserSession, req *pb.HeroDrawCardReq) (code pb.ErrorCode) {
if req.DrawType <= 0 { // 只能是单抽或10抽 if req.DrawType < 0 { // 只能是单抽或10抽
code = pb.ErrorCode_ReqParameterError code = pb.ErrorCode_ReqParameterError
} }
return return
@ -27,28 +27,24 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq
cfgDraw *cfg.GameglobalData cfgDraw *cfg.GameglobalData
costAtn *cfg.Gameatn costAtn *cfg.Gameatn
heroRecord *pb.DBHeroRecord heroRecord *pb.DBHeroRecord
pool string
//heroRecord *pb.DBHeroRecord // 英雄扩展属性 //heroRecord *pb.DBHeroRecord // 英雄扩展属性
) )
req.DrawCount = 10 // test
cfgDraw = this.module.configure.GetGlobalConf() // 读取抽卡配置文件 cfgDraw = this.module.configure.GetGlobalConf() // 读取抽卡配置文件
code = this.DrawCardCheck(session, req)
if code != pb.ErrorCode_Success {
return
}
szCards = make([]string, 0) szCards = make([]string, 0)
rsp := &pb.HeroDrawCardResp{} rsp := &pb.HeroDrawCardResp{}
cfg := cfgDraw cfg := cfgDraw
costAtn = cfgDraw.BasePoolCost
heroRecord, _ = this.module.modelRecord.GetHeroRecord(session.GetUserId()) heroRecord, _ = this.module.modelRecord.GetHeroRecord(session.GetUserId())
drawCount = heroRecord.Drawcount drawCount = heroRecord.Drawcount
pool = this.module.modelHero.CheckPool(drawCount, cfg)
if req.DrawType == 0 { // 普通卡池抽卡 if req.DrawType == 0 { // 普通卡池抽卡
// 获取普通抽卡池 // 获取普通抽卡池
pool := this.module.modelHero.CheckPool(drawCount, cfg)
_data := this.module.configure.GetPollByType(pool)
if _data == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
costAtn = cfgDraw.BasePoolCost
costAtn.N *= req.DrawCount // 重新计算消耗数量
costRes = append(costRes, costAtn) costRes = append(costRes, costAtn)
code = this.module.CheckRes(session, costRes) code = this.module.CheckRes(session, costRes)
if code != pb.ErrorCode_Success { // 消耗数量不足直接返回 if code != pb.ErrorCode_Success { // 消耗数量不足直接返回
@ -68,35 +64,9 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq
sz = append(sz, cfgDraw.BasePoolStar5) sz = append(sz, cfgDraw.BasePoolStar5)
} }
starIndex := this.module.modelHero.GetRandW(sz)
if starIndex == 1 {
star4Max++
} else if starIndex == 2 {
star5Max++
}
if star4Max >= cfgDraw.Draw10Star4Max {
starIndex = 0
} else if star5Max >= cfgDraw.Draw10Star5Max {
starIndex = 0
}
szStar = append(szStar, starIndex)
if len(szStar) >= int(req.DrawCount) {
break
}
} }
for star := range szCards { // szStar 转 szHeroId
sz := make([]int32, 0)
for _, v := range _data[int32(star)] {
sz = append(sz, v.Weight)
}
randomIndex := this.module.modelHero.GetRandW(sz)
szCards = append(szCards, _data[int32(star)][randomIndex].Id)
}
} else { // 所有阵营抽卡都走这里 } else { // 所有阵营抽卡都走这里
pool := ""
switch req.DrawType { switch req.DrawType {
case 1: case 1:
@ -115,11 +85,7 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq
} }
costAtn.N *= req.DrawCount costAtn.N *= req.DrawCount
costRes = append(costRes, costAtn) costRes = append(costRes, costAtn)
_data := this.module.configure.GetPollByType(pool)
if _data == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
//阵营消耗 //阵营消耗
code = this.module.CheckRes(session, costRes) code = this.module.CheckRes(session, costRes)
if code != pb.ErrorCode_Success { // 消耗数量不足直接返回 if code != pb.ErrorCode_Success { // 消耗数量不足直接返回
@ -144,35 +110,37 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq
} else if starIndex == 2 { } else if starIndex == 2 {
star5Max++ star5Max++
} }
if star4Max >= cfgDraw.Draw10Star4Max { if star4Max >= cfgDraw.Draw10Star4Max || star5Max >= cfgDraw.Draw10Star5Max {
starIndex = 0
} else if star5Max >= cfgDraw.Draw10Star5Max {
starIndex = 0 starIndex = 0
} }
szStar = append(szStar, starIndex) szStar = append(szStar, starIndex+3)
if len(szStar) >= int(req.DrawCount) { if len(szStar) >= int(req.DrawCount) {
break break
} }
} }
for star := range szCards { // szStar 转 szHeroId
sz := make([]int32, 0)
for _, v := range _data[int32(star)] {
sz = append(sz, v.Weight)
}
randomIndex := this.module.modelHero.GetRandW(sz)
szCards = append(szCards, _data[int32(star)][randomIndex].Id)
}
} }
_data := this.module.configure.GetPollByType(pool)
if _data == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
for _, star := range szStar { // szStar 转 szHeroId
sz := make([]int32, 0)
for _, v := range _data[int32(star)] {
sz = append(sz, v.Weight)
}
randomIndex := this.module.modelHero.GetRandW(sz)
szCards = append(szCards, _data[int32(star)][randomIndex].Id)
}
// 更新record 配置信息 // 更新record 配置信息
update := map[string]interface{}{} update := map[string]interface{}{}
if drawCount != -1 { if drawCount != -1 {
drawCount += req.DrawCount drawCount += req.DrawCount
update["drawcount"] = drawCount update["drawcount"] = drawCount
} }
//update["race"+strconv.Itoa(int(race)-1)] = raceData
this.module.modelRecord.ChangeHeroRecord(session.GetUserId(), update) this.module.modelRecord.ChangeHeroRecord(session.GetUserId(), update)
// 消耗道具 // 消耗道具
code = this.module.ConsumeRes(session, costRes, true) code = this.module.ConsumeRes(session, costRes, true)