Skip to content

Commit

Permalink
Wild Mode only (#120)
Browse files Browse the repository at this point in the history
* update for bugfix due to SPS UI release

* updated version bugfix ui battle details

* UPDATE for Wild mode only and fixed quest names
  • Loading branch information
alfficcadenti authored Jul 15, 2022
1 parent 16161c8 commit a2a59b7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
28 changes: 15 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,9 @@ async function findBattleResultsModal(page) {

try {
const winner = await getElementText(page, 'section.player.winner .bio__name__display', 15000);
console.log('the winner is:',winner)
if (winner.trim() == account) {
const decWon = await getElementText(page, '.player.winner span.dec-reward span', 1000);
const decWon = await getElementText(page, 'section.player.winner span.dec-reward span', 1000).catch(()=> { console.log('No Rewards Found'); return 0; });;
console.log(chalk.green('You won! Reward: ' + decWon + ' DEC'));
totalDec += !isNaN(parseFloat(decWon)) ? parseFloat(decWon) : 0 ;
winTotal += 1;
Expand All @@ -260,8 +261,8 @@ async function findBattleResultsModal(page) {
console.log(chalk.red('You lost'));
loseTotal += 1;
}
} catch {
console.log('Could not find winner - draw?');
} catch (e) {
console.log('Could not find winner - draw?', e);
undefinedTotal += 1;
}
await clickOnElement(page, '.btn--done', 20000, 10000);
Expand All @@ -279,7 +280,7 @@ async function commenceBattle(page) {
0: modal #wait_for_opponent_dialog has not appeared
1: modal #wait_for_opponent_dialog has appeared and not closed
*/
let btnRumbleTimeout = 20000;
let btnSkipTimeout = 20000;

console.log('check #wait_for_opponent_dialog modal visibility');
waitForOpponentDialogStatus = await page.waitForSelector('#wait_for_opponent_dialog', { timeout: 10000, visible: true })
Expand All @@ -288,21 +289,21 @@ async function commenceBattle(page) {

if (waitForOpponentDialogStatus === 1) {
await page.waitForSelector('#wait_for_opponent_dialog', { timeout: 100000, hidden: true })
.then(()=> { console.log('wait_for_opponent_dialog has closed'); btnRumbleTimeout = 5000; })
.then(()=> { console.log('wait_for_opponent_dialog has closed'); btnSkipTimeout = 5000; })
.catch((e)=> console.log(e.message));
}

await page.waitForTimeout(5000);
const isBtnRumbleVisible = await page.waitForSelector('#btnRumble', { timeout: btnRumbleTimeout })
const isBtnSkipVisible = await page.waitForSelector('#btnSkip', { timeout: btnSkipTimeout })
.then(()=> { console.log('btnRumble visible'); return true; })
.catch(()=> { console.log('btnRumble not visible'); return false; });
// if btnRumble not visible, check battle results modal in case the opponent surrendered
if (!isBtnRumbleVisible && await findBattleResultsModal(page)) return
else if (!isBtnRumbleVisible) return
if (!isBtnSkipVisible && await findBattleResultsModal(page)) return
else if (!isBtnSkipVisible) return

await page.waitForTimeout(5000);
await page.$eval('#btnRumble', elem => elem.click()).then(()=>console.log('btnRumble clicked')).catch(()=>console.log('btnRumble didnt click')); //start rumble
await page.waitForSelector('#btnSkip', { timeout: 10000 }).then(()=>console.log('btnSkip visible')).catch(()=>console.log('btnSkip not visible'));
//await page.waitForTimeout(5000);
//await page.$eval('#btnRumble', elem => elem.click()).then(()=>console.log('btnRumble clicked')).catch(()=>console.log('btnRumble didnt click')); //start rumble
await page.waitForSelector('#btnSkip', { timeout: 30000 }).then(()=>console.log('btnSkip visible')).catch(()=>console.log('btnSkip not visible'));
await page.$eval('#btnSkip', elem => elem.click()).then(()=>console.log('btnSkip clicked')).catch(()=>console.log('btnSkip not visible')); //skip rumble
await page.waitForTimeout(5000);

Expand All @@ -321,7 +322,7 @@ async function startBotPlayMatch(page, browser) {
});

await page.goto('https://splinterlands.com/');
await page.waitForTimeout(8000);
await page.waitForTimeout(5000);

let item = await page.waitForSelector('#log_in_button > button', {
visible: true,
Expand All @@ -341,6 +342,7 @@ async function startBotPlayMatch(page, browser) {
await page.waitForTimeout(8000);
await closePopups(page);
await closePopups(page);
await clickOnElement(page, '#bh_wild_toggle', 1000, 2000);

const ecr = await checkEcr(page);
if (ecr === undefined) throw new Error('Fail to get ECR.')
Expand Down Expand Up @@ -372,7 +374,7 @@ async function startBotPlayMatch(page, browser) {

if(process.env.SKIP_QUEST && quest?.splinter && process.env.SKIP_QUEST.split(',').includes(quest?.splinter) && quest?.total !== quest?.completed) {
try {
await page.click('#quest_new_btn')
await page.click('#focus_new_btn')
.then(async a=>{
await page.reload();
console.log('New quest requested')})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "splinterlands-bot",
"version": "1.13.0",
"version": "1.14.0",
"description": "",
"main": "main.js",
"engines": {
Expand Down
3 changes: 3 additions & 0 deletions quests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ const fetch = require("node-fetch");
const quests = [
{name: "defend", element: "life"},
{name: "pirate", element: "water"},
{name: "High Priority Targets", element: "snipe"},
{name: "lyanna", element: "earth"},
{name: "stir", element: "fire"},
{name: "rising", element: "death"},
{name: "Stubborn Mercenaries", element: "neutral"},
{name: "gloridax", element: "dragon"},
{name: "Stealth Mission", element: "sneak"},
]

const getQuestSplinter = (questName) => {
Expand Down

0 comments on commit a2a59b7

Please sign in to comment.