107 lines
2.9 KiB
Go
107 lines
2.9 KiB
Go
package hero
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) PeachRewardCheck(session comm.IUserSession, req *pb.HeroPeachRewardReq) (errdata *pb.ErrorData) {
|
|
|
|
return
|
|
}
|
|
|
|
// 圣桃树领奖
|
|
func (this *apiComp) PeachReward(session comm.IUserSession, req *pb.HeroPeachRewardReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
rsp *pb.HeroPeachRewardResp
|
|
bchange bool
|
|
reward []*cfg.Gameatn // 奖励
|
|
err error
|
|
drawConf *cfg.GameDrawPoolData
|
|
)
|
|
rsp = &pb.HeroPeachRewardResp{}
|
|
bchange = false
|
|
|
|
// 校验时间 是否在活动范围
|
|
if drawConf, err = this.module.configure.GetHeroDrawConfigByType(comm.DrawCardType0); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Message: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
}
|
|
return
|
|
}
|
|
if user, err := this.module.GetUserForSession(session); err == nil {
|
|
if drawConf.Etime != -1 {
|
|
if user.Ctime+int64(drawConf.Etime*3600*24) < configure.Now().Unix() {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_HeroDrawOutTime,
|
|
Message: pb.ErrorCode_HeroDrawOutTime.ToString(),
|
|
}
|
|
return
|
|
}
|
|
}
|
|
|
|
}
|
|
heroRecord, _ := this.module.modelRecord.GetHeroRecord(session.GetUserId())
|
|
if req.BAllGet { // 一键领取
|
|
allreawd := this.module.configure.GetAllDrawRewardConf()
|
|
|
|
for k, v := range allreawd {
|
|
if _, ok := heroRecord.Peach[k]; !ok {
|
|
if v1, ok := heroRecord.Race[comm.DrawCardType0]; ok {
|
|
if v1 >= v.Num { //可以领取
|
|
heroRecord.Peach[k] = true
|
|
bchange = true
|
|
reward = append(reward, v.Reward)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
if conf, err := this.module.configure.GetHeroDrawRewardConfigById(req.RewardCid); err == nil {
|
|
if _, ok := heroRecord.Peach[conf.Num]; !ok {
|
|
if v1, ok := heroRecord.Race[2]; ok {
|
|
if v1 > conf.Num { //可以领取
|
|
heroRecord.Peach[conf.Num] = true
|
|
bchange = true
|
|
reward = append(reward, conf.Reward)
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
}
|
|
if bchange {
|
|
update := make(map[string]interface{}, 0)
|
|
update["peach"] = heroRecord.Peach
|
|
this.module.modelRecord.ChangeHeroRecord(session.GetUserId(), update)
|
|
// 发奖
|
|
if errdata, rsp.Atno = this.module.DispenseAtno(session, reward, true); errdata != nil {
|
|
return
|
|
}
|
|
} else {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_HeroRepeatReward,
|
|
|
|
Message: fmt.Sprintf("HeroRepeatReward:%d :%v", req.RewardCid, heroRecord.Peach),
|
|
}
|
|
return
|
|
}
|
|
rsp.Peach = heroRecord.Peach
|
|
session.SendMsg(string(this.module.GetType()), HeroPeachRewardReq, rsp)
|
|
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), req, comm.GMResAddType, "HeroPeachRewardReq", reward)
|
|
})
|
|
return
|
|
}
|