Skip to content

Commit

Permalink
feat: 装备强化
Browse files Browse the repository at this point in the history
  • Loading branch information
Zebartin committed Mar 21, 2023
1 parent 3be92de commit fef9d48
Show file tree
Hide file tree
Showing 3 changed files with 273 additions and 78 deletions.
145 changes: 140 additions & 5 deletions NIKKE/NIKKE日常.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
var {
启动NIKKE, 等待NIKKE加载, 退出NIKKE,
mostSimilar, 返回首页, 关闭限时礼包
mostSimilar, 返回首页, 关闭限时礼包,
detectNikkes
} = require('./NIKKEutils.js');
var { 模拟室 } = require('./模拟室.js');
var {
ocrUntilFound, clickRect, findImageByFeature,
requestScreenCaptureAuto, getDisplaySize
requestScreenCaptureAuto, getDisplaySize,
findContoursRect
} = require('./utils.js');
let width, height;
let NIKKEstorage = storages.create("NIKKEconfig");
Expand Down Expand Up @@ -40,7 +42,8 @@ function 日常() {
竞技场: 竞技场,
爬塔: 爬塔,
咨询: 咨询,
模拟室: () => 模拟室(true)
模拟室: () => 模拟室(true),
每日任务: 每日任务
};
let alreadyRetry = 0;
const maxRetry = NIKKEstorage.get('maxRetry', 1);
Expand Down Expand Up @@ -97,7 +100,7 @@ function 商店() {
clickRect(ocrUntilFound(res => res.find(e => e.text == '购买'), 30, 1000));
let affordable = true;
ocrUntilFound(res => {
if (res.text.includes('不足')) {
if (res.find(e => e.text.match(/不足.?$/) != null)) {
affordable = false;
return true;
}
Expand Down Expand Up @@ -786,4 +789,136 @@ function 单次咨询(advise) {
}
toast('回到咨询首页');
return true;
}
}

function listEquip() {
let [equip, leftBound, lowerBound] = ocrUntilFound(res => {
let e = res.find(e => e.text == 'EQUIP');
let le = res.find(e => e.text.match(/(装备|技能|魔方)/) != null);
let lo = res.find(e => e.text.match(/(快捷|全部)/) != null);
if (!e || !le || !lo)
return null;
return [e.bounds.bottom, le.bounds.right, lo.bounds.top];
}, 30, 300);
let ret = [];
let equipHeight = lowerBound - equip;
for (let i = 0; i < 10; ++i) {
ret = findContoursRect(captureScreen(), {
thresh: 160,
region: [leftBound, equip, width - leftBound, equipHeight]
}).filter(rect => {
if (rect.height() < equipHeight / 4 || rect.height() > equipHeight / 2)
return false;
if (rect.width() < equipHeight / 4 || rect.width() > equipHeight / 2)
return false;
return true;
});
if (ret.length == 4)
break;
}
return ret;
}

function 强化装备() {
let dailyMission = NIKKEstorage.get('dailyMission', {});
let targetEquip = dailyMission.equipEnhanceSlot || 0;
let targetNikke = dailyMission.equipEnhanceNikke || '';
if (targetNikke == '') {
toastLog('未指定强化装备妮姬');
return;
}
let targetNikkeReg = new RegExp(targetNikke);
let target = null;
clickRect(ocrUntilFound(res => res.find(e => e.text == '妮姬'), 40, 1000));
let upperBound = ocrUntilFound(res => {
let upper = res.find(e => e.text == 'ALL');
if (!upper)
return null;
return upper.bounds.bottom;
}, 30, 600);
// 找到指定妮姬
for (let retry = 0; target == null && retry < 3; ++retry) {
if (retry > 0)
for (let i = 0; i < 7; ++i)
swipe(width / 2, (upperBound + height) / 2, width / 2, height, 300);
sleep(1000);
let lastNikke = null;
for (let page = 0; page < 10; ++page) {
let nikkes = detectNikkes(captureScreen(), [0, upperBound]);
if (nikkes[nikkes.length - 1].name == lastNikke)
break;
lastNikke = nikkes[nikkes.length - 1].name;
let bottomY = nikkes[nikkes.length - 1].bounds.bottom;
let t = mostSimilar(targetNikke, nikkes.map(x => x.name));
if (t.similarity > 0.5) {
target = nikkes.find(e => e.name == t.result);
break;
}
t = nikkes.find(x => targetNikkeReg.test(x.name));
if (t != null) {
target = t;
break;
}
swipe(width / 2, bottomY, width / 2, upperBound, 1000);
swipe(100, bottomY, width / 2, bottomY, 500);
sleep(500);
}
}
if (target == null) {
console.error(`没有找到名为“${targetNikke}”的妮姬`);
clickRect(ocrUntilFound(res => res.find(e => e.text == '大厅'), 30, 1000));
return;
}
clickRect(target, 0.01);
ocrUntilFound(res => res.text.match(/(STATUS|体力|攻击|返回)/), 30, 1000);
// 点击指定装备
clickRect({ bounds: listEquip()[targetEquip] });
ocrUntilFound(res => res.find(e => e.text.match(/^(升级|穿戴|交换|改造)/) == null), 20, 1000);
// 检查是否可以升级
let enhanceBtn = ocrUntilFound(res => res.find(e => e.text.match(/^升级$/) != null), 3, 1000);
if (enhanceBtn == null) {
toastLog('指定装备不可升级');
back();
返回首页();
return;
}
// 检查升级材料
clickRect(enhanceBtn);
let [enhanceConfirm, equipUpperBound] = ocrUntilFound(res => {
if (!res.text.includes('自动'))
return null;
let confirm = res.find(e => e.text == '升级');
let upper = res.find(e => e.text.match(/(择升|级别|等级)/) != null);
if (!confirm || !upper)
return null;
return [confirm, upper.bounds.bottom];
}, 30, 1000);
let enhanceStuff = findContoursRect(captureScreen(), {
thresh: 170,
region: [0, equipUpperBound, width, enhanceConfirm.bounds.top - equipUpperBound]
}).filter(x => {
if (x.width() < 100)
return false;
if (Math.abs(x.width() - x.height()) > 20)
return false;
return true;
});
if (enhanceStuff.length == 0) {
toastLog('没有强化材料');
} else {
clickRect({ bounds: enhanceStuff[0] });
clickRect(enhanceConfirm);
sleep(1000);
while (colors.blue(captureScreen().pixel(
enhanceConfirm.bounds.left,
enhanceConfirm.bounds.top
)) > 220)
sleep(300);
}
back();
返回首页();
}

function 每日任务() {
强化装备();
}
155 changes: 82 additions & 73 deletions NIKKE/NIKKE设置.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,78 +114,64 @@ ui.layout(
</horizontal>
<text margin="10 2" textSize="14sp">刷buff时只考虑以下增益效果:</text>
<vertical>
<card w="*" h="auto" margin="10 2" cardCornerRadius="2dp"
cardElevation="1dp">
<horizontal gravity="center_vertical">
<checkbox id="引流转换器" marginLeft="4" marginRight="6" />
<vertical padding="18 8" h="auto" w="0" layout_weight="1">
<text text="引流转换器" textColor="#222222" textSize="14sp" />
<text text="攻击命中时恢复体力" textColor="#999999" textSize="12sp" />
</vertical>
</horizontal>
</card>
<card w="*" h="auto" margin="10 2" cardCornerRadius="2dp"
cardElevation="1dp">
<horizontal gravity="center_vertical">
<checkbox id="高品质粉末" marginLeft="4" marginRight="6" />
<vertical padding="18 8" h="auto" w="0" layout_weight="1">
<text text="高品质粉末" textColor="#222222" textSize="14sp" />
<text text="提高攻击力(不限对象)" textColor="#999999" textSize="12sp" />
</vertical>
</horizontal>
</card>
<card w="*" h="auto" margin="10 2" cardCornerRadius="2dp"
cardElevation="1dp">
<horizontal gravity="center_vertical">
<checkbox id="冲击引流器" marginLeft="4" marginRight="6" />
<vertical padding="18 8" h="auto" w="0" layout_weight="1">
<text text="冲击引流器" textColor="#222222" textSize="14sp" />
<text text="提高暴击伤害(不限对象)" textColor="#999999" textSize="12sp" />
</vertical>
</horizontal>
</card>
<card w="*" h="auto" margin="10 2" cardCornerRadius="2dp"
cardElevation="1dp">
<horizontal gravity="center_vertical">
<checkbox id="控制引导器" marginLeft="4" marginRight="6" />
<vertical padding="18 8" h="auto" w="0" layout_weight="1">
<text text="控制引导器" textColor="#222222" textSize="14sp" />
<text text="提高暴击率(不限对象)" textColor="#999999" textSize="12sp" />
</vertical>
</horizontal>
</card>
<card w="*" h="auto" margin="10 2" cardCornerRadius="2dp"
cardElevation="1dp">
<horizontal gravity="center_vertical">
<checkbox id="聚焦瞄准镜" marginLeft="4" marginRight="6" />
<vertical padding="18 8" h="auto" w="0" layout_weight="1">
<text text="聚焦瞄准镜" textColor="#222222" textSize="14sp" />
<text text="提高命中率" textColor="#999999" textSize="12sp" />
</vertical>
</horizontal>
</card>
<card w="*" h="auto" margin="10 2" cardCornerRadius="2dp"
cardElevation="1dp">
<horizontal gravity="center_vertical">
<checkbox id="隐形粉" marginLeft="4" marginRight="6" />
<vertical padding="18 8" h="auto" w="0" layout_weight="1">
<text text="隐形粉" textColor="#222222" textSize="14sp" />
<text text="提高全蓄力攻击伤害" textColor="#999999" textSize="12sp" />
</vertical>
</horizontal>
</card>
<card w="*" h="auto" margin="10 2" cardCornerRadius="2dp"
cardElevation="1dp">
<horizontal gravity="center_vertical">
<checkbox id="快速充电器" marginLeft="4" marginRight="6" />
<vertical padding="18 8" h="auto" w="0" layout_weight="1">
<text text="快速充电器" textColor="#222222" textSize="14sp" />
<text text="减少蓄力时间" textColor="#999999" textSize="12sp" />
</vertical>
</horizontal>
</card>
<horizontal gravity="bottom">
<checkbox id="引流转换器" marginLeft="10" marginRight="6" />
<text text="引流转换器" textColor="#222222" textSize="14sp" layout_weight="3" w="0" />
<text text="攻击命中时恢复体力" textColor="#999999" textSize="12sp" layout_weight="7" w="0" />
</horizontal>
<horizontal gravity="bottom">
<checkbox id="高品质粉末" marginLeft="10" marginRight="6" />
<text text="高品质粉末" textColor="#222222" textSize="14sp" layout_weight="3" w="0" />
<text text="提高攻击力(不限对象)" textColor="#999999" textSize="12sp" layout_weight="7" w="0" />
</horizontal>
<horizontal gravity="bottom">
<checkbox id="冲击引流器" marginLeft="10" marginRight="6" />
<text text="冲击引流器" textColor="#222222" textSize="14sp" layout_weight="3" w="0" />
<text text="提高暴击伤害(不限对象)" textColor="#999999" textSize="12sp" layout_weight="7" w="0" />
</horizontal>
<horizontal gravity="bottom">
<checkbox id="控制引导器" marginLeft="10" marginRight="6" />
<text text="控制引导器" textColor="#222222" textSize="14sp" layout_weight="3" w="0" />
<text text="提高暴击率(不限对象)" textColor="#999999" textSize="12sp" layout_weight="7" w="0" />
</horizontal>
<horizontal gravity="bottom">
<checkbox id="聚焦瞄准镜" marginLeft="10" marginRight="6" />
<text text="聚焦瞄准镜" textColor="#222222" textSize="14sp" layout_weight="3" w="0" />
<text text="提高命中率" textColor="#999999" textSize="12sp" layout_weight="7" w="0" />
</horizontal>
<horizontal gravity="bottom">
<checkbox id="隐形粉" marginLeft="10" marginRight="6" />
<text text="隐形粉" textColor="#222222" textSize="14sp" layout_weight="3" w="0" />
<text text="提高全蓄力攻击伤害" textColor="#999999" textSize="12sp" layout_weight="7" w="0" />
</horizontal>
<horizontal gravity="bottom">
<checkbox id="快速充电器" marginLeft="10" marginRight="6" />
<text text="快速充电器" textColor="#222222" textSize="14sp" layout_weight="3" w="0" />
<text text="减少蓄力时间" textColor="#999999" textSize="12sp" layout_weight="7" w="0" />
</horizontal>
</vertical>
</vertical>
<card w="*" h="auto" margin="10 5" cardCornerRadius="2dp"
cardElevation="1dp">
<horizontal gravity="center_vertical">
<checkbox id="每日任务" marginLeft="4" marginRight="6" />
<vertical padding="18 8" h="auto" w="0" layout_weight="1">
<text text="每日任务" textColor="#222222" textSize="16sp" />
<text text="完成其他每日任务:强化装备、社交点数招募" textColor="#999999" textSize="14sp" />
</vertical>
</horizontal>
</card>
<vertical id="dailyMission" visibility="gone">
<text textSize="16sp" margin="8">每日任务设置</text>
<horizontal margin="10 2">
<text textSize="14sp" w="0" layout_weight="5">强化装备指定妮姬:</text>
<input textSize="14sp" id="equipEnhanceNikke" w="0" layout_weight="5" hint="妮姬名/正则表达式" />
</horizontal>
<horizontal margin="10 2">
<text id="equipEnhanceSlotText" textSize="14sp" w="0" layout_weight="5">强化装备部位:头</text>
<seekbar id="equipEnhanceSlot" w="0" layout_weight="5" />
</horizontal>
</vertical>
</vertical>
<text textSize="16sp" margin="8 50 8 8">其他设置</text>
<vertical>
Expand Down Expand Up @@ -255,7 +241,7 @@ function checkUpdate() {
const NIKKEstorage = storages.create("NIKKEconfig");
const todoTaskDefault = [
"商店", "基地收菜", "好友", "竞技场",
"爬塔", "咨询", "模拟室"
"爬塔", "咨询", "模拟室", "每日任务"
];
const simulationRoomDefault = {
maxPass: 20,
Expand Down Expand Up @@ -283,6 +269,9 @@ ui.findView('竞技场').on('check', function (checked) {
ui.findView('模拟室').on('check', function (checked) {
ui.simulationRoom.attr('visibility', checked ? 'visible' : 'gone');
});
ui.findView('每日任务').on('check', function (checked) {
ui.dailyMission.attr('visibility', checked ? 'visible' : 'gone');
});

ui.buyCodeManual.setMin(0);
ui.buyCodeManual.setMax(4);
Expand Down Expand Up @@ -366,6 +355,17 @@ for (let task of todoTask)
for (let buffName of simulationRoom.preferredBuff)
ui.findView(buffName).setChecked(true);

ui.equipEnhanceSlot.setMin(0);
ui.equipEnhanceSlot.setMax(3);
ui.equipEnhanceSlot.setOnSeekBarChangeListener({
onProgressChanged: function (seekbar, p, fromUser) {
ui.equipEnhanceSlotText.setText(`强化装备部位:${'头身手腿'[p]}`);
}
});
let dailyMission = NIKKEstorage.get('dailyMission', {});
ui.equipEnhanceNikke.setText(dailyMission.equipEnhanceNikke || '');
ui.equipEnhanceSlot.setProgress(dailyMission.equipEnhanceSlot || 0);

for (let generalOption of [
'mute', 'alreadyInGame', 'checkUpdateAuto',
'checkSale', 'exitGame', 'checkDailyLogin', 'v2rayNG'
Expand Down Expand Up @@ -414,10 +414,14 @@ ui.save.on("click", function () {
toast('模拟室编队格式有误,无法保存');
return;
}
if (ui.findView('每日任务').isChecked() && ui.equipEnhanceNikke.text().trim() == '') {
toast('强化装备指定妮姬不可留空,无法保存');
return;
}
let todoTask = [];
for (let task of [
"基地收菜", "好友", "竞技场",
"商店", "爬塔", "咨询", "模拟室"
"基地收菜", "好友", "竞技场", "商店",
"爬塔", "咨询", "模拟室", "每日任务"
])
if (ui.findView(task).isChecked())
todoTask.push(task);
Expand All @@ -440,6 +444,11 @@ ui.save.on("click", function () {
simulationRoom.preferredBuff.push(buffName);
NIKKEstorage.put('simulationRoom', JSON.stringify(simulationRoom));

let dailyMission = {};
dailyMission.equipEnhanceNikke = ui.equipEnhanceNikke.text().trim();
dailyMission.equipEnhanceSlot = ui.equipEnhanceSlot.getProgress();
NIKKEstorage.put('dailyMission', dailyMission);

for (let generalOption of [
'mute', 'alreadyInGame', 'checkUpdateAuto',
'checkSale', 'exitGame', 'checkDailyLogin', 'v2rayNG'
Expand Down

0 comments on commit fef9d48

Please sign in to comment.