Browse Source

开宝箱

master
kavil 1 year ago
parent
commit
9ae72903e0
  1. 2
      package.json
  2. 87
      src/baoxiang.ts
  3. 172
      src/index.ts
  4. 2
      src/lib/index.ts
  5. 35
      src/lib/utils.ts

2
package.json

@ -2,7 +2,7 @@
"name": "dpa-andriod-starter",
"version": "1.0.0",
"description": "一个用来快速开始编写 dpa-andriod 脚本的模板",
"main": "index.js",
"main": "baoxiang.js",
"scripts": {
"build": "webpack --config ./buildConfig/webpack.dev.js"
},

87
src/baoxiang.ts

@ -0,0 +1,87 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { DPStarter, DPTask } from './lib/index';
import { clickForce, isNextElement, findPrevElement, withMakeSure, swipeToCenter, nextElement } from './lib/utils';
// 弹窗关闭按钮
const = className('com.lynx.tasm.behavior.ui.LynxFlattenUI')
.boundsInside(100, device.height / 2, device.width - 100, device.height)
.clickable(true)
.text('');
// 福利界面底部栏入口按钮
const = id('di1').text('福利').visibleToUser();
class HongguoBao extends DPStarter {
doInit() {
withMakeSure('打开红果', () => app.launch('com.phoenix.read'), {
hasModal: [
() => {
if (nextElement(, 'com.lynx.tasm.behavior.ui.LynxFlattenUI') === null) {
return .findOne(500);
} else {
return null;
}
}
],
landOver: [() => .findOne(500)] // 确认是否到达目的页
});
clickForce(.findOne(500));
}
doFinish() {
sleep(3000);
app.launch('org.autojs.autoxjs.v6');
}
}
const hongguoBao = new HongguoBao();
const task = new DPTask(hongguoBao, '开宝箱');
task.run((task) => {
const = className('com.lynx.tasm.behavior.ui.text.FlattenUIText').textContains('宝箱').visibleToUser();
const = className('com.lynx.tasm.behavior.ui.text.FlattenUIText').textContains('看视频最高再领').visibleToUser();
if (!.exists()) {
task.log('没有找到宝箱');
return;
}
clickForce(.findOne(500));
withMakeSure('开宝箱', () => clickForce(.findOne(500)), {
landOver: [() => .findOne(500)] // 确认是否到达目的页
});
if (.exists()) {
clickForce(.findOne(1500), false);
lookAD();
}
});
function lookAD() {
//已经进入广告页面
const = className('com.lynx.tasm.behavior.ui.text.FlattenUIText').text('领取成功').visibleToUser();
const = className('com.lynx.tasm.behavior.ui.text.FlattenUIText').text('领取奖励').visibleToUser();
sleep(3000);
let ok = false;
let times = 0;
while (!ok) {
if (times > 100) {
break;
}
ok = .exists();
times % 2 === 1 && console.log('广告ing');
sleep(2000);
times++;
}
if (!ok) {
console.log('看广告失败');
return;
}
const bounds = .findOne(500)!.bounds();
click(bounds.right + 5, bounds.top + 5);
sleep(1000);
if (.exists()) {
clickForce(.findOne(500), false);
console.log('看第二个广告再次领取奖励');
lookAD();
}
}
hongguoBao.start();

172
src/index.ts

@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { DPStarter, DPTask } from './lib/index';
import { clickForce, clickForceXY, isNextElement, findPrevElement, withMakeSure, swipeToCenter } from './lib/utils';
import { clickForce, isNextElement, findPrevElement, withMakeSure, swipeToCenter, nextElement } from './lib/utils';
// 弹窗关闭按钮
const = className('com.lynx.tasm.behavior.ui.LynxFlattenUI')
@ -11,33 +11,37 @@ const 弹窗关闭按钮 = className('com.lynx.tasm.behavior.ui.LynxFlattenUI')
// 福利界面底部栏入口按钮
const = id('di1').text('福利').visibleToUser();
const lookTime = 60 * 8; // 看剧时间 默认8小时
class Hongguo extends DPStarter {
doInit() {
withMakeSure('打开红果', () => app.launch('com.phoenix.read'), {
hasModal: [
() => {
if (nextElement(, 'com.lynx.tasm.behavior.ui.LynxFlattenUI') === null) {
return .findOne(500);
} else {
return null;
}
}
],
landOver: [() => .findOne(500)] // 确认是否到达目的页
});
clickForce(.findOne(500));
}
doFinish() {
sleep(3000);
app.launch('org.autojs.autoxjs.v6');
}
}
const hongguo = new Hongguo();
const task = new DPTask(hongguo, '新人见面礼');
const task = new DPTask(hongguo, '日常福利-吃饭补贴');
const task = new DPTask(hongguo, '日常福利-签到');
const 广task = new DPTask(hongguo, '看广告视频');
const task = new DPTask(hongguo, '看短剧');
// 新人见面礼立即领取
task.run((task) => {
swipe(device.width / 2, device.height * 0.2, device.width / 2, device.height * 0.9, 500);
swipe(device.width / 2, device.height * 0.2, device.width / 2, device.height * 0.9, 500);
const = className('com.lynx.tasm.behavior.ui.text.FlattenUIText')
.boundsInside(0, 0, device.width / 2, device.height / 2)
.text('立即领取')
.visibleToUser();
const = className('com.lynx.tasm.behavior.ui.text.FlattenUIText').textContains('额外福利').visibleToUser();
const = findPrevElement(, 'com.lynx.tasm.behavior.ui.text.FlattenUIText');
const = className('com.lynx.tasm.behavior.ui.text.FlattenUIText').text('立即领取').visibleToUser();
const = className('com.lynx.tasm.behavior.ui.text.FlattenUIText').text('金币奖励可在「福利」查看').visibleToUser();
const = className('com.lynx.tasm.behavior.ui.text.FlattenUIText').text('明日再来').visibleToUser();
@ -45,7 +49,7 @@ const 看短剧task = new DPTask(hongguo, '看短剧');
const = withMakeSure(
'点击立即领取',
() => {
clickForce(.findOne(500));
clickForce();
return ;
},
{
@ -72,61 +76,7 @@ const 看短剧task = new DPTask(hongguo, '看短剧');
}
});
task.run(() => {
const = className('com.lynx.tasm.behavior.ui.text.FlattenUIText').text('吃饭补贴').visibleToUser();
withMakeSure('确保在吃饭补贴区域', () => .findOne(500), {
landOver: [() => .findOne(500)], // 确认是否到达目的页
auxAction: [
(makeSure) => {
// 如果有这个控件 直接划到可视区域
makeSure && swipe(makeSure.bounds().centerX(), makeSure.bounds().centerY(), makeSure.bounds().centerX(), 0, 500);
},
() => {
// 如果没有 滑到顶部
swipe(device.width / 2, device.height * 0.2, device.width / 2, device.height * 0.9, 500);
},
() => {
// 如果没有 往下滑动
swipe(device.width / 2, device.height * 0.7, device.width / 2, 0, 500);
}
]
});
swipeToCenter(.findOne(500)!);
const = className('com.lynx.tasm.behavior.ui.text.FlattenUIText').text('去领取').visibleToUser();
const = className('com.lynx.tasm.behavior.ui.text.UIText').textContains('早饭').visibleToUser();
const = className('com.lynx.tasm.behavior.ui.text.UIText').textContains('午饭').visibleToUser();
const = className('com.lynx.tasm.behavior.ui.text.UIText').textContains('晚饭').visibleToUser();
const = className('com.lynx.tasm.behavior.ui.text.UIText').textContains('夜宵').visibleToUser();
withMakeSure('签到', () => clickForce(.findOne(500)), {
landOver: [() => .findOne(500)], // 确认是否到达目的页
retry: 2
});
const eat = (ele: UiSelector) => {
clickForce(ele.findOne(500), false);
const = className('com.lynx.tasm.behavior.ui.text.FlattenUIText').textContains('后可领取奖励').visibleToUser();
const = className('com.lynx.tasm.behavior.ui.text.FlattenUIText').textContains('看视频再领').visibleToUser();
sleep(3000);
if (.exists()) {
lookAD();
sleep(3000);
if (.exists()) {
clickForce(.findOne(1500), false);
lookAD();
}
}
};
eat();
eat();
eat();
eat();
back();
});
const task = new DPTask(hongguo, '日常福利-签到');
task.run((task) => {
const = className('com.lynx.tasm.behavior.ui.text.FlattenUIText').text('日常福利').visibleToUser();
withMakeSure('确保在日常福利区域', () => .findOne(500), {
@ -170,6 +120,7 @@ const 看短剧task = new DPTask(hongguo, '看短剧');
clickForce(.findOne(1500));
});
const 广task = new DPTask(hongguo, '看广告视频');
广task.run(() => {
const = className('com.lynx.tasm.behavior.ui.text.FlattenUIText').text('日常福利').visibleToUser();
withMakeSure('确保在日常福利区域', () => .findOne(500), {
@ -198,77 +149,22 @@ const 看短剧task = new DPTask(hongguo, '看短剧');
lookAD();
});
task.run(() => {
const = className('com.lynx.tasm.behavior.ui.text.FlattenUIText').text('日常福利').visibleToUser();
withMakeSure('确保在日常福利区域', () => .findOne(500), {
landOver: [() => .findOne(500)], // 确认是否到达目的页
auxAction: [
(makeSure) => {
// 如果有这个控件 直接划到可视区域
makeSure && swipe(makeSure.bounds().centerX(), makeSure.bounds().centerY(), makeSure.bounds().centerX(), 0, 500);
},
() => {
// 如果没有 滑到顶部
swipe(device.width / 2, device.height * 0.2, device.width / 2, device.height * 0.9, 500);
},
() => {
// 如果没有 往下滑动
swipe(device.width / 2, device.height * 0.7, device.width / 2, 0, 500);
}
]
const task = new DPTask(hongguo, '开宝箱');
task.run((task) => {
const = className('com.lynx.tasm.behavior.ui.text.FlattenUIText').textContains('宝箱').visibleToUser();
const = className('com.lynx.tasm.behavior.ui.text.FlattenUIText').textContains('看视频最高再领').visibleToUser();
if (!.exists()) {
task.log('没有找到宝箱');
return;
}
clickForce(.findOne(500));
withMakeSure('开宝箱', () => clickForce(.findOne(500)), {
landOver: [() => .findOne(500)] // 确认是否到达目的页
});
const = className('com.lynx.tasm.behavior.ui.text.FlattenUIText').textContains('去看剧').visibleToUser();
clickForce(.findOne(500));
const = id('com.phoenix.read:id/nj').textContains('金币').visibleToUser();
const = className('android.widget.TextView').text('追剧');
const = className('com.lynx.tasm.behavior.ui.text.FlattenUIText').text('立即领取').visibleToUser();
const = className('com.lynx.tasm.behavior.ui.text.FlattenUIText').textContains('再攒').visibleToUser();
const = className('com.lynx.tasm.behavior.ui.text.UIText').textContains('看视频').visibleToUser();
const startTime = new Date().getTime();
let looking = true;
while (looking) {
if (.exists()) {
withMakeSure('领金币', () => clickForce(.findOne(500)), {
retry: 2,
landOver: [() => .findOne(500)]
});
const = findPrevElement(, 'com.lynx.tasm.behavior.ui.text.FlattenUIText');
clickForce();
if (.exists()) {
clickForce(.findOne(1500), false);
lookAD();
}
console.log('task0');
const = className('com.lynx.tasm.behavior.ui.text.FlattenUIText').text('开宝箱得金币');
if (.exists()) {
withMakeSure('开宝箱', () => clickForce(.findOne(500)), {
landOver: [() => .findOne(500)], // 确认是否到达目的页
retry: 2
});
if (.exists()) {
clickForce(.findOne(1500), false);
lookAD();
}
}
clickForce(.findOne(1500));
clickForce(.findOne(500));
}
if (!.exists()) {
looking = false;
}
sleep(30000);
console.log(`已经看了${((new Date().getTime() - startTime) / 1000 / 60).toFixed(1)}分钟`);
// 8小时结束
if (new Date().getTime() - startTime > 1000 * 60 * lookTime) {
looking = false;
}
if (.exists()) {
clickForce(.findOne(1500), false);
lookAD();
}
back();
});
function lookAD() {
@ -283,7 +179,7 @@ function lookAD() {
break;
}
ok = .exists();
console.log('广告ing');
times % 2 === 1 && console.log('广告ing');
sleep(2000);
times++;
}

2
src/lib/index.ts

@ -16,6 +16,7 @@ export abstract class DPStarter extends DPEvent<DPStarterEvents> {
console.log('初始化!');
this.doInit();
}
abstract doFinish(): void;
abstract doInit(): void;
@ -31,6 +32,7 @@ export abstract class DPStarter extends DPEvent<DPStarterEvents> {
if (index === this._tasks.length - 1) {
this.emit('exit');
this.doFinish && this.doFinish();
}
});
this._tasks[0]?.start();

35
src/lib/utils.ts

@ -5,7 +5,7 @@
*/
export function clickForce(ele: UiObject | null, muilt = true) {
if (!ele) {
console.log('控件不存在');
console.log('clickForce', '控件不存在');
return;
}
const bound = ele.bounds();
@ -33,6 +33,35 @@ export function clickForceXY(x: number, y: number, width?: number, height?: numb
click(x + 1, y - 1);
}
export function nextElement(ele: UiSelector, classNameString: string, step = 1) {
const findit = ele.findOne(500);
if (!findit) {
return null;
}
const eles = className(classNameString).find();
const index = eles.findIndex((ele) => {
if (ele.bounds().centerX() === findit.bounds().centerX() && ele.bounds().centerY() === findit.bounds().centerY()) {
return ele;
}
});
console.log('nextElement', eles[index + step]);
return eles[index + step];
}
export function prevElement(ele: UiSelector, classNameString: string, step = 1) {
const findit = ele.findOne(500);
if (!findit) {
return null;
}
const eles = className(classNameString).find();
const index = eles.findIndex((ele) => {
if (ele.bounds().centerX() === findit.bounds().centerX() && ele.bounds().centerY() === findit.bounds().centerY()) {
return ele;
}
});
return eles[index - step];
}
/**
* @description:
* @param {string} ele
@ -137,7 +166,7 @@ export function findNextElement(ele: UiSelector, classNameString: string, step =
export function swipeToCenter(ele: UiObject) {
if (!ele) {
console.log('控件不存在');
console.log('swipeToCenter', '控件不存在');
return;
}
const bound = ele.bounds();
@ -178,7 +207,7 @@ export function withMakeSure<T>(name: string, mainFn: () => T, options: MakeSure
const res = mainFn();
result = res || true;
console.log(name);
console.log('withMakeSure', name);
let whileNum = 0;
let ok = false;

Loading…
Cancel
Save