Created
April 6, 2012 14:44
-
-
Save xcvd/2320487 to your computer and use it in GitHub Desktop.
Gatestone Creator
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
/* )............( / | |
/ / ___/| \ / | |
/ | /o \/| | / | |
/ | \_____/\| | / | |
/ \ -xcvd- / / | |
/ ')__________(' */ | |
import java.awt._ | |
import java.net.URL | |
import javax.imageio.ImageIO | |
import org.powerbot.concurrent.strategy.Strategy | |
import org.powerbot.concurrent.Task | |
import org.powerbot.game.api.methods.interactive.Players | |
import org.powerbot.game.api.methods.node.{Locations} | |
import org.powerbot.game.api.methods.tab.{Skills, Inventory} | |
import org.powerbot.game.api.methods.widget.Camera | |
import org.powerbot.game.api.methods.{Tabs, Widgets, Walking} | |
import org.powerbot.game.api.util.{Time} | |
import org.powerbot.game.api.wrappers.Tile | |
import org.powerbot.game.api.{ActiveScript, Manifest} | |
import org.powerbot.game.bot.event.listener.PaintListener | |
@Manifest(name = "Gate Stone Creator", | |
description = "Creates gatestone teleports in Daemonheim for free magic xp.", | |
authors = Array("xcvd"), | |
version = 1.0d) | |
class GateStoneCreator extends ActiveScript with PaintListener { | |
val itemIdRingOfKinship = 15707 | |
val itemIdBoundCosmicRune = 16100 | |
val itemIdGatestone = 17489 | |
val paintBackground = ImageIO.read(new URL("http://localhostr.com/file/VT6xLdx/GatestoneCreator.png")) | |
val georgia = new Font("Georgia", Font.PLAIN, 14) | |
val startTime = System.currentTimeMillis() | |
var xp = 0.0 | |
lazy val startLevel = Skills.getLevel(Skills.MAGIC) | |
def locationEnterDungeon = Locations.getNearest(48496) | |
def locationBrokenStairs = Locations.getNearest(50552) | |
def locationLeaveDungeon = Locations.getNearest(51156) | |
def selectFloorConfirm = Widgets.get(947).getChild(762) | |
def selectFloorOne = Widgets.get(947).getChild(631) | |
def selectComplexityConfirm = Widgets.get(938).getChild(38) | |
def oneOptionDialogContinue = Widgets.get(1186).getChild(8) | |
def oneOptionDialogTwoContinue = Widgets.get(1189).getChild(11) | |
def twoOptionDialogFirst = Widgets.get(1188).getChild(3) | |
def twoOptionDialogSecond = Widgets.get(1188).getChild(11) | |
def inventoryTab = Widgets.get(548).getChild(93) | |
def magicTab = Widgets.get(548).getChild(96) | |
def magicSpellbookCreateGatestone = Widgets.get(950).getChild(38) | |
def timeNow = System.currentTimeMillis() | |
def xpPerHour = ((xp / (timeNow-startTime).toDouble) * 3600000).toInt | |
def playerX = Players.getLocal.getPosition.getX | |
def playerY = Players.getLocal.getPosition.getY | |
def inDungeon = | |
!(playerX < 3456 && playerX > 3441 && playerY < 3730 && playerY > 3709) | |
/** | |
* Waits while a condition is true, with a specified timeout. | |
* | |
* @param condition the method to be evaluated in order to discover if the condition | |
* still holds true | |
* @param timeout the time in milliseconds until the wait times out | |
* @return whether the true if the condition was falisified within the time limit, | |
* otherwise returns false. | |
*/ | |
def waitWhile(condition: () => Boolean, timeout: Int): Boolean = { | |
for (i <- 0 to timeout/50 if condition()) { | |
Time.sleep(50) | |
if (i == timeout/50) { return false } | |
} | |
true | |
} | |
/** | |
* Waits until a condition is true, with a specified timeout. | |
* | |
* @param condition the method to be evaluated in order to discover if the condition | |
* is true | |
* @param timeout the time in milliseconds until the wait times out | |
* @return whether the true if the condition was falisified within the time limit, | |
* otherwise returns false. | |
*/ | |
def waitUntil(condition: () => Boolean, timeout: Int): Boolean = { | |
for (i <- 0 to timeout/50 if !condition()) { | |
Time.sleep(50) | |
if (i == timeout/50) { return false } | |
} | |
true | |
} | |
def cosmicRuneCount: Int = { | |
Inventory.getItems.foreach (item => | |
if (item.getId == itemIdBoundCosmicRune) { return item.getStackSize }) | |
-1 | |
} | |
/** Setup the Gatestone Creator script and provide all strategies */ | |
override def setup() { | |
log.info("Welcome to xcvd's Gatestone Creator!"); | |
provide(new EnterDungeon) | |
provide(new DungeonOptions) | |
provide(new CreateGatestone) | |
provide(new DropGatestone) | |
provide(new LeaveDungeon) | |
provide(new JumpStairs) | |
} | |
class EnterDungeon extends Strategy with Task { | |
override def validate() = !inDungeon && !selectFloorConfirm.isOnScreen && Players.getLocal.getPlane == 0 | |
override def run() { | |
if (playerX != 3454 && playerY != 3725) { | |
require (Walking.walk(new Tile(3445, 3724, 0)), { | |
log.info("Could not walk to dungeon entrance") | |
return | |
}) | |
waitWhile(Players.getLocal.isMoving, 5000) | |
} | |
require (locationEnterDungeon.interact("Climb-down", "Dungeon Entrance"), { | |
log.info("Could not interact with the dungeon entrance") | |
return | |
}) | |
require (waitUntil(oneOptionDialogContinue.isOnScreen, 4000), { | |
log.info("Dialog did not appear, perhaps party is already formed") | |
return | |
}) | |
require (oneOptionDialogContinue.interact("Continue"), { | |
log.info("Could not interact with dialog to continue") | |
return | |
}) | |
require (waitUntil(twoOptionDialogFirst.isOnScreen, 2500), { | |
log.info("'Would you like to start a party' did not appear") | |
return | |
}) | |
require (twoOptionDialogFirst.interact("Continue"), { | |
log.info("Could not interact with dialog to start a party") | |
return | |
}) | |
waitWhile(twoOptionDialogFirst.isOnScreen, 3500) | |
require (locationEnterDungeon.interact("Climb-down", "Dungeon Entrance"), { | |
log.info("Could not interact with the dungeon entrance") | |
return | |
}) | |
waitUntil(selectFloorConfirm.isOnScreen, 2500) | |
} | |
} | |
class DungeonOptions extends Strategy with Task { | |
override def validate() = selectFloorConfirm.isOnScreen | |
override def run() { | |
require (selectFloorOne.interact("Select-floor"), { | |
log.info("Could not interact to select floor") | |
return | |
}) | |
require (selectFloorConfirm.interact("Confirm"), { | |
log.info("Could not interact to confirm floor") | |
return | |
}) | |
waitUntil(selectComplexityConfirm.isOnScreen, 2500) | |
require (selectComplexityConfirm.interact("Confirm"), { | |
log.info("Could not interact to confirm complexity") | |
return | |
}) | |
waitUntil(twoOptionDialogFirst.isOnScreen, 4000) | |
require (twoOptionDialogFirst.interact("Continue"), { | |
log.info("Could not select small dungeon size") | |
return | |
}) | |
waitWhile(twoOptionDialogFirst.isOnScreen, 2500) | |
waitUntil(() => Inventory.getCount(itemIdBoundCosmicRune) == 0, 4000) | |
} | |
} | |
class CreateGatestone extends Strategy with Task { | |
override def validate() = cosmicRuneCount > 2 && Inventory.getCount(itemIdGatestone) == 0 | |
override def run() { | |
require (magicTab.interact("Magic Spellbook"), { | |
log.info("Could not interact with magic spellbook tab") | |
return | |
}) | |
require (waitUntil(() => Tabs.getCurrent == Tabs.MAGIC, 2000), { | |
log.info("Tab did not change to magic spellbook tab") | |
return | |
}) | |
require (magicSpellbookCreateGatestone.interact("Quick-cast", "Create Gatestone"), { | |
log.info("Could not interact with create gatestone spell") | |
return | |
}) | |
xp += 43.5 | |
require (inventoryTab.interact("Inventory"), { | |
log.info("Could not interact inventory tab") | |
return | |
}) | |
waitUntil(() => Tabs.getCurrent == Tabs.INVENTORY, 2000) | |
waitWhile(() => Inventory.getCount(itemIdGatestone) == 0, 2000) | |
} | |
} | |
class DropGatestone extends Strategy with Task { | |
override def validate() = Inventory.getCount(itemIdGatestone) == 1 | |
override def run() { | |
for(item <- Inventory.getItems) { | |
if (item.getId == itemIdGatestone) { | |
require (item.getWidgetChild.interact("Drop", "Gatestone"), { | |
log.info("Could not drop gatestone") | |
return | |
}) | |
waitWhile(() => Inventory.getCount(itemIdGatestone) == 1, 1500) | |
return | |
} | |
} | |
} | |
} | |
class LeaveDungeon extends Strategy with Task { | |
override def validate() = cosmicRuneCount < 3 && inDungeon && cosmicRuneCount != -1 | |
override def run() { | |
require(Walking.walk(locationLeaveDungeon.getPosition), { | |
log.info("Could not walk to leave dungeon location.") | |
return | |
}) | |
waitWhile(Players.getLocal.isMoving, 8000) | |
require(locationLeaveDungeon.interact("Climb-up", "Dungeon exit"), { | |
log.info("Could not interact with Dungeon exit.") | |
return | |
}) | |
require(waitUntil(oneOptionDialogContinue.isOnScreen, 2000), { | |
log.info("Dialog to leave dungeon did not appear on screen") | |
return | |
}) | |
require(oneOptionDialogContinue.interact("Continue"), { | |
log.info("Could not interact with continue button") | |
return | |
}) | |
require(waitUntil(twoOptionDialogFirst.isOnScreen, 2000), { | |
log.info("Could not continue dialog") | |
return | |
}) | |
require(twoOptionDialogFirst.interact("Continue"), { | |
log.info("Could not interact with confirm dialog") | |
return | |
}) | |
waitWhile(() => Players.getLocal.getPlane == 0, 4000) | |
} | |
} | |
class JumpStairs extends Strategy with Task { | |
override def validate() = Players.getLocal.getPlane == 1 | |
override def run() { | |
Walking.walk(locationBrokenStairs.getPosition) | |
Camera.setAngle(30) | |
waitWhile(Players.getLocal.isMoving, 5000) | |
require (locationBrokenStairs.interact("Jump-down", "Broken-stairs"), { | |
log.info("Could not interact to jump-down broken-stairs") | |
return | |
}) | |
waitWhile(() => Players.getLocal.getPlane == 1, 3000) | |
} | |
} | |
/** | |
* Overrides client surface repaint | |
* | |
* @param render graphics instance to render | |
*/ | |
override def onRepaint(render: Graphics) { | |
var g2 = render.asInstanceOf[Graphics2D] | |
g2.drawImage(paintBackground, 547, 355, null) | |
g2.setFont(georgia) | |
g2.setColor(Color.LIGHT_GRAY) | |
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB) | |
g2.drawString(xp.toInt.toString, 593, 428) | |
g2.drawString(xpPerHour.toString, 649, 441) | |
g2.drawString((Skills.getLevel(Skills.MAGIC) - startLevel).toString, 702, 454) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment