go_dreamfactory/modules/hunting/api_getlist.go

59 lines
1.5 KiB
Go

package hunting
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
"google.golang.org/protobuf/proto"
)
//参数校验
func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.HuntingGetListReq) (code pb.ErrorCode) {
return
}
func (this *apiComp) GetList(session comm.IUserSession, req *pb.HuntingGetListReq) (code pb.ErrorCode, data proto.Message) {
code = this.GetListCheck(session, req)
if code != pb.ErrorCode_Success {
return // 参数校验失败直接返回
}
list, err := this.module.modelHunting.getHuntingList(session.GetUserId())
if err != nil {
code = pb.ErrorCode_DBError
return
}
// 检查恢复时间
conf := this.module.configure.GetGlobalConf()
if conf == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
if list.LeftCount != conf.VikingNum {
if list.RecoveryTime == 0 {
list.RecoveryTime = configure.Now().Unix()
}
count := (configure.Now().Unix() - list.RecoveryTime) / int64(conf.VikingExpeditionRecoveryTime*60) // 暂时用维京配置 11月21号统一修改配置
if count > 1 {
list.LeftCount += int32(count)
}
if list.LeftCount >= conf.VikingNum {
list.LeftCount = conf.VikingNum
list.RecoveryTime = 0
} else {
list.RecoveryTime += count * int64(conf.VikingExpeditionRecoveryTime*60) // 更新刷新时间
}
} else {
list.RecoveryTime = 0
}
for k := range list.Boss {
list.Boss[k] += 1
}
session.SendMsg(string(this.module.GetType()), HuntingGetListResp, &pb.HuntingGetListResp{Data: list})
return
}