//许⊙帅是瞄准准心,系数可调
//设置分辨率
setScreenMetrics(1080,1920);
// 长按的时间系数根据实际情况调节
var press_coefficient = 1.392;
const under_game_score_y = 300;
const press_x = 163;
const press_y = 1822;
// 棋子的宽度,比截图中量到的稍微大一点比较安全,可能要调节
const piece_body_width = 80 ;
//棋子最顶部到棋子底部中点的距离
const piece_dist_from_top_to_base = 188;
//棋子大致颜色
const piece_color = "#3d3752";
var w = device.width;
var h = device.height;
//记录按键被按下时的触摸坐标
var xx = 0, yy = 0, boardX, boardY, sta=0;
//记录按键被按下时的悬浮窗位置
var windowX, windowY;
//记录按键被按下的时间以便判断长按等动作
var downTime;
var window = floaty.window( <frame>
<button id="action" text="许⊙帅" w="120" h="60" bg="#1f995566"/>
</frame>
);
//使这些函数调用更方便
const red = colors.red;
const green = colors.green;
const blue = colors.blue;
const max = Math.max;
const abs = Math.abs;
window.action.setOnTouchListener(function(view, event)
{
switch(event.getAction())
{
case event.ACTION_DOWN:
xx = event.getRawX();
yy = event.getRawY();
windowX = window.getX();
windowY = window.getY();
downTime = new Date().getTime();
sta=0;
return true;
case event.ACTION_MOVE:
window.setPosition(windowX + (event.getRawX() - xx), windowY + (event.getRawY() - yy));
sta=0;
return true;
case event.ACTION_UP:
boardX=window.getX()+60;
boardY=window.getY()+30;
sta=1;
return true;
}
return true;
});
prepare();
main();
function jump(boardX , piecex ,distance)
{
var fir=1.1, finaltime;
if(boardX <= piecex)
{
fir=0.74;
}
var press_time = distance * press_coefficient;
press_time = Math.max(200, press_time);
finaltime = parseInt(press_time) * fir;
press(press_x, press_y, parseInt(finaltime));
log("FinalTime="+parseInt(finaltime));
fir=1.1;
}
function find_piece(im)
{
//使用内置找色函数找出棋子最顶部的位置
var piece_top = findColor(im, piece_color, { region: [0, 300, 1080, 1580], threshold: 4 });
if(!piece_top)
{
log("Can't Spot Piece, Exit.");
exit(0);
}
var piece_start_x = -1;
var piece_end_x = -1;
//遍历该行找出棋子顶部中点位置
for(var x = 0; x < w; x++)
{
var is_piece = images.detectsColor(im, piece_color, x, piece_top.y);
if(is_piece && piece_start_x < 0)
{
piece_start_x = x;
}
if(!is_piece && piece_start_x >= 0)
{
piece_end_x = x;
break;
}
}
//棋子顶部中点位置
var piece_top_center_x = (piece_start_x + piece_end_x) / 2;
var piece_x = piece_top_center_x;
var piece_y = piece_top.y + piece_dist_from_top_to_base;
return {
px: piece_x, py: piece_y
}
}
function main()
{
toast("请打开游戏,并在5秒内点击开始按钮");
log("MainStarted.....................");
waitForActivity("com.tencent.mm.plugin.appbrand.ui.AppBrandUI");
sleep(5000);
var deltaX,deltaY,im,piece;
while(1)
{
if(currentActivity() != "com.tencent.mm.plugin.appbrand.ui.AppBrandUI")
{
log("Wait For WeChat");
sleep(1000);
continue;
}
im = captureScreen();
// 获取棋子和的位置
piece = find_piece(im);
log(piece.px+" "+piece.py);
if( piece.x!=0 && piece.y !=0 && sta==1 )
{
deltaX=abs(boardX - piece.px);
deltaY=abs(boardY - piece.py);
toast("jump");
log("BoardX="+boardX+",BoardY="+boardY+";piece.px="+piece.px+",piece.py="+piece.py);
log("Jump");
jump(boardX,piece.px,Math.sqrt(deltaX * deltaX + deltaY * deltaY));
}
else
{
log("Wait For User");
continue;
}
sta=0;
piece.x=0;
piece.y=0;
sleep(950);
}
}
function prepare()
{
//确保无障碍服务开启
auto();
//请求截图权限
requestScreenCapture();
//请求稳定窗口
setInterval(()=>{}, 1000);
//让用户输入系数
// press_coefficient = dialogs.input("调整跳跃系数(可选)", press_coefficient);
}