心愿招募
This commit is contained in:
parent
b43ea0870c
commit
eecbed54c9
@ -79,79 +79,7 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq
|
||||
}
|
||||
// 校验是否是心愿招募
|
||||
if req.DrawType == comm.DrawCardType6 && req.DrawCount == 1 {
|
||||
// 心愿消耗 走单独配置
|
||||
// 校验许愿英雄
|
||||
var cd int64
|
||||
var drcount int32
|
||||
//atn := this.module.ModuleTools.GetGlobalConf().ExchangeHero // 校验消耗数量
|
||||
if conf := this.module.configure.GetWishHeroReplaceConfig(); conf != nil {
|
||||
if heroRecord.WishHero == "" { // 如果当前许愿英雄是空 则读取 默认许愿英雄
|
||||
heroRecord.WishHero = conf.InitHero
|
||||
}
|
||||
cd = int64(conf.Cond[heroRecord.WishHero].cd)
|
||||
drcount = conf.Cond[heroRecord.WishHero].num
|
||||
// 校验该抽卡是否在CD 中
|
||||
if outTime, ok := heroRecord.Wish[heroRecord.WishHero]; ok {
|
||||
if outTime > configure.Now().Unix() {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_HeroDrawCD,
|
||||
}
|
||||
return
|
||||
} else { // 时间到了
|
||||
heroRecord.Wish[heroRecord.WishHero] = 0 // 时间清0
|
||||
}
|
||||
}
|
||||
costRes = append(costRes, conf.Cond[heroRecord.WishHero].buyCos)
|
||||
if errdata = this.module.CheckRes(session, costRes); errdata != nil {
|
||||
return
|
||||
}
|
||||
} else { // 配置错误
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ConfigNoFound,
|
||||
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
||||
Message: fmt.Sprintf("GetWishHeroReplaceConfig is nil"),
|
||||
}
|
||||
return
|
||||
}
|
||||
// 校验 解锁所需抽奖次数
|
||||
if drcount > heroRecord.Race[comm.DrawCardType0] {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_HeroDrawCountErr,
|
||||
}
|
||||
return
|
||||
}
|
||||
var hero *pb.DBHero
|
||||
|
||||
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 { // 广播 首次获得英雄
|
||||
if HeroConf, err := this.module.configure.GetHeroConfig(heroRecord.WishHero); 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 {
|
||||
return
|
||||
}
|
||||
|
||||
if errdata = this.module.ConsumeRes(session, costRes, true); errdata != nil {
|
||||
return
|
||||
}
|
||||
// 修改recode 数据
|
||||
if cd != 0 {
|
||||
heroRecord.Wish[heroRecord.WishHero] = configure.Now().Unix() + cd
|
||||
update["wish"] = heroRecord.Wish
|
||||
this.module.modelRecord.ChangeHeroRecord(session.GetUserId(), update)
|
||||
}
|
||||
session.SendMsg(string(this.module.GetType()), DrawCard, rsp)
|
||||
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)
|
||||
})
|
||||
errdata = this.wishDrawCard(session, heroRecord)
|
||||
return
|
||||
}
|
||||
// 准备数据
|
||||
@ -415,3 +343,87 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (this *apiComp) wishDrawCard(session comm.IUserSession, heroRecord *pb.DBHeroRecord) (errdata *pb.ErrorData) {
|
||||
|
||||
var (
|
||||
cd int64
|
||||
drcount int32
|
||||
costRes []*cfg.Gameatn
|
||||
atno []*pb.UserAtno
|
||||
update map[string]interface{}
|
||||
rsp *pb.HeroDrawCardResp
|
||||
)
|
||||
|
||||
update = make(map[string]interface{})
|
||||
if conf := this.module.configure.GetWishHeroReplaceConfig(); conf != nil {
|
||||
if heroRecord.WishHero == "" { // 如果当前许愿英雄是空 则读取 默认许愿英雄
|
||||
heroRecord.WishHero = conf.InitHero
|
||||
}
|
||||
cd = int64(conf.Cond[heroRecord.WishHero].cd)
|
||||
drcount = conf.Cond[heroRecord.WishHero].num
|
||||
// 校验该抽卡是否在CD 中
|
||||
if outTime, ok := heroRecord.Wish[heroRecord.WishHero]; ok {
|
||||
if outTime > configure.Now().Unix() {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_HeroDrawCD,
|
||||
}
|
||||
return
|
||||
} else { // 时间到了
|
||||
heroRecord.Wish[heroRecord.WishHero] = 0 // 时间清0
|
||||
}
|
||||
}
|
||||
costRes = append(costRes, conf.Cond[heroRecord.WishHero].buyCos)
|
||||
if errdata = this.module.CheckRes(session, costRes); errdata != nil {
|
||||
return
|
||||
}
|
||||
} else { // 配置错误
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ConfigNoFound,
|
||||
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
||||
Message: fmt.Sprintf("GetWishHeroReplaceConfig is nil"),
|
||||
}
|
||||
return
|
||||
}
|
||||
// 校验 解锁所需抽奖次数
|
||||
if drcount > heroRecord.Race[comm.DrawCardType0] {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_HeroDrawCountErr,
|
||||
}
|
||||
return
|
||||
}
|
||||
var hero *pb.DBHero
|
||||
|
||||
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 { // 广播 首次获得英雄
|
||||
if HeroConf, err := this.module.configure.GetHeroConfig(heroRecord.WishHero); 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 {
|
||||
return
|
||||
}
|
||||
|
||||
if errdata = this.module.ConsumeRes(session, costRes, true); errdata != nil {
|
||||
return
|
||||
}
|
||||
// 修改recode 数据
|
||||
if cd != 0 {
|
||||
heroRecord.Wish[heroRecord.WishHero] = configure.Now().Unix() + cd
|
||||
update["wish"] = heroRecord.Wish
|
||||
this.module.modelRecord.ChangeHeroRecord(session.GetUserId(), update)
|
||||
}
|
||||
rsp.Record = heroRecord
|
||||
session.SendMsg(string(this.module.GetType()), DrawCard, rsp)
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user