diff --git a/scripts/com.r2studio.TsumBeta/index.zip b/scripts/com.r2studio.TsumBeta/index.zip index 3241c79e..f7f21735 100644 Binary files a/scripts/com.r2studio.TsumBeta/index.zip and b/scripts/com.r2studio.TsumBeta/index.zip differ diff --git a/scripts/com.r2studio.TsumBeta/src/index.js b/scripts/com.r2studio.TsumBeta/src/index.js index 2a59396a..6a3d69ce 100644 --- a/scripts/com.r2studio.TsumBeta/src/index.js +++ b/scripts/com.r2studio.TsumBeta/src/index.js @@ -1227,6 +1227,7 @@ function Tsum(isJP, detect, logs) { this.claimAllWithoutCoins = false; this.nextMonitorExecution = 0; this.lastVisitedPages = {init1: true, init2: true, init3: true}; // trigger initial monitor call on script startup + this.sendHeartsDownwards = true; this.init(detect); } @@ -2392,25 +2393,35 @@ Tsum.prototype.friendPageGoToSelf = function() { this.sleep(2000); } -Tsum.prototype.taskSendHearts = function() { - if (this.findPage() === 'GamePause') - return; - log(this.logs.friendsPage); - this.goFriendPage(); - log(this.logs.startSendingHearts); - this.sleep(1000); - if (this.sendHeartMaxDuring === 0) { - this.friendPageGoToSelf(); - tap(0, 0, 20); // Avoid overlap between zero score and pointer location - } - - var startTime = Date.now(); +Tsum.prototype.doHeartSending = function(startTime) { var retry = 0; var times = 0; var hfx = Button.outSendHeartFrom.x; var hfy = Button.outSendHeartFrom.y - 40; // hearts from y var hty = Button.outSendHeartTo.y + 30; // hearts to y - while(this.isRunning) { + var finished; + + function scrollToNextHearts() { + if (this.sendHeartsDownwards) { + this.tapDown({x: Button.outSendHeart3.x - 10, y: Button.outSendHeart3.y}, 50); + this.moveTo({x: Button.outSendHeart3.x - 10, y: Button.outSendHeart3.y}, 50); + this.moveTo({x: Button.outSendHeart3.x - 10, y: Button.outSendHeart2.y}, 50); + this.moveTo({x: Button.outSendHeart3.x - 10, y: Button.outSendHeart1.y}, 50); + this.moveTo({x: Button.outSendHeart3.x - 10, y: Button.outSendHeart0.y}, 50); + this.moveTo({x: Button.outSendHeart3.x - 10, y: Button.outSendHeartTop.y}, 500); + this.tapUp({x: Button.outSendHeart3.x - 10, y: Button.outSendHeartTop.y}, 100); + } else { + this.tapDown({x: Button.outSendHeart3.x - 10, y: Button.outSendHeart0.y}, 50); + this.moveTo({x: Button.outSendHeart3.x - 10, y: Button.outSendHeart0.y}, 50); + this.moveTo({x: Button.outSendHeart3.x - 10, y: Button.outSendHeart1.y}, 50); + this.moveTo({x: Button.outSendHeart3.x - 10, y: Button.outSendHeart2.y}, 50); + this.moveTo({x: Button.outSendHeart3.x - 10, y: Button.outSendHeart3.y}, 50); + this.moveTo({x: Button.outSendHeart3.x - 10, y: Button.outSendHeartBottom.y}, 500); + this.tapUp({x: Button.outSendHeart3.x - 10, y: Button.outSendHeartBottom.y}, 100); + } + } + + while (this.isRunning && typeof finished === 'undefined') { this.requestTsumMonitor(); times++; if (times % 15 === 0) { @@ -2423,7 +2434,7 @@ Tsum.prototype.taskSendHearts = function() { var img = this.screenshot(); var isOk = isSameColor(Button.outReceiveOk.color, this.getColor(img, Button.outReceiveOk), 40); - for(var y = hfy; y <= hty; y += 8) { + for (var y = hfy; y <= hty; y += 8) { var isHs = isSameColor(Button.outSendHeart0.color, this.getColor(img, {x: hfx, y: y}), 40); if (isHs) { heartsPos.push({x: hfx, y: y, color: Button.outSendHeart0.color, color2: Button.outSendHeart0.color2}); @@ -2442,17 +2453,20 @@ Tsum.prototype.taskSendHearts = function() { } } var isNotEnd = isSameColor(Button.outSendHeartEnd2.color, this.getColor(img, Button.outSendHeartEnd2), 40); //x: 75, y: 420 - var isEnd1 = isSameColor({r: 162, g: 84, b: 53}, this.getColor(img, {x: 75*3, y: 420*3}), 40); // {x: 75, y: 420, r: 162, g: 84, b: 53}} + var isEnd1 = isSameColor({r: 162, g: 84, b: 53}, this.getColor(img, {x: 75 * 3, y: 420 * 3}), 40); // {x: 75, y: 420, r: 162, g: 84, b: 53}} var isEnd2 = isSameColor(Button.outSendHeartEnd.color, this.getColor(img, Button.outSendHeartEnd), 40); // x: 109, y: 422 var isEnd3 = isSameColor(Button.outSendHeartEnd3.color, this.getColor(img, Button.outSendHeartEnd3), 40); // x: 105, y: 408 - var isNotEndJP = isSameColor(Button.outSendHeartEnd2.color, this.getColor(img, {x: 75*3, y: 352*3}), 40); //x: 75, y: 352 - var isEndJP1 = isSameColor({r: 162, g: 84, b: 53}, this.getColor(img, {x: 75*3, y: 352*3}), 40); // {x: 75, y: 352, r: 162, g: 84, b: 53}} - var isEndJP3 = isSameColor(Button.outSendHeartEnd3.color, this.getColor(img, {x: 105*3, y: 340*3}), 40); // x: 105, y: 340 + var isNotEndJP = isSameColor(Button.outSendHeartEnd2.color, this.getColor(img, {x: 75 * 3, y: 352 * 3}), 40); //x: 75, y: 352 + var isEndJP1 = isSameColor({r: 162, g: 84, b: 53}, this.getColor(img, {x: 75 * 3, y: 352 * 3}), 40); // {x: 75, y: 352, r: 162, g: 84, b: 53}} + var isEndJP3 = isSameColor(Button.outSendHeartEnd3.color, this.getColor(img, {x: 105 * 3, y: 340 * 3}), 40); // x: 105, y: 340 var isEnd = !this.isJP && (!isNotEnd && isEnd1 && isEnd2 && isEnd3); // both jp or global using this now var isEndJP = !isNotEndJP && isEndJP1 && isEnd2 && isEndJP3; + + var isTop = isSameColor({r: 255, g: 227, b: 115}, this.getColor(img, {x: 200, y: 670})); + releaseImage(img); if (this.isJP) { log('isNotEndJP', isNotEndJP, 'isEndJP1', isEndJP1, 'isEndJP3', isEndJP3, 'isEndJP', isEndJP, 'retry', retry, 'heartsLength', heartsPos.length, 'isZero', isZero); @@ -2464,25 +2478,21 @@ Tsum.prototype.taskSendHearts = function() { this.tap(Button.outReceiveOk); } - if ((heartsPos.length === 0 && (isEnd || isEndJP)) || (!this.sentToZero && isZero && heartsPos.length !== 0)) { - if(retry < 3){ - this.tapDown({x: Button.outSendHeart3.x - 10 ,y: Button.outSendHeart3.y }, 50); - this.moveTo ({x: Button.outSendHeart3.x - 10, y: Button.outSendHeart3.y }, 50); - this.moveTo ({x: Button.outSendHeart3.x - 10, y: Button.outSendHeart2.y }, 50); - this.moveTo ({x: Button.outSendHeart3.x - 10, y: Button.outSendHeart1.y }, 50); - this.moveTo ({x: Button.outSendHeart3.x - 10, y: Button.outSendHeart0.y }, 50); - this.moveTo ({x: Button.outSendHeart3.x - 10, y: Button.outSendHeartTop.y}, 500); - this.tapUp ({x: Button.outSendHeart3.x - 10, y: Button.outSendHeartTop.y}, 100); + if ((heartsPos.length === 0 && (isEnd || isEndJP || isTop)) || (!this.sentToZero && isZero && heartsPos.length !== 0)) { + if (retry < 3) { + scrollToNextHearts.call(this); retry++; log(this.logs.checkSendingHearts, retry); - this.sleep(1000); + this.sleep(2000); } else { if (this.sendHeartMaxDuring !== 0) { this.sleep(1000); this.friendPageGoToSelf(); } debug("Ending taskSendHearts"); - break; + this.sendHeartsDownwards = !this.sendHeartsDownwards; + // we're finished if we reached the top of the ranking and will send downwards again on the next run + finished = this.sendHeartsDownwards; } } else { var rTimes = 0; @@ -2506,7 +2516,7 @@ Tsum.prototype.taskSendHearts = function() { debug("Tried return to FriendPage"); } if (!this.isRunning) { - return; + return true; // don't let the surrounding job retry this immediately, so we pretend to be finished } } if (heartsPos.length !== 0 && rTimes === 0) { @@ -2516,29 +2526,14 @@ Tsum.prototype.taskSendHearts = function() { this.saveRecord(); } this.sleep(250); - if (true) { - this.tapDown({x: Button.outSendHeart3.x - 10 ,y: Button.outSendHeart3.y }, 50); - this.moveTo ({x: Button.outSendHeart3.x - 10, y: Button.outSendHeart3.y }, 50); - this.moveTo ({x: Button.outSendHeart3.x - 10, y: Button.outSendHeart2.y }, 50); - this.moveTo ({x: Button.outSendHeart3.x - 10, y: Button.outSendHeart1.y }, 50); - this.moveTo ({x: Button.outSendHeart3.x - 10, y: Button.outSendHeart0.y }, 50); - this.moveTo ({x: Button.outSendHeart3.x - 10, y: Button.outSendHeartTop.y}, 400); - this.tapUp ({x: Button.outSendHeart3.x - 10, y: Button.outSendHeartTop.y}, 100); - } else { - this.tapDown({x: Button.outSendHeart3.x - 10, y: Button.outSendHeart0.y }, 50); - this.moveTo ({x: Button.outSendHeart3.x - 10, y: Button.outSendHeart0.y }, 50); - this.moveTo ({x: Button.outSendHeart3.x - 10, y: Button.outSendHeart1.y }, 50); - this.moveTo ({x: Button.outSendHeart3.x - 10, y: Button.outSendHeart2.y }, 50); - this.moveTo ({x: Button.outSendHeart3.x - 10, y: Button.outSendHeart3.y }, 50); - this.moveTo ({x: Button.outSendHeart3.x - 10, y: Button.outSendHeartBottom.y}, 400); - this.tapUp ({x: Button.outSendHeart3.x - 10 ,y: Button.outSendHeartBottom.y}, 100); - } + scrollToNextHearts.call(this); this.sleep(400); if (this.sendHeartMaxDuring !== 0) { if (Date.now() - startTime > this.sendHeartMaxDuring) { + // we exceeded the maximum allowed sending time. leaving unfinished. log(this.logs.timeIsUp); - break; + finished = true; } } if (heartsPos.length === 0 && isEnd2) { @@ -2546,6 +2541,35 @@ Tsum.prototype.taskSendHearts = function() { } } } + return finished; +} + +Tsum.prototype.taskSendHearts = function() { + debug("Started taskSendHearts"); + if (this.findPage() === 'GamePause') + return; + log(this.logs.friendsPage); + this.goFriendPage(); + log(this.logs.startSendingHearts); + this.sleep(1000); + if (this.sendHeartMaxDuring === 0) { + this.friendPageGoToSelf(); + tap(0, 0, 20); // Avoid overlap between zero score and pointer location + } + + var startTime = Date.now(); + var finished; + do { + finished = this.doHeartSending(startTime); + debug("Finished doHeartSending with result " + finished); + this.sleep(2000); + if (!finished) { + this.friendPageGoToSelf(); + tap(0, 0, 20); // Avoid overlap between zero score and pointer location + } + this.sleep(2000); + } while (!finished) + debug("Finished taskSendHearts"); } Tsum.prototype.taskAutoUnlockLevel = function() {