go_dreamfactory/modules/hero/api_selectdraw.go
2023-11-27 10:13:16 +08:00

235 lines
6.7 KiB
Go

package hero
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
)
//参数校验
func (this *apiComp) SelectDrawCheck(session comm.IUserSession, req *pb.HeroSelectDrawReq) (errdata *pb.ErrorData) {
return
}
func (this *apiComp) SelectDraw(session comm.IUserSession, req *pb.HeroSelectDrawReq) (errdata *pb.ErrorData) {
var (
err error
result *pb.DBSelectDraw
drawType int32
)
if result, err = this.module.modelSelect.GetDrawSelectData(session.GetUserId()); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
return
}
if result.Complete {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_HeroSelectDrawComplete,
Title: pb.ErrorCode_HeroSelectDrawComplete.ToString(),
}
return
}
var (
szCards []string // 最终抽到的卡牌
drawCount 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{}
drawConf *cfg.GameDrawPoolData
IsBaodiPool bool // 是否是保底卡池
appointmap map[int32]string // 指定次数抽卡到指定卡池
)
drawType = comm.DrawCardTypeNew // 抽卡类型 1
drawCount = 10 // 10连
update = make(map[string]interface{})
appointmap = make(map[int32]string)
szCards = make([]string, 0)
if heroRecord, err = this.module.modelRecord.GetHeroRecord(session.GetUserId()); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
return
}
// 准备数据
/////////////////////////////////////
drawConf, err = this.module.configure.GetHeroDrawConfigByType(drawType) // 获取新的抽卡配置
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
Message: err.Error(),
}
return
}
for _, v := range drawConf.RecruitmentType {
appointmap[v.K] = v.S // 指定次抽数据
}
////////////////////////////////////////////////////////
cfgGlobal = this.module.ModuleTools.GetGlobalConf() // 读取抽卡配置文件
if cfgGlobal == nil {
return
}
drawCount = heroRecord.Count[drawType] // 获取当前阵容抽卡次数
if true { // 普通卡池抽卡
////// 获取消耗
if costRes, errdata = this.module.modelHero.CheckDrawCardRes(session, drawConf, 0, drawCount); errdata != nil {
return
}
// 校验是否达到保底卡池
if drawConf.Protect >= drawCount {
IsBaodiPool = true
}
///// 获取消耗 end
for i := 1; i <= int(drawCount); i++ { // 一张一张的抽
heroRecord.Race[drawType] += 1
drawCount++
heroRecord.Baodi5[drawType]++
heroRecord.Baodi4[drawType]++
if v, ok := appointmap[drawCount]; ok { // 优先校验是否是指定抽
strPool = append(strPool, v) //找到了
continue
}
Is5Star := false
starWeight := []int32{drawConf.Star3w, drawConf.Star4w, drawConf.Star5w} // 随机获取三星
if drawConf.Permission != -1 && heroRecord.Baodi5[drawType] > 0 { // 橙权递增
starWeight[2] += this.module.configure.GetHeroDrawWeightConfigById(drawConf.Permission, heroRecord.Baodi5[drawType])
}
starIndex := comm.GetRandW(starWeight) // 3 4 5 星索引
if IsBaodiPool {
if starIndex == 0 {
strPool = append(strPool, drawConf.P3pool)
} else if starIndex == 1 {
star4Count++
heroRecord.Baodi4[drawType] = 0
strPool = append(strPool, drawConf.P4pool)
} else if starIndex == 2 {
star5Count++
heroRecord.Baodi5[drawType] = 0
strPool = append(strPool, drawConf.P5pool)
Is5Star = true
}
} else {
if starIndex == 0 {
strPool = append(strPool, drawConf.N3pool)
} else if starIndex == 1 {
star4Count++
heroRecord.Baodi4[drawType] = 0
strPool = append(strPool, drawConf.N4pool)
} else if starIndex == 2 {
star5Count++
heroRecord.Baodi5[drawType] = 0
strPool = append(strPool, drawConf.N5pool)
Is5Star = true
}
}
// 判断是否必出5星
if heroRecord.Baodi5[drawType] >= drawConf.Baidi5 && !Is5Star {
heroRecord.Baodi5[drawType] = 0
star5Count++
if IsBaodiPool {
strPool[len(strPool)-1] = drawConf.P5pool
} else {
strPool[len(strPool)-1] = drawConf.N5pool
}
Is5Star = true
continue
}
// 判断是否必出4星
if heroRecord.Baodi4[drawType] >= drawConf.Baodi4 {
heroRecord.Baodi4[drawType] = 0
star4Count++
if IsBaodiPool {
strPool[len(strPool)-1] = drawConf.P4pool
} else {
strPool[len(strPool)-1] = drawConf.N4pool
}
continue
}
if drawCount == 10 {
if star4Count >= cfgGlobal.Draw10Star4Max { // 10连抽最大4星数量
if IsBaodiPool {
strPool[len(strPool)-1] = drawConf.P3pool
} else {
strPool[len(strPool)-1] = drawConf.N3pool
}
}
if star5Count >= cfgGlobal.Draw10Star5Max { // 10连抽最大5星数量
if IsBaodiPool {
strPool[len(strPool)-1] = drawConf.P3pool
} else {
strPool[len(strPool)-1] = drawConf.N3pool
}
}
}
}
}
// 通过卡池获得最终的英雄
for _, v := range strPool {
card, err := this.module.configure.GetHeroByPool(v)
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound,
Title: pb.ErrorCode_ConfigNoFound.ToString(),
Message: err.Error(),
}
return
}
szCards = append(szCards, card)
}
// 消耗道具
if errdata = this.module.ConsumeRes(session, costRes, true); errdata != nil {
return
}
heroRecord.Totalcount += drawCount
heroRecord.Daycount += drawCount
heroRecord.Count[drawType] = drawCount
update["drawcount"] = drawCount
update["count"] = heroRecord.Count
update["totalcount"] = heroRecord.Totalcount
update["race"] = heroRecord.Race
update["daycount"] = heroRecord.Daycount
update["baodi4"] = heroRecord.Baodi4
update["baodi5"] = heroRecord.Baodi5
if err = this.module.modelRecord.ChangeHeroRecord(session.GetUserId(), update); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.String(),
Message: err.Error(),
}
return
}
// 抽卡次数+1
result.Count += 1
result.Cur = szCards
this.module.modelSelect.Change(session.GetUserId(), map[string]interface{}{
"count": result.Count,
"cur": result.Cur,
})
session.SendMsg(string(this.module.GetType()), "selectdraw", &pb.HeroSelectDrawResp{})
return
}