Jump to content

Lazy Man MOD - Auto building Upgrade


Recommended Posts

Someone suggested adding a feature to automatically do upgrades.  My 1st thought was why even play CoC if you want robot to do all the work?

Then a few weeks later needed massive amount of loot for max camp upgrade, and want the upgrade to start ASAP.  SO.....

Created a simple MOD that allows manually selecting a building to upgrade and when it gets enough loot and builder is free, it starts the upgrade.  I've used to start 3 upgrades (camp, cannon, archer tower), so have no clue if works for everything?  Its rough, ugly, and barely tested. YMMV

This MOD touches many files and is not for those that do not know basic Autoit editing.  I put all the changes required with instructions here:


;===========================================================
; insert after line 889 in COCBot\CGB GUI Design.au3
; this creates the new button to manually locate 1 bldg to upgrade
;===========================================================
   $btnUpgradeSomething = GUICtrlCreateButton("Building Upgrade", $X, $y + 70, 100, 25)
   GUICtrlSetOnEvent(-1, "btnUpgradeSomething")
;===================================================================
; insert this function in the COCBot\CGB GUI Control.au3 file anywhere, I did it on line 169 in front of the other locate button commands
; this is the code that executes when the button is pushed.
;==================================================================
Func btnUpgradeSomething()
  $RunState = True
 While 1
  ZoomOut()
  LocateUpgrade()
  ExitLoop
 WEnd
 $RunState = False
EndFunc   ;==>btnUpgradeSomething
;=================================================================
; Insert this variable declaration into the COCBot\CGB Global Variables.au3 file at the end.
; this stores the location of the bldg to be upgraded
;================================================================
Global $UpgradePos[2] = [-1, -1]
;================================================================
; Insert this code into main CGB Bot.au3 file @ line 130 in front of idle()
;================================================================
   UpgradeIt($UpgradePos)  ; This calls function to perform upgrade
    If _Sleep(1000) Then Return
    checkMainScreen(False)
    If $Restart = True Then ContinueLoop
;===================================================================
; Insert these 2 function in the COCBot\functions\Village\UpgradeWall.au3 file
;=================================================================
 Func UpgradeIt(Byref $Upgrd)  ;Function to upgrade building
 If $Upgrd[0] < 0 Then ;check to see if upgrade manually selected
  Return False
 Else
  If $FreeBuilder > 0 Then  ;check for free builder
   SetLog("Checking Misc Upgrade", $COLOR_GREEN)
   ; SetLog("-Upgrade location =  " & "(" & $Upgrd[0] & "," & $Upgrd[1] & ")", $COLOR_PURPLE)
   If _Sleep(500) Then Return
   Click($Upgrd[0], $Upgrd[1])  ; click on item to upgrade
   If _Sleep(1000) Then Return
   ; check for upgrade button and return location
   Local $offColors[2][3] = [[0x854833, 35, 33], [0x2B2D1F, 76, 0]] ; 2nd pixel brown hammer, 3th pixel edge of button
   Global $ButtonPixel = _MultiPixelSearch(240, 563, 670, 600, 1, 1, Hex(0xF2F6F5, 6), $offColors, 30) ; first white pixel of button
   If IsArray($ButtonPixel) Then  ; Did we find the button?
    If _Sleep(500) Then Return
    Click($ButtonPixel[0] + 20, $ButtonPixel[1] + 20) ; Click Upgrade Button
    If _Sleep(1000) Then Return
    _CaptureRegion()
    If _ColorCheck(_GetPixelColor(685, 150), Hex(0xE1090E, 6), 20) Then ; Check if the Upgrade window is open
     If _Sleep(500) Then Return
     Click(440, 480)  ;Click upgrade button
     If _Sleep(1000) Then Return
     _CaptureRegion()
     If _ColorCheck(_GetPixelColor(573, 256), Hex(0xE1090E, 6), 20) Then ;Check if the use Gem window opens
      SetLog("Upgrade Fail - No Loot!", $COLOR_RED)
      Click(1, 1) ; click away to close window as we don't want to use gems!
      Return False
     Else
      SetLog("Upgrade complete", $COLOR_GREEN)
      $Upgrd[0] = -1 ;Reset $UpGrade position coordinates to blank to show its completed
      $Upgrd[1] = -1
      Click(1, 1) ; click away to close window
      Return True
     EndIf
    Else
     Setlog("Upgrade Error", $COLOR_RED)  ; In case we cant find upgrade window
     Click(1, 1) ; click away
     Return False
    EndIf
   Else
    Setlog("No Upgrade Available", $COLOR_RED)  ; could not find upgrade button
    Click(1, 1) ; click away
    Return False
   EndIf
  Else
   SetLog("No free builder for Upgrade it", $COLOR_RED)
  EndIf
 EndIf
EndFunc   ;==>UpgradeIt
;
;
;
Func LocateUpgrade()
 Local $MsgBox
 $MsgBox = MsgBox(1 + 262144, "Locate Item to Upgrade", "Click OK then click on your building to upgrade", 0, $frmBot)
 If $MsgBox = 1 Then
  $UpgradePos[0] = FindPos()[0]
  $UpgradePos[1] = FindPos()[1]
  Setlog("Upgrade will not work if Auto Wall Upgrade is used ", $COLOR_RED)
  Setlog("unless mininum value is larger than upgrade cost!", $COLOR_RED)
  SetLog("-Upgrade location =  " & "(" & $UpgradePos[0] & "," & $UpgradePos[1] & ")", $COLOR_GREEN)
 EndIf
 EndFunc   ;==>UpgradeSomething
;==================================================================
; OR you can put the 2 above functions in a newly created file located in functions\Village\UpgradeSomething.au3 and
; then edit COCBot\CGB Functions.au3 and put this declaration at the end
;=================================================================
#include "functions\Village\UpgradeSomething.au3"

Link to post
Share on other sites
  • Replies 33
  • Created
  • Last Reply

Top Posters In This Topic

I hope in feature this upgrading mod will added

Benefits:

Sometimes we upgrade building in 12am - 5 am time. Me sometimes don't sleep yet even i'm sleepy already because i wait to finish the building that i upgrade 12 am - 5am then upgrade another building so there will be no free builder. This mod can help us we can upgrade building continuously.

This will benefit for me i can sleep early without worrying there will be free builder between 12am - 5am.

Link to post
Share on other sites

this is what i do

If you have always have a builder idle for walls upgrade. and you have a upgrade ending around 2am to 5am and probably u will not wake up to do the upgraade.. use ur spare builder to build first. this way no time is wasted and u get to overlap

Link to post
Share on other sites

@1337Echo:

This code is simple 1 building upgrade.

You manually locate the upgrade before starting the bot, and it checks after each attack if the upgrade can be done.

Upgrading more than 1 item is much more complicated. I started to write code to upgrade up to 4 items at a time, but the code got difficult quickly. Needed more GUI changes so your not blind on what happened (not much room left in GUI as it is now), and the error proofing to avoid creating new problems was tricky. Not saying it can't be done, only that it wasn't something I could do in 2-3 hours I was willing to spend to get this feature.

@nhoc_ly:

Everyone has a different idea of which mods are useful? :)

The beauty of open source is you can decide what you want to use.

To be honest, if you are a basic user and not capable of basic code editing, then its best you wait for released versions.

In addition, combining mods requires loads of testing/verification time. I've tried some other MODS posted, such as the Red area deployment MOD and can not get it to work without errors. Plus if I created MOD complication, then folks start wanting support when it has errors, and expect this site to provide support to fix everything. I don't want the main developers wasting time on "why doesn't MOD XXX work". So this is DIY as far as I am concerned.

Clash on!

Link to post
Share on other sites

×
×
  • Create New...