76 lines
2.1 KiB
Go
76 lines
2.1 KiB
Go
package troll
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/utils"
|
|
"time"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.TrollGetListReq) (code pb.ErrorCode) {
|
|
|
|
return
|
|
}
|
|
|
|
///获取美食城基本信息
|
|
func (this *apiComp) GetList(session comm.IUserSession, req *pb.TrollGetListReq) (code pb.ErrorCode, data proto.Message) {
|
|
var (
|
|
update map[string]interface{}
|
|
maxCoefficient int32
|
|
)
|
|
|
|
update = make(map[string]interface{})
|
|
if code = this.GetListCheck(session, req); code != pb.ErrorCode_Success {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
trolltrain, err := this.module.modelTroll.getTrollList(session.GetUserId())
|
|
if err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
maxCoefficient = this.configure.GetTrollMaxCoefficientNux() // 增长幅度的最大值
|
|
if maxCoefficient == 0 {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
// 跨天 则清除 每日交易次数
|
|
if !utils.IsToday(trolltrain.RefreshTime) {
|
|
trolltrain.SellCount = 0
|
|
update["sellCount"] = trolltrain.SellCount
|
|
this.module.ModifyTrollData(session.GetUserId(), update)
|
|
}
|
|
// 重新计算刷新时间
|
|
t := time.Now().Unix() - trolltrain.RefreshTime
|
|
/// 计算经过了多少个周期
|
|
sz := this.configure.GetTrollAllTrain()
|
|
var (
|
|
circle int32 // 循环一个周期的时间
|
|
curTime int32
|
|
)
|
|
for _, v := range sz {
|
|
circle += v
|
|
}
|
|
curTime = (int32(t) % circle)
|
|
// 循环次数
|
|
index := int32((int32(t) / circle)) * this.configure.GetTrollMaxTraintNum()
|
|
trolltrain.TarinPos += index
|
|
for pos, v := range sz {
|
|
trolltrain.TarinPos++
|
|
if curTime < v {
|
|
trolltrain.RefreshTime = time.Now().Unix() - int64(curTime)
|
|
trolltrain.TarinPos = int32(pos) // 设置火车位置
|
|
trolltrain.RangeId = (trolltrain.TarinPos % maxCoefficient)
|
|
update["refreshTime"] = trolltrain.RefreshTime
|
|
update["tarinPos"] = trolltrain.TarinPos
|
|
update["rangeId"] = trolltrain.RangeId
|
|
break
|
|
}
|
|
}
|
|
this.module.ModifyTrollData(session.GetUserId(), update)
|
|
session.SendMsg(string(this.module.GetType()), TrollGetListResp, &pb.TrollGetListResp{Data: trolltrain})
|
|
return
|
|
}
|