153 lines
3.9 KiB
Go
153 lines
3.9 KiB
Go
package warorder
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"go_dreamfactory/utils"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) ReceiveCheck(session comm.IUserSession, req *pb.WarorderReceiveReq) (errdata *pb.ErrorData) {
|
|
|
|
return
|
|
}
|
|
|
|
// /获取系统公告
|
|
func (this *apiComp) Receive(session comm.IUserSession, req *pb.WarorderReceiveReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
info *pb.DBWarorders
|
|
warorder *pb.Warorder
|
|
dwarorder *pb.DreamWarorder
|
|
confs []*cfg.GamePassCheckData
|
|
awards []*cfg.Gameatn
|
|
ads []*pb.UserAssets = make([]*pb.UserAssets, 0)
|
|
days int32
|
|
err error
|
|
ok bool
|
|
)
|
|
if errdata = this.ReceiveCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
if info, err = this.module.model.getUserWarorders(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if confs, err = this.module.configure.getorder(req.Rtype); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
switch req.Rtype {
|
|
case 1, 2, 3:
|
|
if warorder, ok = info.Warorder[req.Rtype]; !ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_WarorderNoOpen,
|
|
Title: pb.ErrorCode_WarorderNoOpen.ToString(),
|
|
Message: fmt.Sprintf("Activity:%d no open", req.Rtype),
|
|
}
|
|
return
|
|
}
|
|
|
|
days = int32(utils.DiffDays(configure.Now().Unix(), warorder.Opentime)) + 1
|
|
awards = make([]*cfg.Gameatn, 0)
|
|
for _, v := range confs {
|
|
if v.Parameter <= days {
|
|
if warorder.Freeprogress < v.Parameter {
|
|
awards = append(awards, v.FreeReward)
|
|
ads = append(ads, &pb.UserAssets{
|
|
A: v.FreeReward.A,
|
|
T: v.FreeReward.T,
|
|
N: v.FreeReward.N,
|
|
})
|
|
}
|
|
if warorder.Vip {
|
|
if warorder.Payprogress < v.Parameter {
|
|
awards = append(awards, v.PayReward...)
|
|
for _, v := range v.PayReward {
|
|
ads = append(ads, &pb.UserAssets{
|
|
A: v.A,
|
|
T: v.T,
|
|
N: v.N,
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
warorder.Freeprogress = days
|
|
if warorder.Vip {
|
|
warorder.Payprogress = days
|
|
}
|
|
case 4:
|
|
if dwarorder, ok = info.Dreamwarorder[req.Rtype]; !ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_WarorderNoOpen,
|
|
Title: pb.ErrorCode_WarorderNoOpen.ToString(),
|
|
Message: fmt.Sprintf("Activity:%d no open", req.Rtype),
|
|
}
|
|
return
|
|
}
|
|
|
|
awards = make([]*cfg.Gameatn, 0)
|
|
for _, v := range confs {
|
|
if v.Parameter <= dwarorder.Lv {
|
|
if dwarorder.Freeprogress < v.Parameter {
|
|
awards = append(awards, v.FreeReward)
|
|
ads = append(ads, &pb.UserAssets{
|
|
A: v.FreeReward.A,
|
|
T: v.FreeReward.T,
|
|
N: v.FreeReward.N,
|
|
})
|
|
}
|
|
if dwarorder.Vip > 0 {
|
|
if dwarorder.Payprogress < v.Parameter {
|
|
awards = append(awards, v.PayReward...)
|
|
for _, v := range v.PayReward {
|
|
ads = append(ads, &pb.UserAssets{
|
|
A: v.A,
|
|
T: v.T,
|
|
N: v.N,
|
|
})
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
dwarorder.Freeprogress = dwarorder.Lv
|
|
if dwarorder.Vip > 0 {
|
|
dwarorder.Payprogress = dwarorder.Lv
|
|
}
|
|
}
|
|
|
|
if errdata = this.module.DispenseRes(session, awards, true); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if err = this.module.model.updateUserWarorders(session.GetUserId(), info); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), "receive", &pb.WarorderReceiveResp{Rtype: req.Rtype, Warorder: warorder, Dwarorder: dwarorder, Award: ads})
|
|
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), "WarorderReceiveReq", awards)
|
|
})
|
|
return
|
|
}
|