Skip to content

Commit

Permalink
Merge pull request #86 from alfficcadenti/99Mana
Browse files Browse the repository at this point in the history
99 mana
  • Loading branch information
alfficcadenti authored Nov 26, 2021
2 parents 767a930 + ea30797 commit edc731a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 29 deletions.
58 changes: 30 additions & 28 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,35 +185,34 @@ async function startBotPlayMatch(page, browser) {
await page.waitForSelector('.btn--create-team', { timeout: 50000 })
.then(()=>console.log('start the match'))
.catch(async (e)=> {
console.error('[Error while waiting for battle]');
console.error('Refreshing the page and retrying to retrieve a battle');
await page.waitForTimeout(5000);
await page.reload();
await page.waitForTimeout(5000);
await page.waitForXPath("//button[contains(., 'BATTLE')]", { timeout: 20000 })
.then(button => {console.log('Battle button clicked'); button.click()})
.catch(e=>console.error('[ERROR] waiting for Battle button. is Splinterlands in maintenance?'));
await page.waitForSelector('.btn--create-team', { timeout: 50000 })
.then(()=>console.log('start the match'))
.catch(async ()=>{
console.log('second attempt failed reloading from homepage...');
await page.goto('https://splinterlands.io/');
await page.waitForTimeout(5000);
await page.waitForXPath("//button[contains(., 'BATTLE')]", { timeout: 20000 })
.then(button => button.click())
.catch(e=>console.error('[ERROR] waiting for Battle button second time'));
await page.waitForTimeout(5000);
await page.waitForSelector('.btn--create-team', { timeout: 50000 })
.then(()=>console.log('start the match'))
.catch((e)=>{
console.log('third attempt failed');
throw new Error(e);})
})
})
console.error('[Error while waiting for battle]');
console.error('Refreshing the page and retrying to retrieve a battle');
await page.waitForTimeout(5000);
await page.reload();
await page.waitForTimeout(5000);
await page.waitForXPath("//button[contains(., 'BATTLE')]", { timeout: 20000 })
.then(button => {console.log('Battle button clicked'); button.click()})
.catch(e=>console.error('[ERROR] waiting for Battle button. is Splinterlands in maintenance?'));
await page.waitForSelector('.btn--create-team', { timeout: 50000 })
.then(()=>console.log('start the match'))
.catch(async ()=>{
console.log('second attempt failed reloading from homepage...');
await page.goto('https://splinterlands.io/');
await page.waitForTimeout(5000);
await page.waitForXPath("//button[contains(., 'BATTLE')]", { timeout: 20000 })
.then(button => button.click())
.catch(e=>console.error('[ERROR] waiting for Battle button second time'));
await page.waitForTimeout(5000);
await page.waitForSelector('.btn--create-team', { timeout: 50000 })
.then(()=>console.log('start the match'))
.catch((e)=>{
console.log('third attempt failed');
throw new Error(e);})
})
})
} catch(e) {
console.error('[Battle cannot start]:', e)
throw new Error('The Battle cannot start');

}
await page.waitForTimeout(10000);
let [mana, rules, splinters] = await Promise.all([
Expand Down Expand Up @@ -254,7 +253,9 @@ async function startBotPlayMatch(page, browser) {
console.log(teamToPlay.summoner,'divId not found, reload and try again')
page.reload();
await page.waitForTimeout(2000);
page.waitForXPath(`//div[@card_detail_id="${teamToPlay.summoner}"]`, { timeout: 10000 }).then(summonerButton => summonerButton.click())
page.waitForXPath(`//div[@card_detail_id="${teamToPlay.summoner}"]`, { timeout: 10000 })
.then(summonerButton => {summonerButton.click();console.log(teamToPlay.summoner,'clicked')})
.catch(()=>{console.log(teamToPlay.summoner,'not clicked')})
});
if (card.color(teamToPlay.cards[0]) === 'Gold') {
const playTeamColor = teamActualSplinterToPlay(teamToPlay.cards.slice(0, 6)) || matchDetails.splinters[0]
Expand All @@ -266,7 +267,8 @@ async function startBotPlayMatch(page, browser) {
for (i = 1; i <= 6; i++) {
console.log('play: ', teamToPlay.cards[i].toString())
await teamToPlay.cards[i] ? page.waitForXPath(`//div[@card_detail_id="${teamToPlay.cards[i].toString()}"]`, { timeout: 10000 })
.then(selector => selector.click()) : console.log('nocard ', i);
.then(selector => {selector.click();console.log(teamToPlay.cards[i],'clicked')})
.catch(()=>{console.log(teamToPlay.cards[i],'not clicked')}) : console.log('nocard ', i);
await page.waitForTimeout(1000);
}

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.0.1",
"version": "1.2.1",
"description": "",
"main": "main.js",
"engines": {
Expand Down
3 changes: 3 additions & 0 deletions possibleTeams.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ const askFormation = function (matchDetails) {
const possibleTeams = async (matchDetails, acc) => {
let possibleTeams = [];
while (matchDetails.mana > 10) {
if (matchDetails.mana === 98) {
matchDetails.mana = 45;
}
console.log('check battles based on mana: '+matchDetails.mana);
account = acc;
possibleTeams = await askFormation(matchDetails);
Expand Down

0 comments on commit edc731a

Please sign in to comment.