Skip to content

Instantly share code, notes, and snippets.

@noih
Last active September 19, 2022 13:08
Show Gist options
  • Save noih/1a99d6260cd8655046c37c787f51c139 to your computer and use it in GitHub Desktop.
Save noih/1a99d6260cd8655046c37c787f51c139 to your computer and use it in GitHub Desktop.
; Pos1 = Potion NPC
; Pos2 = Item
; Pos3 = Bank
; "Alt + \" => start
; "Pause" => pause
; "Ctrl + r" => reolad
; "Ctrl + t" => commands on end
; "Delete" => exit app
global pickItem := "secret.bmp" ; filename or ""
global money := 2000000 ; how much to prepare the materials
global foodHotKey := "1" ; 1 ~ 5, F1 ~ F8, eat food or skill
; =====================================
#SingleInstance, Force
#NoEnv
SetBatchLines -1
ListLines Off
SendMode Input
SetDefaultMouseSpeed, 2
SetWorkingDir, %A_ScriptDir%
global Role := { x: 401, y: 273 }
global Pos := []
global TimePool := {}
global CommandsOnStart := ["/run", "/nowar", "/nomenu", "/shift on", "/trade off", "/effectoff", "/weather off"]
global CommandsOnEnd := ["/nowar off", "/nomenu off", "/shift off", "/trade on", "/effecton", "/weather on"]
^r::Reload
Pause::Pause, Toggle
Delete::ExitApp
!\::
try {
if (!CheckResolution(800, 600)) {
throw "resolution not match"
}
if (Pos[1] = "" OR Pos[2] = "" OR Pos[3] = "") {
MsgBox, no Pos 1, 2 or 3
throw "no pos"
}
InitWindowsState()
Speak(CommandsOnStart)
Loop {
CheckHungry(foodHotKey, 2000, 4000, Role)
OpenShop(Pos[1])
BuyMaterials(["1211", "1352", "2242"], 10)
CloseShop()
MakeItem(Pos[2], 10)
if (pickItem) {
DetectPick(pickItem)
} else {
Pick()
}
OpenShop(Pos[1])
isOver100M := SellItems()
CloseShop()
if (isOver100M) {
SaveMoney(Pos[3])
TakeMoney(Pos[3])
SaveBond(Pos[3])
}
}
} catch e {
; MsgBox, % e
}
return
^!1::
^!2::
^!3::
MouseGetPos, x, y
idx := SubStr(A_ThisHotkey, 3, 1)
Pos[idx] := { x: x, y: y }
return
^t::
InitWindowsState()
Speak(CommandsOnEnd)
return
LClick(x, y) {
MouseClick, Left, x, y, 1, 0
Sleep, 80
}
RClick(x, y) {
MouseClick, Right, x, y, 1, 0, D,
Sleep, 80
MouseClick, Right, x, y, 1, 0, U,
Sleep, 80
}
KeyPress(key) {
Send, {%key% Down}
Sleep, 80
Send, {%key% Up}
Sleep, 80
}
AlignCenter() {
Loop 2 {
KeyPress("Space")
}
Sleep, 750
}
SetBattle(isBattle) {
Loop, 10 {
PixelGetColor, color, 691, 567
if ((isBattle AND color = 0x000000) OR (!isBattle AND (color = 0x213039 OR color = 0x293845 OR color = 0x293842))) {
break
}
LClick(708, 560)
Sleep, 100
}
}
; ex. UseBelt(1)
UseBelt(index) {
if (RegExMatch(index, "^[1-5]$")) {
Send, {Alt Down}
Send, {%index% Down}
Sleep, 80
Send, {%index% Up}
Send, {Alt Up}
}
}
IsTimeUp(key, duration) {
if (duration = "" OR duration <= 0 OR TimePool[key] = "") {
return TRUE
}
return (GetUnixTimestamp() - TimePool[key]) >= duration
}
UseSkill(key, preMS, postMS, position, mouseKey, duration) {
if (RegExMatch(key, "^F[1-8]$") AND IsTimeUp(key, duration)) {
KeyPress(key)
Sleep, preMS
Loop, 3 {
MouseClick, %mouseKey%, position.x, position.y, 1, 0, D,
Sleep, 80
MouseClick, %mouseKey%, position.x, position.y, 1, 0, U,
Sleep, 80
}
Sleep, postMS
; prevent failed
Loop, 2 {
KeyPress("~")
}
TimePool[key] := GetUnixTimestamp()
}
}
IsHungry() {
PixelGetColor, color, 76, 533
return color != 0x00C7EF
}
CheckHungry(key, preMs = "", postMs = "", position = "") {
if (IsHungry()) {
if (RegExMatch(key, "^F[1-8]$")) {
SetBattle(TRUE)
UseSkill(key, preMs, postMs, position, "Right", "")
} else if (RegExMatch(key, "^[1-5]$")) {
UseBelt(key)
}
}
}
CheckResolution(targetX, targetY) {
if (A_ScreenWidth != targetX OR A_ScreenHeight != targetY) {
KeyPress("Enter")
Sleep, 100
Send, {Text}current resolution: %A_ScreenWidth%x%A_ScreenHeight%, %targetX%x%targetY% required.
return FALSE
}
return TRUE
}
; ! Note: seconds
GetUnixTimestamp() {
NowUTC := A_NowUTC
NowUTC -= 19700101000000, S
return NowUTC
}
InitWindowsState() {
; close window
Loop, 3 {
KeyPress("Escape")
}
AlignCenter()
; release skill
Loop 2 {
RClick(401, 273)
}
}
Speak(contents, shouldESC = TRUE) {
KeyPress("Enter")
for k, v in contents {
Send, {Text}%v%
KeyPress("Enter")
}
if (shouldESC) {
KeyPress("Escape")
}
}
CallBoss(position) {
MouseMove, position.x, position.y, 0
Sleep, 100
Speak(["boss"], FALSE)
MouseMove, 208, 304, 0
Sleep, 700
}
BuyMaterials(items, count) {
if (items.MaxIndex() <= 0 OR count <= 0) {
return FALSE
}
if (!GoBuyPanel()) {
throw "BuyMaterials.GoBuyPanel, failed"
}
GoShopPanelFirstPage()
for k, v in items {
page := SubStr(v, 1, 1)
row := SubStr(v, 2, 1) - 1
col := SubStr(v, 3, 1) - 1
cnt := SubStr(v, 4, 1) * count
if (cnt <= 0) {
continue
}
if (k = 1) {
GoShopPanelRelativePage(1, page)
} else {
prev := SubStr(items[k - 1], 1, 1)
GoShopPanelRelativePage(prev, page)
}
x := 467 + (col * 35)
y := 73 + (row * 35)
LClick(x, y)
Loop, %cnt% {
LClick(469, 292) ; confirm button
Sleep, 80
}
}
LClick(626, 292) ; cancel button
return TRUE
}
GoShopPanelRelativePage(prev, next) {
diff := next - prev
count := Abs(diff)
Loop, %count% {
if (diff < 0) {
LClick(638, 73) ; prev page
} else {
LClick(638, 136) ; next page
}
}
}
SellItems() {
if (!GoSellPanel()) {
throw "SellItems.GoSellPanel"
}
GoShopPanelFirstPage()
Loop, 10 {
SellAPage()
PixelGetColor, color, 467, 73
if (color = 0x293439) { ; empty
break
}
LClick(638, 136) ; next page
Sleep, 80
}
isOver100M := IsOver100Million()
LClick(626, 292) ; cancel button
return isOver100M
}
SellAPage() {
y := 0
Loop, 3 {
x := 0
Loop, 5 {
px := 467 + (x * 35)
py := 73 + (y * 35)
LClick(px, py)
; MouseClick, Left, px, py
; Sleep, 80
LClick(469, 292)
; MouseClick, Left, 469, 292, 1, 0
; Sleep, 80
x := x + 1
}
y := y + 1
}
}
OpenShop(position) {
Loop, 10 {
CallBoss(position)
if (IsShopOpen()) {
return TRUE
}
}
return FALSE
}
CloseShop() {
Loop, 10 {
KeyPress("Escape")
if (!IsShopOpen()) {
return TRUE
}
}
return FALSE
}
IsShopOpen() {
PixelGetColor, color1, 605, 281
PixelGetColor, color2, 516, 281
return color1 = 0x081010 AND color2 = 0x081010
}
RecentSkill() {
Loop, 2 {
Send, {Alt Down}
Send, {/ Down}
Sleep, 80
Send, {/ Up}
Send, {Alt Up}
}
Sleep, 250
MouseClick, Right, 779, 429, 1, 0, D,
Sleep, 80
MouseClick, Right, 779, 429, 1, 0, U,
Sleep, 80
}
GoBuyPanel() {
Loop, 10 {
PixelGetColor, color, 545, 49
if (color = 0x101C21) {
return TRUE
}
LClick(522, 162) ; buy button
}
return FALSE
}
GoSellPanel() {
Loop, 10 {
PixelGetColor, color, 545, 49
if (color = 0x000000) {
return TRUE
}
LClick(601, 162) ; sell button
}
return FALSE
}
GoShopPanelFirstPage() {
Loop, 10 {
PixelGetColor, color, 631, 62
if (color = 0x081018) {
return TRUE
}
LClick(638, 73) ; prev page
}
return FALSE
}
IsMakePanelOpen() {
PixelGetColor, color1, 399, 107
PixelGetColor, color2, 442, 90
return color1 = 0x101C21 AND color2 = 0x080C10
}
OpenMakePanel() {
Loop, 10 {
if (IsMakePanelOpen()) {
return TRUE
}
RecentSkill()
}
return FALSE
}
MakeItem(position, count) {
if (!OpenMakePanel()) {
throw "MakeItem.OpenMakePanel"
}
LClick(position.x, position.y)
if (count >= 10) {
LClick(403, 382) ; max
} else {
Loop, %count% {
LClick(404, 356) ; add
}
}
LClick(324, 369) ; confirm
Sleep, 250
if (IsMakePanelOpen()) {
LClick(479, 371) ; cancel
Sleep, 250
throw "MakeItem.confirm"
}
}
IsBankOpen() {
PixelGetColor, color1, 478, 75
PixelGetColor, color2, 644, 290
return color1 = 0x080808 AND color2 = 0x081418
}
IsSaveMoneyPanel() {
PixelGetColor, color1, 466, 84
PixelGetColor, color2, 556, 54
return color1 = 0x081010 AND color2 = 0x000000
}
IsTakeMoneyPanel() {
PixelGetColor, color1, 466, 84
PixelGetColor, color2, 556, 54
return color1 = 0x081010 AND color2 = 0x5A7D9C
}
IsSaveItemPanel() {
PixelGetColor, color1, 171, 216
PixelGetColor, color2, 364, 216
return color1 = 0x000000 AND color2 = 0x000000
}
SaveMoney(position) {
if (!OpenBank(position)) {
throw "SaveMoney.OpenBank"
}
LClick(566, 104)
Sleep, 200
if (!IsSaveMoneyPanel()) {
throw "SaveMoney.IsSaveMoneyPanel"
}
Send, {Text}9999999999
Sleep, 100
LClick(503, 303) ; confirm
Sleep, 250
if (IsSaveMoneyPanel()) {
LClick(635, 303) ; cancel
}
}
Take1Billion() {
Loop, 5 {
PixelSearch, x, y, 571, 151, 577, 159, 0xCEE3DE, 0, FAST
if (x > 0 AND y > 0) {
Send, {Text}1000000000
Sleep, 100
LClick(503, 303) ; confirm
Sleep, 250
} else {
break
}
}
}
TakeMoney(position) {
if (!OpenBank(position)) {
throw "TakeMoney.OpenBank"
}
LClick(566, 135)
Sleep, 200
if (!IsTakeMoneyPanel()) {
throw "TakeMoney.IsTakeMoneyPanel"
}
Send, {Text}%money%
Sleep, 100
LClick(503, 303) ; confirm
Sleep, 250
Take1Billion()
if (IsTakeMoneyPanel()) {
LClick(635, 303) ; cancel
}
}
SaveBond(position) {
if (!OpenBank(position)) {
throw "SaveBond.OpenBank"
}
LClick(566, 167)
Sleep, 200
if (!IsSaveItemPanel()) {
throw "SaveBond.IsSaveItemPanel"
}
Loop, 3 { ; go first page
LClick(630, 336)
Sleep, 100
}
Loop, 3 { ; page
Loop, 4 { ; find times
MouseMove, 588, 334, 0
Sleep, 80
PixelSearch, x, y, 503, 205, 782, 308, 0x5AC3AD, 0, FAST
if (x > 0 AND y > 0) {
; double click
LClick(x, y)
LClick(x, y)
} else {
break
}
}
LClick(665, 334) ; next page
Sleep, 200
}
LClick(355, 203) ; Done
}
OpenBank(position) {
if (IsBankOpen()) {
return TRUE
}
Loop, 10 {
CallBoss(position)
if (IsBankOpen()) {
return TRUE
}
}
return FALSE
}
IsOver100Million() {
PixelSearch, x, y, 501, 287, 507, 295, 0xCEE3DE, 0, FAST
return x > 0 AND y > 0
}
Pick() {
left := 65
right := 65
top := 55
bottom := 65
x := 400 + right
While (x >= (400 - left)) {
y := 303 - top
While (y <= (303 + bottom)) {
LClick(x, y)
y := y + 15
}
x := x - 8
}
}
DetectPick(path) {
y := 303
While (y >= 248) {
LClick(400, y)
y := y - 8
}
Loop, 12 {
MouseMove, 400, 180, 0
Sleep, 100
ImageSearch, x, y, 317, 230, 483, 400, %path%
if (x > 0 AND y > 0) {
Loop, 2 {
MouseMove, x, y, 0
Sleep, 80
MouseClick, Left, x, y, 1, 0, D
Sleep, 120
MouseClick, Left, x, y, 1, 0, U
Sleep, 80
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment