恢复时间计算

This commit is contained in:
meixiongfeng 2022-11-28 21:28:37 +08:00
parent 950261af45
commit 809d5d2dc5
4 changed files with 46 additions and 48 deletions

View File

@ -63,15 +63,17 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.HuntingBuyReq) (code
if list.RecoveryTime == 0 {
list.RecoveryTime = configure.Now().Unix()
}
count := (configure.Now().Unix() - list.RecoveryTime) / int64(conf.HuntingRecovery*60)
if count > 1 {
curCount += int32(count)
}
if curCount >= conf.HuntingNum {
curCount = conf.HuntingNum
list.RecoveryTime = 0
} else {
list.RecoveryTime += count * int64(conf.VikingExpeditionRecoveryTime*60) // 更新刷新时间
for { // 计算恢复时间
if list.RecoveryTime+int64(conf.HuntingRecovery*60) <= configure.Now().Unix() {
curCount++
list.RecoveryTime += int64(conf.HuntingRecovery * 60)
if curCount >= conf.HuntingNum {
list.RecoveryTime = 0
break
}
} else {
break
}
}
if curCount-amount > 0 {
if code = this.module.DispenseRes(session, []*cfg.Gameatn{&cfg.Gameatn{
@ -88,14 +90,14 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.HuntingBuyReq) (code
mapData["recoveryTime"] = list.RecoveryTime
curByCount += req.Count // 当前需要购买的数量
if this.configure.GetMaxBuyChallengeCount() < curByCount {
code = pb.ErrorCode_VikingBuyMaxCount
code = pb.ErrorCode_HuntingBuyMaxCount
return
}
for i := list.BuyCount + 1; i <= curByCount; i++ {
_cfg := this.configure.GetBuyChallengeCount(i)
if _cfg == nil {
code = pb.ErrorCode_VikingBuyMaxCount
code = pb.ErrorCode_HuntingBuyMaxCount
return
}
szCostRes = append(szCostRes, _cfg.Need...)

View File

@ -46,34 +46,30 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.HuntingGetListRe
code = pb.ErrorCode_ConfigNoFound
return
}
costRes := conf.VikingExpeditionCos
costRes := conf.HuntingCos
if costRes == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
amount := int32(this.module.ModuleItems.QueryItemAmount(session.GetUserId(), costRes.T)) // 获取当前数量
curCount = amount
if amount < conf.VikingNum {
if amount < conf.HuntingNum {
if list.RecoveryTime == 0 {
list.RecoveryTime = configure.Now().Unix()
}
for { // 计算恢复时间
amount++
if amount > conf.VikingNum {
list.RecoveryTime = 0
if list.RecoveryTime+int64(conf.HuntingRecovery*60) <= configure.Now().Unix() {
curCount++
list.RecoveryTime += int64(conf.HuntingRecovery * 60)
if curCount >= conf.HuntingNum {
list.RecoveryTime = 0
break
}
} else {
break
}
}
count := (configure.Now().Unix() - list.RecoveryTime) / int64(conf.HuntingRecovery*60) // 暂时用维京配置 11月21号统一修改配置
if count > 1 {
curCount += int32(count)
}
if curCount > conf.VikingNum {
curCount = conf.VikingNum
list.RecoveryTime = 0
} else {
list.RecoveryTime += count * int64(conf.HuntingRecovery*60) // 更新刷新时间
}
addCount := curCount - amount
if addCount > 0 {
if code = this.module.DispenseRes(session, []*cfg.Gameatn{&cfg.Gameatn{

View File

@ -64,19 +64,17 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.VikingBuyReq) (code
if list.RecoveryTime == 0 {
list.RecoveryTime = configure.Now().Unix()
}
if conf.VikingExpeditionRecoveryTime == 0 { // 配置校验 被除数不能为0
code = pb.ErrorCode_ConfigNoFound
return
}
count := (configure.Now().Unix() - list.RecoveryTime) / int64(conf.VikingExpeditionRecoveryTime*60)
if count > 1 {
curCount += int32(count)
}
if curCount > conf.VikingNum {
curCount = conf.VikingNum
list.RecoveryTime = 0
} else {
list.RecoveryTime += count * int64(conf.VikingExpeditionRecoveryTime*60) // 更新刷新时间
for { // 计算恢复时间
if list.RecoveryTime+int64(conf.VikingExpeditionRecoveryTime*60) <= configure.Now().Unix() {
curCount++
list.RecoveryTime += int64(conf.VikingExpeditionRecoveryTime * 60)
if curCount >= conf.HuntingNum {
list.RecoveryTime = 0
break
}
} else {
break
}
}
if curCount-amount > 0 {
if code = this.module.DispenseRes(session, []*cfg.Gameatn{&cfg.Gameatn{

View File

@ -59,15 +59,17 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.VikingGetListReq
if list.RecoveryTime == 0 {
list.RecoveryTime = configure.Now().Unix()
}
count := (configure.Now().Unix() - list.RecoveryTime) / int64(conf.VikingExpeditionRecoveryTime*60)
if count > 1 {
curCount += int32(count)
}
if curCount >= conf.VikingNum {
curCount = conf.VikingNum
list.RecoveryTime = 0
} else {
list.RecoveryTime += count * int64(conf.VikingExpeditionRecoveryTime*60) // 更新刷新时间
for { // 计算恢复时间
if list.RecoveryTime+int64(conf.VikingExpeditionRecoveryTime*60) <= configure.Now().Unix() {
curCount++
list.RecoveryTime += int64(conf.VikingExpeditionRecoveryTime * 60)
if curCount >= conf.HuntingNum {
list.RecoveryTime = 0
break
}
} else {
break
}
}
addCount := curCount - amount
if addCount > 0 {