go_dreamfactory/modules/pagoda/api_warorder.go
2023-06-06 11:08:14 +08:00

125 lines
2.9 KiB
Go

package pagoda
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
)
//参数校验
func (this *apiComp) WarOrderCheck(session comm.IUserSession, req *pb.PagodaWarOrderReq) (errdata *pb.ErrorData) {
return
}
// 战令领取
func (this *apiComp) WarOrder(session comm.IUserSession, req *pb.PagodaWarOrderReq) (errdata *pb.ErrorData) {
var (
list *pb.DBPagoda
resCfg []*cfg.Gameatn
res []*pb.UserAssets
vip bool // 是否有特权
resID []int32 // 当前可领取的id
vipID []int32 // 有vip的情况 可领取的id
mapData map[string]interface{}
bReward bool
)
mapData = make(map[string]interface{}, 0)
//this.WarOrderCheck(session, req)
list, _ = this.module.modelPagoda.getPagodaList(session.GetUserId())
if list.Id == "" {
code = pb.ErrorCode_PagodaConditionErr // 领取条件没达到
return
}
payPoint := this.module.configure.GetPassCheckPointByTtype(1)
if payPoint != "" {
// 获取特权信息
vip = this.module.ModulePrivilege.CheckPrivilege(session, payPoint)
}
if list.PagodaId < list.PassCheckID { // 层数校验
//code = pb.ErrorCode_PagodaConditionErr // 领取条件没达到
//return
bReward = true
}
if vip && bReward {
if list.PagodaId < list.VipPassCheckID { // 层数校验
code = pb.ErrorCode_PagodaConditionErr // 领取条件没达到
return
}
}
conf := this.module.configure.GetPassCheckByTtype(1)
for _, v := range conf {
if v.Parameter <= list.PassCheckID {
continue
}
if v.Parameter <= list.PagodaId {
resID = append(resID, v.Id)
mapData["passCheckID"] = v.Parameter
list.PassCheckID = v.Parameter
}
}
if vip {
for _, v := range conf {
if v.Parameter <= list.VipPassCheckID {
continue
}
if v.Parameter <= list.PagodaId {
vipID = append(vipID, v.Id)
mapData["vipPassCheckID"] = v.Parameter
list.VipPassCheckID = v.Parameter
}
}
}
for _, v := range resID {
if confCheck := this.module.configure.GetPassCheckByID(v); conf != nil {
resCfg = append(resCfg, confCheck.FreeReward)
}
}
for _, v := range vipID {
if confCheck := this.module.configure.GetPassCheckByID(v); conf != nil {
resCfg = append(resCfg, confCheck.PayReward)
}
}
// 资源整合
var totalRes []*cfg.Gameatn
for _, v := range resCfg {
b := false
for _, v1 := range totalRes {
if v.A == v1.A && v.T == v1.T {
b = true
v1.N += v.N
break
}
}
if !b {
totalRes = append(totalRes, v)
}
}
if len(totalRes) > 0 {
if errdata = this.module.DispenseRes(session, totalRes, true); errdata != nil { // 发放奖励
return
}
}
// 转成协议格式
for _, v := range totalRes {
res = append(res, &pb.UserAssets{
A: v.A,
T: v.T,
N: v.N,
})
}
code = this.module.ModifyPagodaData(session.GetUserId(), mapData)
session.SendMsg(string(this.module.GetType()), PagodaWarOrderResp, &pb.PagodaWarOrderResp{
Data: list,
Itmes: res,
})
return
}