-
-
Save romaxd/3f816f846fdeeb55d9b5a8b1755e9d9b to your computer and use it in GitHub Desktop.
LSS Bot Rise of Kingdoms Fog Clearing v0.0 Script Source Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.lssbot.scripts.rok.fog; | |
import com.lssbot.core.api.device.Device; | |
import com.lssbot.core.api.game.Game; | |
import com.lssbot.core.api.script.AbstractScript; | |
import com.lssbot.core.api.script.ScriptManifest; | |
import com.lssbot.core.api.script.config.Config; | |
/** | |
* @author Roma on 01.10.2022 | |
*/ | |
@ScriptManifest( | |
game = Game.RISE_OF_KINGDOMS, | |
name = "Fog Clearing (Explore)", | |
version = 0.0, | |
author = "LSS Bot", | |
timeoutMinutes = 8, | |
description = "<p>Explores the world map and clears the fog.</p>" + | |
"<p><b>Make sure that the scout camp is at it's default spot (position #3 on the layout guide).</b></p>" | |
) | |
public class FogScript extends AbstractScript { | |
private final FogConfig CONFIG = new FogConfig(); | |
private FogTask task; | |
public FogScript(Device device) { | |
super(device); | |
} | |
@Override | |
public void onStart() { | |
task = new FogTask(this, 3); | |
} | |
@Override | |
public int loop() { | |
return task.execute(); | |
} | |
@Override | |
public Config getConfig() { | |
return CONFIG; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.lssbot.scripts.rok.fog; | |
import com.lssbot.core.api.geometry.BRectangle; | |
import com.lssbot.core.api.script.AbstractScript; | |
import com.lssbot.core.api.script.ExitCodes; | |
import com.lssbot.core.api.script.methodprovider.ROKMethodProvider; | |
import com.lssbot.core.api.time.Condition; | |
import com.lssbot.core.framework.executor.rok.building.ROKBuildingLocator; | |
/** | |
* @author Roma on 01.10.2022 | |
*/ | |
public class FogTask extends ROKMethodProvider { | |
private ROKBuildingLocator buildingLocator; | |
private AbstractScript script; | |
private int buildingSlot; | |
private BRectangle cachedButton; | |
public FogTask(AbstractScript script, int buildingSlot) { | |
super(script.getDevice()); | |
this.script = script; | |
this.buildingSlot = buildingSlot; | |
initNewBuildingSolver(); | |
} | |
public int execute() { | |
if (isScoutManagementMenuOpen()) { | |
if (isExploreButtonVisible()) { | |
if (pressCachedButton("Explore", this::isSendMenuOpen)) { | |
pressCachedButton("Send", getViewport()::isOnMap); | |
} | |
} else { | |
device.log("Scout queue is busy or there is no fog left"); | |
getViewport().tryReturnToCityOrMap(1); | |
return ExitCodes.COMPLETED; | |
} | |
} else if (getViewport().isOnMap()) { | |
if (isExploreButtonVisible()) { | |
if (pressCachedButton("Explore", this::isSendMenuOpen)) { | |
pressCachedButton("Send", getViewport()::isOnMap); | |
} | |
} else { | |
buildingLocator.restart(); | |
} | |
} else if (getViewport().isInCity()) { | |
if (isOpenScoutManagementButtonVisible()) { | |
pressCachedButton("Scout", this::isScoutManagementMenuOpen); | |
}else if (buildingLocator.shouldRestart()) { | |
buildingLocator.restart(); | |
} else { | |
device.warn("Building not found in slot " + buildingSlot); | |
return ExitCodes.FAILED; | |
} | |
} | |
return 0; | |
} | |
private boolean pressCachedButton(final String buttonName, final Condition timeoutCondition) { | |
if (cachedButton != null) { | |
device.log("Pressing button " + buttonName); | |
getMouse().click(cachedButton); | |
return sleepUntil(timeoutCondition); | |
} else { | |
device.log("Cached button is null"); | |
} | |
return false; | |
} | |
private boolean isScoutManagementMenuOpen() { | |
return getMenu().isMenuOpen("SCOUT"); | |
} | |
private void initNewBuildingSolver() { | |
if (buildingLocator != null) script.removeExecutor(buildingLocator); | |
script.addExecutor(buildingLocator = new ROKBuildingLocator(script.getDevice(), buildingSlot)); | |
} | |
private boolean isSendMenuOpen() { | |
return (cachedButton = getOpenCV().getAreaMatch(Images.BUTTON_SEND, 0.7)) != null; | |
} | |
private boolean isExploreButtonVisible() { | |
return (cachedButton = getOpenCV().getAreaMatch(Images.BUTTON_EXPLORE, 0.7)) != null; | |
} | |
private boolean isOpenScoutManagementButtonVisible() { | |
return (cachedButton = getOpenCV().getAreaMatch(Images.BUTTON_OPEN_SCOUT_MANAGEMENT, 0.7)) != null; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.lssbot.scripts.rok.fog; | |
import java.io.File; | |
/** | |
* @author Roma on 01.10.2022 | |
*/ | |
public class Images { | |
private static final String PREFIX = "rok" + File.separator + "fog" + File.separator; | |
public static final String BUTTON_EXPLORE = PREFIX + "explore"; | |
public static final String BUTTON_SEND = PREFIX + "send"; | |
public static final String BUTTON_OPEN_SCOUT_MANAGEMENT = PREFIX + "opts"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.lssbot.scripts.rok.fog; | |
import com.lssbot.core.api.script.config.Config; | |
/** | |
* @author Roma on 01.10.2022 | |
*/ | |
public class FogConfig implements Config { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment