模拟抽卡

This commit is contained in:
meixiongfeng 2023-12-05 11:25:42 +08:00
parent cb8418d79a
commit f89bda8372
5 changed files with 213 additions and 69 deletions

View File

@ -149,8 +149,6 @@ type (
// 检查圣桃树奖励是否发放
CheckPeachReward(session IUserSession, ctime int64)
CreateOneHero(session IUserSession, heroCfgId string) (hero *pb.DBHero, atno []*pb.UserAtno, errdata *pb.ErrorData)
// 通过卡池随机获取指定数量的英雄卡
GetRandomCardByCardPool(uid string, count int32) (cards []string, err error)
}

View File

@ -42,6 +42,19 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq
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
}
cfgGlobal = this.module.ModuleTools.GetGlobalConf() // 读取抽卡配置文件
if cfgGlobal == nil {
return
}
if req.DrawType == 1 { // 新手抽卡校验
if heroRecord.Newcomplete {
errdata = &pb.ErrorData{
@ -58,14 +71,6 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq
return
}
}
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
}
rsp := &pb.HeroDrawCardResp{
Data: []*pb.AtnoData{},
@ -117,7 +122,7 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq
}
var hero *pb.DBHero
if hero, atno, errdata = this.module.ModuleHero.CreateOneHero(session, heroRecord.WishHero); errdata == nil {
if hero, atno, errdata = this.module.CreateOneHero(session, heroRecord.WishHero); errdata == nil {
for _, v := range atno {
if v.A == "hero" && v.T == heroRecord.WishHero && v.N == 1 {
if user, err := this.module.ModuleUser.GetUser(session.GetUserId()); err == nil { // 广播 首次获得英雄
@ -167,11 +172,6 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq
////////////////////////////////////////////////////////
cfgGlobal = this.module.ModuleTools.GetGlobalConf() // 读取抽卡配置文件
if cfgGlobal == nil {
return
}
// 每日抽卡上限校验
if cfgGlobal.DrawToplimit < heroRecord.Daycount+req.DrawCount {
errdata = &pb.ErrorData{
@ -311,53 +311,73 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq
update["daycount"] = heroRecord.Daycount
update["baodi4"] = heroRecord.Baodi4
update["baodi5"] = heroRecord.Baodi5
if req.DrawType == 1 {
heroRecord.Selectcount += 1 // 抽卡次数+1
heroRecord.Cur = szCards
update["selectcount"] = heroRecord.Selectcount
update["cur"] = heroRecord.Cur
} else {
for _, heroId := range szCards {
//var
var (
hero *pb.DBHero
HeroConf *cfg.GameHeroData
)
if HeroConf, err = this.module.configure.GetHeroConfig(heroId); err == nil {
szStar = append(szStar, HeroConf.Star) // 获得许愿石
var tmp *cfg.Gameatn
if HeroConf.Star == 4 {
tmp = this.module.ModuleTools.GetGlobalConf().RewardStar4
reward = append(reward, tmp)
} else if HeroConf.Star == 5 {
tmp = this.module.ModuleTools.GetGlobalConf().RewardStar5
reward = append(reward, tmp)
if req.DrawType == comm.DrawCardType5 { // 限时招募
if heroRecord.LimitHero == "" {
if conf := this.module.configure.GetApportHeroReplaceConfig(); conf != nil {
heroRecord.LimitHero = conf.InitHero
update["limitHero"] = heroRecord.LimitHero
}
for _, heroId := range szCards {
//var
var (
hero *pb.DBHero
HeroConf *cfg.GameHeroData
)
if HeroConf, err = this.module.configure.GetHeroConfig(heroId); err == nil {
szStar = append(szStar, HeroConf.Star) // 获得许愿石
var tmp *cfg.Gameatn
if HeroConf.Star == 4 {
tmp = this.module.ModuleTools.GetGlobalConf().RewardStar4
reward = append(reward, tmp)
} else if HeroConf.Star == 5 {
tmp = this.module.ModuleTools.GetGlobalConf().RewardStar5
reward = append(reward, tmp)
if req.DrawType == comm.DrawCardType5 { // 限时招募
if heroRecord.LimitHero == "" {
if conf := this.module.configure.GetApportHeroReplaceConfig(); conf != nil {
heroRecord.LimitHero = conf.InitHero
update["limitHero"] = heroRecord.LimitHero
}
heroId = heroRecord.LimitHero // 替换成心愿英雄
}
}
if tmp != nil {
if rsp.Wish == nil {
rsp.Wish = &pb.UserAtno{
A: tmp.A,
T: tmp.T,
N: tmp.N,
}
} else {
rsp.Wish.N += tmp.N
}
heroId = heroRecord.LimitHero // 替换成心愿英雄
}
}
if tmp != nil {
if rsp.Wish == nil {
rsp.Wish = &pb.UserAtno{
A: tmp.A,
T: tmp.T,
N: tmp.N,
}
} else {
rsp.Wish.N += tmp.N
}
}
}
var atno []*pb.UserAtno
if hero, atno, errdata = this.module.ModuleHero.CreateOneHero(session, heroId); errdata == nil {
var atno []*pb.UserAtno
if req.DrawType == 1 {
heroRecord.Selectcount += 1 // 抽卡次数+1
heroRecord.Cur = szCards
update["selectcount"] = heroRecord.Selectcount
update["cur"] = heroRecord.Cur
if hero, atno, err = this.module.modelHero.imitateHero(session, heroId); err == nil {
for _, v := range atno {
if v.A == "hero" && v.T == heroId && v.N == 1 {
if user, err := this.module.ModuleUser.GetUser(session.GetUserId()); err == nil { // 广播 首次获得英雄
this.chat.SendSysChatToWorld(comm.ChatSystem13, hero, HeroConf.Star, 0, user.Name, v.T)
}
}
}
rsp.Data = append(rsp.Data, &pb.AtnoData{Atno: atno})
} else {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_HeroNoExist,
Title: pb.ErrorCode_HeroNoExist.ToString(),
Message: err.Error(),
}
return
}
} else {
if hero, atno, errdata = this.module.CreateOneHero(session, heroId); errdata == nil {
for _, v := range atno {
if v.A == "hero" && v.T == heroId && v.N == 1 {
if user, err := this.module.ModuleUser.GetUser(session.GetUserId()); err == nil { // 广播 首次获得英雄
@ -372,18 +392,26 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq
}
this.module.modelRecord.ChangeHeroRecord(session.GetUserId(), update)
// 发放许愿石奖励
if errdata, atno = this.module.DispenseAtno(session, reward, true); errdata != nil {
return
if req.DrawType != 1 {
if errdata, atno = this.module.DispenseAtno(session, reward, true); errdata != nil { // 发放许愿石奖励
return
}
}
session.SendMsg(string(this.module.GetType()), DrawCard, rsp)
if req.DrawType != 1 {
// 任务统计
this.module.SendTaskMsg(session, szStar, req.DrawCount, req.DrawType)
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
this.module.WriteUserLog(session.GetUserId(), comm.GMResAddType, "HeroDrawCardReq", atno)
this.module.WriteUserLog(session.GetUserId(), comm.GMResDelType, "HeroDrawCardReq", costRes)
})
} else {
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
this.module.WriteUserLog(session.GetUserId(), comm.GMResDelType, "HeroDrawCardReq", costRes)
})
}
session.SendMsg(string(this.module.GetType()), DrawCard, rsp)
// 任务统计
this.module.SendTaskMsg(session, szStar, req.DrawCount, req.DrawType)
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
this.module.WriteUserLog(session.GetUserId(), comm.GMResAddType, "HeroDrawCardReq", atno)
this.module.WriteUserLog(session.GetUserId(), comm.GMResDelType, "HeroDrawCardReq", costRes)
})
return
}

View File

@ -70,7 +70,7 @@ func (this *apiComp) SelectCard(session comm.IUserSession, req *pb.HeroSelectCar
}
var atno []*pb.UserAtno
if hero, atno, errdata = this.module.ModuleHero.CreateOneHero(session, heroId); errdata == nil {
if hero, atno, errdata = this.module.CreateOneHero(session, heroId); errdata == nil {
for _, v := range atno {
if v.A == "hero" && v.T == heroId && v.N == 1 {
if user, err := this.module.ModuleUser.GetUser(session.GetUserId()); err == nil { // 广播 首次获得英雄

View File

@ -977,3 +977,119 @@ func (this *ModelHero) GetDrawCardReward(session comm.IUserSession, szCards []st
})
return
}
// 模拟获得英雄
func (this *ModelHero) imitateHero(session comm.IUserSession, heroCfgId string) (hero *pb.DBHero, atno []*pb.UserAtno, err error) {
heros := make([]*pb.DBHero, 0)
uid := session.GetUserId()
heroCfg, _ := this.module.configure.GetHeroConfig(heroCfgId)
bFirst := true
if heroCfg == nil {
err = errors.New("not found hero configID")
this.module.Errorf("not found hero configID:%s", heroCfgId)
return
}
if err = this.GetList(uid, &heros); err != nil {
this.module.Errorf("err:%v", err)
}
for _, obj := range heros {
if obj.HeroID == heroCfgId {
hero = obj
bFirst = false
atno = append(atno, &pb.UserAtno{ // 有英雄的时候 数量给0
A: "hero",
T: hero.HeroID,
N: 0,
O: hero.Id,
})
break
}
}
if bFirst { // 没有当前英雄
hero, err = this.initHeroOverlying(uid, heroCfgId, 1)
if err != nil {
return
}
atno = append(atno, &pb.UserAtno{
A: "hero",
T: hero.HeroID,
N: 1,
O: hero.Id,
})
}
rst, err := this.module.ModuleUser.GetUserExpand(session.GetUserId())
if err != nil {
return
}
if rst.Expitem == nil {
rst.Expitem = make(map[string]int32)
}
if rst.Herofrag == nil {
rst.Herofrag = make(map[string]int32)
}
// 转碎片处理
bAdd := false
//守护之星 获得
if heroCfg.Herofragnum > 0 {
if v, ok := rst.Herofrag[hero.HeroID]; !ok {
rst.Herofrag[hero.HeroID] = 1
bAdd = true
} else if heroCfg.Herofragnum > v {
rst.Herofrag[hero.HeroID] += 1
bAdd = true
}
}
if bAdd {
for _, v := range heroCfg.Herofrag {
atno = append(atno, &pb.UserAtno{
A: v.A,
T: v.T,
N: v.N,
})
}
} else {
list := this.module.ModuleTools.GetGlobalConf().Moonshopmoney
if list != nil {
for pos, v := range list {
if int32(pos)+3 == heroCfg.Star && v > 0 {
atno = append(atno, &pb.UserAtno{
A: "attr",
T: "moongold",
N: v,
})
break
}
}
}
}
bAdd = false // 初始化
// expitem 获得
if heroCfg.Expitemnum > 0 {
if v, ok := rst.Expitem[hero.HeroID]; ok {
if heroCfg.Expitemnum > v {
rst.Expitem[hero.HeroID] += 1
bAdd = true
}
} else {
rst.Expitem[hero.HeroID] = 1
bAdd = true
}
}
if bAdd {
for _, v := range heroCfg.Expitem {
atno = append(atno, &pb.UserAtno{
A: v.A,
T: v.T,
N: v.N,
})
}
}
return
}

View File

@ -47,6 +47,7 @@ import (
"go_dreamfactory/modules/mail"
"go_dreamfactory/modules/maincity"
"go_dreamfactory/modules/mainline"
"go_dreamfactory/modules/monkey"
"go_dreamfactory/modules/moonfantasy"
"go_dreamfactory/modules/moonlv"
"go_dreamfactory/modules/notify"
@ -190,6 +191,7 @@ func main() {
catchbugs.NewModule(),
moonlv.NewModule(),
whackamole.NewModule(),
monkey.NewModule(),
)
}