Skip to content

Commit

Permalink
倒计时根据实际时间来计算,而不再基于次数 预留5分钟窗口期
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyJiangWJ committed Dec 6, 2019
1 parent 8d82894 commit fcfdbb4
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions lib/CommonFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: TonyJiangWJ
* @Date: 2019-11-27 09:03:57
* @Last Modified by: TonyJiangWJ
* @Last Modified time: 2019-12-01 13:47:14
* @Last Modified time: 2019-12-05 13:52:42
* @Description: 通用方法
*/
importClass(android.content.Context)
Expand Down Expand Up @@ -537,27 +537,20 @@ function CommonFunctions () {
let speeded = sleepStorage.speeded
sleepStorage.count = (sleepStorage.count || 0) + 1
let passedCount = sleepStorage.count - 1
let fullTime = speeded ? 240 : 300
// 经过的时间 单位分
let passedTime = (new Date().getTime() - sleepStorage.startTime)/60000
// 第一次喂食后 睡眠20分钟,然后循环5分钟多次 直到赶走了野鸡或者超时
if (passedCount === 0) {
// 后面循环睡眠5分钟
sleepStorage.sleepTime = 5
} else if (returnVal >= 300) {
returnVal = 300 - 20 - (passedCount - 1) * 5
if (speeded) {
// 使用加速卡则减少60分钟
returnVal -= 60
}
} else if (passedCount === 5 && returnVal === 5) {
// 循环经过了5次,20 + 4 * 5, 40分钟后
// 且睡眠时间依旧为5分钟
// 此时没有野鸡来 修改睡眠时间为260分钟
returnVal = 260
if (speeded) {
// 使用加速卡则减少60分钟
returnVal -= 60
}
} else if (passedCount >= 6) {
// 超过6次的 全部睡眠5分钟
} else if (returnVal >= 300 || passedTime <= fullTime && passedTime >= 40) {
// 揍过鸡后会设置为300 此时重新计算具体时间
// or
// 经过了超过40分钟 而且此时没有野鸡来 开始睡眠更久不再检测小鸡
returnVal = parseInt(fullTime + 5 - passedTime)
} else if (passedTime > fullTime) {
// 300分钟以上的 直接循环等待5分钟 理论上不会进到这一步 300分钟以上已经没饭吃了
returnVal = 5
}
sleepStorage.sleepTime = 5
Expand All @@ -583,6 +576,7 @@ function CommonFunctions () {
currentSleepTime.sleepTime = sleepTime || 10
if (resetCount) {
currentSleepTime.count = 0
currentSleepTime.startTime = new Date().getTime()
}
this.updateRuntimeStorage(SLEEP_TIME, currentSleepTime)
}
Expand Down Expand Up @@ -658,6 +652,7 @@ function CommonFunctions () {
let initSleepTime = {
sleepTime: 10,
count: 0,
startTime: new Date().getTime(),
date: today
}
let runtimeStorages = storages.create(RUNNING_PACKAGE)
Expand Down

0 comments on commit fcfdbb4

Please # to comment.