Skip to content

Commit

Permalink
wip: First draft tested with Int'l and no max send time
Browse files Browse the repository at this point in the history
  • Loading branch information
mcs committed Oct 31, 2024
1 parent a1ecf45 commit 203b158
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 49 deletions.
Binary file modified scripts/com.r2studio.TsumBeta/index.zip
Binary file not shown.
122 changes: 73 additions & 49 deletions scripts/com.r2studio.TsumBeta/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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});
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -2516,36 +2526,50 @@ 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) {
this.sleep(700); // end bug
}
}
}
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() {
Expand Down

0 comments on commit 203b158

Please sign in to comment.