/** * Waits for the next turn to begin or the battle to end, kicking inactive players. * * @param kickAfterSeconds Clicks 'Kick inactive player' after this number of seconds. Set to 0 to * never kick * @return TurnEndStatus indicator. */ public TurnEndStatus waitForNextTurn(int kickAfterSeconds) { int waited = 0; boolean gameOver = false; while (!isElementPresent(By.cssSelector("div.whatdo")) && !gameOver) { if (!battleTimerOn && kickAfterSeconds != 0 && waited >= kickAfterSeconds * 1000) { kickInactivePlayer(); kickAfterSeconds = 0; } sleep(500); waited += 500; gameOver = ((Long) javascript("return curRoom.battle.done;") > 0); } updateBattleLog(); if (gameOver) { if (battlelog.contains(getUserName() + " won the battle!", true)) { return TurnEndStatus.WON; } else { return TurnEndStatus.LOST; } } else { String whatdoText = driver.findElement(By.cssSelector("div.whatdo")).getText(); if (whatdoText.contains("Switch " + getCurrentPokemon(false) + " to:")) { return TurnEndStatus.SWITCH; } else if (whatdoText.contains("What will " + getCurrentPokemon(false) + " do?")) { return TurnEndStatus.ATTACK; } } return TurnEndStatus.UNKNOWN; }
public void updateBattleLog() { battlelog.setLogText( driver.findElement(By.cssSelector("div.battle-log > div.inner")).getAttribute("innerHTML")); }
// Why? Answer: lazy. public static String substringToFirst(String s, int startIndex, String stop) { return BattleLog.substringToFirst(s, startIndex, stop); }