Inside the main loop...
Code:
Public Sub StartBotting()
''todo: better FSM here? or whatever logic control structure you choose. Custom Scripting language?! //todo
_isBotOn = True
Dim _timeLapse As New TimeSpan
GOOEY.FocusWoW()
Do Until _isBotOn = False
''Priority #0. If we're dead, we can't do anything..
If OBJMGR.LocalPlayer.Health = 0 Then
DoOutput("LocalPlayer DIED!")
_isBotOn = False
Form1.cmdBotOnOff.Text = "STOP"
Exit Do
End If
''Priority #1. If master is dead, we can't do anything. logout. //todo: rez
If OBJMGR.MasterPlayer.Health = 0 Then 'master is dead. wtf :(
DoOutput("MAINCHAR IS DEAD" & Environment.NewLine & "SHUTTING OFF")
_isBotOn = False
Form1.cmdBotOnOff.Text = "START"
Exit Do
End If
''Priority #2. Self Defense.
If OBJMGR.GetTargetCount(OBJMGR.LocalPlayer) > 0 Then
DoOutput("something is targeting me? wth?")
If OBJMGR.LocalPlayer.HealthAsPercent < 98 Then
DoOutput("i'm hurt. Being Attacked?!")
''wow will auto-target an attacker. wait a second for that that to happen. (Subject to Change?)**
'wait for auto-target
Dim _timeoutLapse As TimeSpan
Dim _starTime As Date = Date.Now
Do Until OBJMGR.LocalPlayer.TargetGuid > 0
_timeoutLapse = Date.Now.Subtract(_starTime)
If _timeLapse.TotalSeconds >= 5 Then
'nothing is attacking us?
DoOutput("auto-target fail?" & Environment.NewLine & "blacklist mob? //todo" & Environment.NewLine & "about to die??")
Threading.Thread.Sleep(1000)
End If
Loop
If OBJMGR.LocalPlayer.TargetGuid > 0 Then
'we have a target. Kill it!
Dim _curTarget As New wowObjMgrUnitObject
_curTarget.BaseAddress = OBJMGR.GetObjectBaseFromGuid(OBJMGR.LocalPlayer.TargetGuid)
Do Until _curTarget.Health = 0
If OBJMGR.LocalPlayer.TargetGuid <> _curTarget.GUID Then
''Target switch. it Happens.
DoOutput("Target switch!")
If _curTarget.Health = 0 Then
DoOutput("Is Ok. Old Target dead")
Else
DoOutput("Old target still alive. wth?") ''shouldn't happen
End If
'update _curTarget?
If OBJMGR.LocalPlayer.TargetGuid > 0 Then
'auto acquired a new target (group attack on LocalPlayer?)
DoOutput("Group Attack?")
_curTarget.BaseAddress = OBJMGR.GetObjectBaseFromGuid(OBJMGR.LocalPlayer.TargetGuid)
Else
'race condition where we read .Health value > 0, but wow.exe sets instantly Target.Health=0, LocalPlayer.TargetGuid = 0
'killed target
Exit Do
End If
End If
'spam 1 attack spell :(
If SelfDefenseSpell.CooldownRemaining = 0 Then
SelfDefenseSpell.CastThisSpell()
End If
DoOutput("..in combat")
Threading.Thread.Sleep(_rndm.Next(1000, 1500))
Loop
DoOutput("Target Killed!!!")
End If
End If
End If
''Priority #3. Face the MainChar
If OBJMGR.MasterPlayer.WorldPos.RelativeTurnDistance > 1.5 Then
GPS.TurnToPoint(OBJMGR.MasterPlayer.WorldPos)
End If
''Priority #4. Within FollowDistance to MainChar
If OBJMGR.MasterPlayer.WorldPos.DistanceFromLocalPlayer > FollowDistance Then
'DoOutput("getting closer")
Dim _rcd As Int32 = _rndm.Next(_followDistance - 2, _followDistance + 4)
Do Until OBJMGR.MasterPlayer.WorldPos.DistanceFromLocalPlayer <= _rcd
If GPS.IsRunningForward = False Then GPS.StartRunningForward()
If OBJMGR.MasterPlayer.WorldPos.RelativeTurnDistance > 0.15 Then
GPS.TurnToPoint(OBJMGR.MasterPlayer.WorldPos)
End If
Loop
If GPS.IsRunningForward Then GPS.StopRunningForward()
Else
If GPS.IsRunningForward Then
GPS.StopRunningForward()
End If
End If
''Priority #5 Is MainChar Curent Target?
If OBJMGR.LocalPlayer.TargetGuid <> modPublic.MastersGUID Then
DoOutput("Need to target MainChar")
If GOOEY.TargetMaster() Then
DoOutput("Success")
Else
DoOutput("Fail") 'continue as normal. //todo: better efforts
End If
End If
''Priority #6. Cast HealthSpell2 'more powerful
If OBJMGR.LocalPlayer.HealthAsPercent <= HealPercent2 Then
If HealSpell2.CooldownRemaining = 0 Then
DoOutput("MainChar needs large heal")
HealSpell2.CastThisSpell()
End If
End If
''Priority #7. Cast HealthSpell1 'only restores minor hp
If OBJMGR.MasterPlayer.HealthAsPercent <= HealPercent1 Then
If HealSpell1.CooldownRemaining = 0 Then
DoOutput("MainChar needs small heal")
HealSpell1.CastThisSpell()
End If
End If
Application.DoEvents()
Loop
DoOutput("BOT OFF")
End Sub
edit: never actually tested the 'self defense' code because my main kept the aggro -- only tested for about 5-10 minutes.
wowObjMgr.GetTargetCount() -- noticed it always returns 0, probably because of how I found the offset for TargetGuid ->via local player, and not via a unit type.
//tmrRadar_Tick --> lblWhatever.text = OBJMGR.GetTargetCount(OBJMGR.LocalPlayer)
// i removed the label right before posting due to GetTargetCount 'error'.