Skip to content

Commit

Permalink
Fix bug + add feature:
Browse files Browse the repository at this point in the history
- fix bug after fix rod: infinity clicking
- add detect rod snapped: if rod time > 2.5s
- click debounce now will work separated on each type of click
- click debound use null as initial time: this make the first clicks will not skipped
- add near rgb detect for enviroment change: when the env change, it will slowly changing the rgb, so we keep detect the change and update the current color and compare with next change. it should be change a little amount (1-2) of rgb
  • Loading branch information
Nam Nguyen committed Sep 7, 2021
1 parent 383dd3f commit 8832e11
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 34 deletions.
52 changes: 31 additions & 21 deletions helper.au3
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ func pick($arrayPos)
return $arrayPos[$rodPosition - 1] * $screenscale
endfunc

func rgb($dec)
local $result = [Floor($dec/65536), Floor(Mod($dec, 65536)/256), Mod($dec, 256)]
return $result
endfunc

func isRGBNear($dec1, $dec2)
local $rgb1 = rgb($dec1)
local $rgb2 = rgb($dec2)
return Abs($rgb1[0]-$rgb2[0]) <= 2 and Abs($rgb1[1]-$rgb2[1]) <= 2 and Abs($rgb1[2]-$rgb2[2]) <= 2
endfunc

;~ $hDC = _WinAPI_GetWindowDC(0) ; DC of entire screen (desktop)
;~ $hPen = _WinAPI_CreatePen($PS_SOLID, 5, 0)
;~ $o_Orig = _WinAPI_SelectObject($hDC, $hPen)
Expand All @@ -98,8 +109,6 @@ endfunc
;~ EndFunc

#region Button clicking
global $timeStartClicked = TimerInit()

global $nox = WinGetHandle('Bộ giả lập android Nox')
if @error <> 0 then
$nox = false
Expand All @@ -114,71 +123,73 @@ func click($x, $y, $clicks = 1, $speed = 100)
sleep($speed)
EndFunc

func clickDebounced($x, $y, $clicks = 1, $speed = 100)
if TimerDiff($timeStartClicked) > $speed then
$timeStartClicked = TimerInit()
local $clickTimer[] = [null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null]

func clickDebounced($id, $x, $y, $clicks = 1, $speed = 100)
if TimerDiff($clickTimer[$id]) >= $speed then
$clickTimer[$id] = TimerInit()
click($x, $y, $clicks, $speed)
endif
EndFunc

func clickUseRod()
clickDebounced($buttonUseRodX, $buttonUseRodY, 1, 200)
clickDebounced(0, $buttonUseRodX, $buttonUseRodY, 1, 200)
EndFunc

func clickWithdrawRod()
clickDebounced($buttonWithdrawRodX, $buttonWithdrawRodY, 10, 10)
clickDebounced(1, $buttonWithdrawRodX, $buttonWithdrawRodY, 10, 10)
EndFunc

func clickOpenBag()
clickDebounced($buttonOpenBagX, $buttonOpenBagY, 1, 0) ;100 trở lên thì sleep vô tận cmnl, wtf?
clickDebounced(2, $buttonOpenBagX, $buttonOpenBagY, 1, 0) ;100 trở lên thì sleep vô tận cmnl, wtf?
EndFunc

func clickTabTool()
clickDebounced($buttonTabTool1X, $buttonTabTool1Y, 1, 200)
clickDebounced(3, $buttonTabTool1X, $buttonTabTool1Y, 1, 200)
EndFunc

func clickCloseBag()
clickDebounced($buttonCloseBag3X, $buttonCloseBag3Y, 1, 200)
clickDebounced(4, $buttonCloseBag3X, $buttonCloseBag3Y, 1, 200)
EndFunc

func clickStoreFish()
clickDebounced($buttonStoreFishX, $buttonStoreFishY, 1, 200)
clickDebounced(5, $buttonStoreFishX, $buttonStoreFishY, 1, 200)
EndFunc

func clickStoreTrash()
clickDebounced($buttonStoreTrashX, $buttonStoreTrashY, 1, 200)
clickDebounced(6, $buttonStoreTrashX, $buttonStoreTrashY, 1, 200)
EndFunc

func clickFixRod()
clickDebounced(pick($buttonFixRodX), pick($buttonFixRodY), 1, 2000)
clickDebounced(7, pick($buttonFixRodX), pick($buttonFixRodY), 1, 1000)
EndFunc

func clickPayMoneyFixRod()
clickDebounced($buttonPayMoneyFixRodX, $buttonPayMoneyFixRodY, 1, 200)
clickDebounced(8, $buttonPayMoneyFixRodX, $buttonPayMoneyFixRodY, 1, 1000)
EndFunc

func clickFixedRod()
clickDebounced($buttonFixedRodX, $buttonFixedRodY, 1, 200)
clickDebounced(9, $buttonFixedRodX, $buttonFixedRodY, 1, 1000)
EndFunc

func clickSelectRod()
clickDebounced(pick($bagItemX), pick($bagItemY), 1, 200)
clickDebounced(10, pick($bagItemX), pick($bagItemY), 1, 200)
EndFunc

func clickCloseMission()
clickDebounced($buttonCloseMissionX, $buttonCloseMissionY, 1, 200)
clickDebounced(11, $buttonCloseMissionX, $buttonCloseMissionY, 1, 200)
endfunc

func clickClosePhone()
clickDebounced($boardPhoneButtonClose1X, $boardPhoneButtonClose1Y, 1, 2000)
clickDebounced(12, $boardPhoneButtonClose1X, $boardPhoneButtonClose1Y, 1, 2000)
endfunc

func clickCloseOtherProfile()
clickDebounced($boardOtherProfileButtonX, $boardOtherProfileButtonY, 1, 2000)
clickDebounced(13, $boardOtherProfileButtonX, $boardOtherProfileButtonY, 1, 2000)
endfunc

func clickCloseShop()
clickDebounced($shopCloseButtonX, $shopCloseButtonY, 1, 2000)
clickDebounced(14, $shopCloseButtonX, $shopCloseButtonY, 1, 2000)
endfunc
#endregion

Expand Down Expand Up @@ -356,7 +367,6 @@ func doBagStuff()
_log('Start doing bag stuff')
LoopOn(isTabToolNotSelected, clickTabTool, 'Clicking tab tool')

_log('Detecting is rod needs fix')
sleep(200)
if isRodNeedFix() Then
_log('Detected rod needs fix')
Expand Down
39 changes: 26 additions & 13 deletions index.au3
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ EndFunc
While True
local $startUsedRodTime
local $beginLoopTime
local $missedRod
local $missedRod = false
local $failUseRodAfterBag = false
local $currentTimeDiff
local $detectedisBagOpened = false
local $detectedisTabToolOpened = false
Expand Down Expand Up @@ -89,20 +90,24 @@ While True
if isBagOpened() then
_log('Detected bag opened')
doBagStuff()
_log('Clicking use rod')
$beginLoopTime = TimerInit()
While isOpenBagButtonShown() and $currentTimeDiff < 5000
LoopOn(isOpenBagButtonShown, clickUseRod, 'Clicking use rod')
if isOpenBagButtonShown() then
$failUseRodAfterBag = true
else
$startUsedRodTime = TimerInit()
clickUseRod()
WEnd
endif
ExitLoop
endif
until $currentTimeDiff >= 5000
else
doBagStuff()
endif
if $failUseRodAfterBag then
_log('End loop, fish failed')
_log('-------- end loop --------')
ContinueLoop
endif

$missedRod = false
_log('Idle rod for ' & $MinimumIdleRod & 's')
do
local $currentTimeDiff = TimerDiff($startUsedRodTime)
Expand All @@ -125,11 +130,13 @@ While True

_log('Detecting exclamimation')
Local $currentColor
$missedRod = false
Do
$currentTimeDiff = TimerDiff($startUsedRodTime)
_log('Detecting exclamimation ' & Round($currentTimeDiff/100)/10 & '/' & $MaximumTimeFishing & 's', false)
$currentColor = getCurrentExclaimationColor()
if isRGBNear($initColor, $currentColor) then
$initColor = $currentColor
endif
if isOpenBagButtonShown() Then
_log('Open bag button found, probably missed fish')
$missedRod = true
Expand All @@ -151,21 +158,27 @@ While True
local $isSuccess = false
Do
if isStoreFishButtonShown() then
_log('Fished successfully')
storeFish()
$isSuccess = true
ExitLoop
Else
if isStoreTrashButtonShown() Then
_log('Fished trash')
storeTrash()
$isSuccess = true
ExitLoop
Else
if isOpenBagButtonShown() Then
_log('Open bag button found, probably color changed wrong or rod snapped')
_log('Initial color: ' & $initColor)
_log('Changed color: ' & $currentColor)

$isSuccess = false
if $initTime < 2500 then
_log('Fish snapped')
$isSuccess = true
else
_log('Open bag button found, probably color changed wrong')
_log('Initial color: ' & $initColor)
_log('Changed color: ' & $currentColor)
$isSuccess = false
endif
ExitLoop
EndIf
EndIf
Expand Down

0 comments on commit 8832e11

Please sign in to comment.