Last active
April 21, 2020 16:02
-
-
Save loopyd/07eeb99afba497da6d6f1fb5cbae0c37 to your computer and use it in GitHub Desktop.
[ahk] Tatsumaki fishing v0.5 - proper OO structure
This file contains hidden or 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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; PawTask base class | |
class PawTask | |
{ | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; Constructors | |
__Init(commandText, duration, parent) | |
{ | |
this.commandText := commandText | |
this.duration := duration | |
this.flag := False | |
this.ticks := 0 | |
this.tickTimer := 0 | |
if (parent == null) { | |
this.parent := null | |
this.children := [] | |
} else { | |
this.parent := parent | |
} | |
this.runCount := 0 | |
return this | |
} | |
__GC() { | |
this.commandText := null | |
this.duration := 0 | |
this.flag := False | |
this.ticks := 0 | |
this.tickTimer := 0 | |
this.children := null | |
this.parent := null | |
} | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; Properties | |
TotalRuns { | |
get { | |
totalRuns := 0 | |
if (!parent) { | |
for index, element in this.children | |
totalRuns+=(0+element.runCount) | |
return (totalRuns + this.runCount) | |
} else { | |
for index, element in parent.children | |
totalRuns+=(0+element.runCount) | |
return (totalRuns + parent.runCount) | |
} | |
} | |
} | |
ActiveChildren { | |
get { | |
if (!parent) | |
return this["children"].MaxIndex() | |
return 0 | |
} | |
} | |
Remaining { | |
get { | |
return this.__FormatSeconds(round((this.duration-this.tickTimer)/1000)) | |
} | |
} | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; Methods | |
toggle() { | |
this.flag := !this["flag"] | |
; Process children | |
if (this.children.MaxIndex() > 0) { | |
for index, element in this.children { | |
element.toggle() | |
} | |
} | |
} | |
update() { | |
if (this.flag) { | |
ts := (A_TickCount-this.ticks) | |
if (ts < 0) { | |
ts += 86400000 ; correct tick underflow. | |
} | |
this.tickTimer += ts | |
if (this.tickTimer >= this.duration) { | |
this.tickTimer := 0 | |
this.updateFireEvent() | |
this.runCount++ | |
} | |
} else { | |
this.updateIdleEvent() | |
} | |
this.ticks := A_TickCount | |
; process children. | |
if (this.children.MaxIndex() > 0) { | |
for index, element in this.children { | |
element.update() | |
} | |
} | |
this.updateCompletedEvent() | |
} | |
addChild(commandText, duration) { | |
this["children"].Push(new command(commandText, duration, this)) | |
} | |
__FormatSeconds(NumberOfSeconds) { | |
time := 19990101 | |
time += NumberOfSeconds, seconds | |
FormatTime, mmss, %time%, mm:ss | |
return NumberOfSeconds//3600 ":" mmss | |
} | |
} | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; Command PawTask | |
class command extends PawTask | |
{ | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; Constructors | |
__New(commandText, duration, parent) { | |
base.__Init(commandText, duration, parent) | |
this.jobStack := new JobStack(5000) | |
return this | |
} | |
__Delete() { | |
base.__GC() | |
this.Dispose() | |
} | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; Properties | |
uiString { | |
get { | |
if (!parent) { | |
oStr:=this.Remaining . "`t | " . this.commandText . " | " . this.runCount . " runs`n" | |
for index, child in this.children { | |
oStr.=child.Remaining . "`t | " . child.commandText . " | " . child.runCount . " runs`n" | |
} | |
return oStr | |
} | |
} | |
} | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; Methods | |
updateFireEvent() { | |
if (this.parent == null) { | |
this["jobStack"].PushJob(this.commandText) | |
} else { | |
this.parent["jobStack"].PushJob(this.commandText) | |
} | |
} | |
updateIdleEvent() { | |
if (this.parent == null) { | |
this["jobStack"].flag := False | |
this["jobStack"].FlushJobs() | |
} | |
} | |
updateCompletedEvent() { | |
; process jobs | |
if (this.parent == null && this.flag) { | |
this["jobStack"].update() | |
} | |
} | |
} | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; JobStack PawTask | |
class JobStack extends PawTask { | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; Constructors | |
__New(duration) { | |
base.__Init(null, duration, null) | |
this.jobStack := {} | |
return this | |
} | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; Properties | |
NumJobs { | |
get { | |
if (this["jobStack"].MaxIndex()) { | |
return this["jobStack"].MaxIndex() | |
} else { | |
return 0 | |
} | |
} | |
} | |
NextData { | |
get { | |
if (this["jobStack"].MaxIndex() > 0) { | |
return this.jobStack[1] | |
} else { | |
return "listening." | |
} | |
} | |
} | |
uiString { | |
get { | |
return "Jobs: " . this.NumJobs . " | " . this.Remaining . " | " . this.NextData . " | " . this.runCount . " runs" | |
} | |
} | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; Methods | |
PushJob(jobData) { | |
this["jobStack"].InsertAt(1, jobData) | |
} | |
PopJob() { | |
if (this["jobStack"].MaxIndex() > 0) { | |
this.FireJob(this.jobStack[1]) | |
this["jobStack"].RemoveAt(1) | |
} | |
} | |
FlushJobs() { | |
if (this["jobStack"].MaxIndex() > 0) { | |
this["jobStack"].Delete(this["jobStack"].MinIndex(), this["jobStack"].MaxIndex()) | |
} | |
} | |
FireJob(jobData) { | |
SendRaw, %jobData% | |
Send, {enter} | |
} | |
updateFireEvent() { | |
this.PopJob() | |
} | |
updateIdleEvent() { | |
this.flag := False | |
} | |
updateCompletedEvent() { | |
if (0+this["jobStack"].MaxIndex() > 0) { | |
this.flag := True | |
} else { | |
this.flag := False | |
} | |
} | |
} | |
#Persistent | |
Thread, interrupt, 0 | |
; time intervals, don't mess with these. | |
second := 1000 | |
minute := second * 60 | |
hour := minute * 60 | |
day := hour * 24 | |
; tunables | |
userMention := "@HeavyPaws" ; put your user mention here. | |
tatusFishBase := second * 32 ; wait 32 seconds before the next fish. | |
tatsuFlushBase := tatusFishBase * 30 ; sell after the player has gathered 30 fish. | |
tatsuRepBase := day + (minute * 10) ; wait 1 day and 10 minutes before repping. | |
; if you want repping to work use an alt to rep your mains. | |
tatsuCookieBase := day + (minute * 5) ; wait 1 day and 5 minutes before giving cookies. | |
; if you want cookies to work use an alt to gift your mains. | |
fishCommand := new command("t!fish", tatusFishBase, null) | |
fishCommand.addChild("t!fish sell common", tatsuFlushBase) | |
fishCommand.addChild("t!fish sell uncommon", tatsuFlushBase + second) | |
fishCommand.addChild("t!fish sell garbage", tatsuFlushBase + (second * 2)) | |
fishCommand.addChild("t!rep " . userMention, tatsuRepBase) | |
fishCommand.addChild("t!cookie " . userMention, tatsuCookieBase) | |
SetTimer, timerThread, 1000 | |
SetTimer, tipThread, 100 | |
return | |
Numpad1:: | |
lastFlag:=fishCommand.flag | |
fishCommand.toggle() | |
if (fishCommand.flag == True && lastFlag == False) { | |
SetTimer, tipThread, 1000 | |
} | |
else if (fishCommand.flag == False && lastFlag == True) { | |
SetTimer, tipThread, 100 | |
} | |
return | |
timerThread: | |
fishCommand.update() | |
return | |
tipThread: | |
result := tipUpdate(fishCommand) | |
ToolTip % result | |
return | |
tipUpdate(Command) { | |
if (Command.flag) { | |
oStr:="Running`n`n" . Command.uiString . Command["jobStack"].uiString | |
return oStr | |
} | |
return "Stopped. Press Numpad 1 to start." | |
} | |
RemoveToolTip: | |
ToolTip | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment