go_dreamfactory/modules/uigame/api_getpuzzle.go
2023-12-19 21:19:45 +08:00

78 lines
2.3 KiB
Go

package uigame
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
"go_dreamfactory/utils"
)
//参数校验
func (this *apiComp) GetPuzzleCheck(session comm.IUserSession, req *pb.UiGameGetPuzzleReq) (errdata *pb.ErrorData) {
return
}
func (this *apiComp) GetPuzzle(session comm.IUserSession, req *pb.UiGameGetPuzzleReq) (errdata *pb.ErrorData) {
if errdata = this.GetPuzzleCheck(session, req); errdata != nil {
return // 参数校验失败直接返回
}
var (
activity *pb.DBHuodong
err error
hdData *pb.DBPuzzleData // 玩家的活动数据
update map[string]interface{} //
)
update = make(map[string]interface{})
curTime := configure.Now().Unix()
if activity, err = this.module.GetActivityData(pb.HdType_HdPuzzle); err != nil { // 活动不存在
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ActivityInvalid,
Title: pb.ErrorCode_ActivityInvalid.ToString(),
}
return
}
if activity.Stime > curTime && curTime > activity.Etime { // 不在活动范围内数据不给活动记录数据
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ActivityNotIntime,
Title: pb.ErrorCode_ActivityNotIntime.ToString(),
}
return
}
// 获取玩家活动数据
hdData, _ = this.module.modelPuzzle.getPuzzleList(session.GetUserId(), activity.Id)
if e, err := this.module.ModuleUser.GetUserExpand(session.GetUserId()); err == nil {
if conf, err := this.module.configure.GetPuzzleConsumConf(); err == nil {
bchange := false
// 清除每日获得的碎片数据
if !utils.IsToday(hdData.Lasttime) {
hdData.Lasttime = configure.Now().Unix()
hdData.Val = 0
update["val"] = hdData.Val
update["lasttime"] = hdData.Lasttime
bchange = true
}
if conf.Getmax > hdData.Val { // 超过今日上限
if e.ConsumPs/conf.Usepawer >= hdData.Val {
hdData.Val = e.ConsumPs / conf.Usepawer
if conf.Getmax < hdData.Val { // 超过今日上限
hdData.Val = conf.Getmax
update["val"] = hdData.Val
bchange = true
}
}
}
if bchange {
this.module.modelPuzzle.modifyPuzzleListByObjId(session.GetUserId(), update)
}
}
}
list, _ := this.module.modelPuzzle.getPuzzleList(session.GetUserId(), req.Hdid)
session.SendMsg(string(this.module.GetType()), "getpuzzle", &pb.UiGameGetPuzzleResp{Data: list})
return
}