175 lines
4.9 KiB
Go
175 lines
4.9 KiB
Go
package hero
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"math/big"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
func (this *apiComp) DrawCardCheck(session comm.IUserSession, req *pb.HeroDrawCardReq) (code pb.ErrorCode) {
|
|
if req.DrawType <= 0 { // 只能是单抽或10抽
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
//抽卡
|
|
func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq) (code pb.ErrorCode, data proto.Message) {
|
|
var (
|
|
szCards []int32 // 最终抽到的卡牌
|
|
totalWeight int64 // 总权重
|
|
curWeigth int64 // 临时随机获得的权重
|
|
drawTimes int32 // 抽卡次数
|
|
hitStar4 int32 // 抽了多少次还没获得4星英雄
|
|
hitStar5 int32 // 抽了多少次还没获得5星英雄
|
|
//hitStar int32 // 抽中几星
|
|
curStar4Count int32 // 当前4星没抽到的次数
|
|
curStar5Count int32 // 当前5星没抽到的次数
|
|
floor4Count int32 // 4星保底次数
|
|
floor5Count int32 // 5星保底次数
|
|
|
|
)
|
|
szCards = make([]int32, 0)
|
|
rsp := &pb.HeroDrawCardResp{}
|
|
//curStar4Count = this.GetFloorStarData(req.DrawType, session.GetUserId(), 4)
|
|
//curStar5Count = this.GetFloorStarData(req.DrawType, session.GetUserId(), 5)
|
|
this.module.Debugf("当前4星抽卡没中次数:%d, 当前5星抽卡没中次数:%d", curStar4Count, curStar5Count)
|
|
|
|
rst, err := this.module.modelHero.GetUserRecord(session.GetUserId())
|
|
if err != nil {
|
|
|
|
}
|
|
for k, v := range rst.Floors {
|
|
if req.DrawType == 1 || req.DrawType == 2 {
|
|
if k == "p4" {
|
|
curStar4Count = v
|
|
} else if k == "p5" {
|
|
curStar5Count = v
|
|
}
|
|
} else if req.DrawType == 3 || req.DrawType == 4 {
|
|
if k == "o4" {
|
|
curStar4Count = v
|
|
} else if k == "o5" {
|
|
curStar5Count = v
|
|
}
|
|
} else if req.DrawType == 5 || req.DrawType == 6 {
|
|
if k == "t4" {
|
|
curStar4Count = v
|
|
} else if k == "t5" {
|
|
curStar5Count = v
|
|
}
|
|
} else if req.DrawType == 7 || req.DrawType == 8 {
|
|
if k == "th4" {
|
|
curStar4Count = v
|
|
} else if k == "th5" {
|
|
curStar5Count = v
|
|
}
|
|
} else if req.DrawType == 9 || req.DrawType == 10 {
|
|
if k == "f4" {
|
|
curStar4Count = v
|
|
} else if k == "f5" {
|
|
curStar5Count = v
|
|
}
|
|
}
|
|
|
|
}
|
|
// 抽卡相关
|
|
// 获取配置文件的权重信息
|
|
_conf, err := this.module.configure.GetHeroDrawConfig()
|
|
if err != nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
|
|
_costConf, err := this.module.configure.GetDrawCostConfigByID(req.DrawType)
|
|
if err != nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
floor4Count = _costConf.Floor4 // 4星保底次数
|
|
floor5Count = _costConf.Floor5 // 五星保底次数
|
|
if floor4Count == 0 || floor5Count == 0 {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
sz := make([]*cfg.Game_atn, 0)
|
|
sz = append(sz, _costConf.Cost)
|
|
code = this.module.CheckRes(session, sz) // 消耗校验
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
drawTimes = _costConf.Count // 抽卡次数
|
|
for _, v := range _conf.GetDataList() {
|
|
totalWeight += int64(v.Weight) // 统计所有权重
|
|
}
|
|
this.module.configure.GetDrawUpDrawConfig()
|
|
drawTimes = 1
|
|
for i := 0; i < int(drawTimes); i++ {
|
|
n, _ := rand.Int(rand.Reader, big.NewInt(totalWeight)) // [0,totalWeight)
|
|
for _, v := range _conf.GetDataList() {
|
|
curWeigth += int64(v.Weight)
|
|
if curWeigth < n.Int64() { // 命中
|
|
szCards = append(szCards, v.Id)
|
|
// 获取当前星级
|
|
_getCardCfg := this.module.configure.GetHero(v.Id) //获取的英雄信息
|
|
if _getCardCfg != nil {
|
|
continue
|
|
}
|
|
if _getCardCfg.Star == 4 { // 当抽取到的英雄是4星的时候 清除 该类型的保底次数
|
|
//SetFloorStarData(req.DrawType, session.GetUserId(), 4)
|
|
hitStar4 = 0
|
|
//hitStar = 4
|
|
break
|
|
} else if _getCardCfg.Star == 5 { // 当抽取到的英雄是5星的时候 清除 该类型的保底次数
|
|
//SetFloorStarData(req.DrawType, session.GetUserId(), 5)
|
|
hitStar5 = 0 // 清0
|
|
//hitStar = 5
|
|
break
|
|
}
|
|
hitStar4++
|
|
hitStar5++
|
|
|
|
if hitStar4 >= floor4Count { // 达到保底次数了 修改当前卡牌星级
|
|
break
|
|
}
|
|
if hitStar5 >= floor5Count { // 触发5星保底
|
|
// 5星卡池找
|
|
break
|
|
}
|
|
break
|
|
}
|
|
}
|
|
// if hitStar != 0 {
|
|
// hitStar = 0
|
|
// //ModifyFloorStarData(req.DrawType, session.GetUserId(), hitStar) // 重置该星级保底
|
|
// }
|
|
}
|
|
// 更新record 配置信息
|
|
update := map[string]interface{}{
|
|
"floors": nil,
|
|
}
|
|
this.module.modelHero.ChangeUserRecord(session.GetUserId(), update)
|
|
if hitStar4 != 0 {
|
|
//AddFloorStarData(req.DrawType, session.GetUserId(), 4, hitStar4) // 增加4星保底次数
|
|
}
|
|
|
|
if hitStar5 != 0 {
|
|
//AddFloorStarData(req.DrawType, session.GetUserId(), 5, hitStar5) // 增加5星保底次数
|
|
}
|
|
//计算保底
|
|
|
|
if err := this.module.modelHero.createMultiHero(session.GetUserId(), szCards...); err != nil {
|
|
code = pb.ErrorCode_HeroCreate
|
|
return
|
|
}
|
|
|
|
rsp.Heroes = szCards
|
|
session.SendMsg(string(this.module.GetType()), DrawCard, rsp)
|
|
return
|
|
}
|