Skip to content

Commit

Permalink
Version 0.7.6
Browse files Browse the repository at this point in the history
* Added "click" to menu Grammar
* Fixed crash related to Hero Powers
* Fixed cards not generating Grammar properly
  • Loading branch information
topher-au committed Aug 28, 2015
1 parent 4c8af2a commit 81047a3
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 20 deletions.
1 change: 1 addition & 0 deletions HDT-Voice/HDT-Voice.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="HDTVoice\HDTGrammarEngine.vb" />
<Compile Include="HDTVoice\HDTMinionOverlay.vb" />
<Compile Include="HDTVoice\HDTMouse.vb" />
<Compile Include="HDTPlugin\configMain.xaml.vb">
<DependentUpon>configMain.xaml</DependentUpon>
Expand Down
2 changes: 1 addition & 1 deletion HDT-Voice/HDTPlugin/HDTVoicePlugin.vb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Public Class HDTVoicePlugin

'Some code is based on code found in HDT Compatibility Window

Public Shared PluginVersion As New Version(0, 7, 5)
Public Shared PluginVersion As New Version(0, 7, 6)

Private createdSettings, createdUpdateNews As Boolean
Private configRecog As configRecog
Expand Down
35 changes: 26 additions & 9 deletions HDT-Voice/HDTVoice/HDTGrammarEngine.vb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Imports System.Speech.Recognition
Imports Hearthstone_Deck_Tracker
Imports Hearthstone_Deck_Tracker.Hearthstone
Imports Hearthstone_Deck_Tracker.API
Imports Hearthstone_Deck_Tracker.Enums
Imports Hearthstone_Deck_Tracker.Hearthstone
Imports Hearthstone_Deck_Tracker.Hearthstone.Entities
Public Class GrammarEngine

Expand Down Expand Up @@ -199,10 +199,13 @@ Public Class GrammarEngine
heroChoice.Add(New SemanticResultValue(heroPowerName, "hero"))
Return New GrammarBuilder(heroChoice)
Else
Return Nothing
Return New GrammarBuilder(heroChoice)
End If
End Function ' Retrieves the active hero power and generates Grammar

Public Sub New()
GameEvents.OnGameStart.Add(New Action(AddressOf StartNewGame))
StartNewGame()
End Sub
Public ReadOnly Property MenuGrammar As Grammar
Get
Dim menuChoices As New Choices
Expand Down Expand Up @@ -254,7 +257,7 @@ Public Class GrammarEngine
menuChoices.Add(New SemanticResultKey("menu", "done"))

menuChoices.Add(New SemanticResultKey("menu", "quest log"))

menuChoices.Add(New SemanticResultKey("menu", "click"))
menuChoices.Add(New SemanticResultKey("menu", "cancel"))
menuChoices.Add(New SemanticResultKey("menu", "back"))

Expand Down Expand Up @@ -287,6 +290,9 @@ Public Class GrammarEngine
End Property ' Builds the Grammar used during mulligan
Public ReadOnly Property GameGrammar As Grammar
Get
If friendlyID = 0 Then
StartNewGame()
End If
myHand = FriendlyHandGrammar()
friendlyTargets = FriendlyTargetGrammar()
opposingTargets = OpposingTargetGrammar()
Expand All @@ -312,6 +318,8 @@ Public Class GrammarEngine
finalChoice.Add(DebuggerGameCommands)
End If

Debug.WriteLine(finalChoice.ToGrammarBuilder.DebugShowPhrases)

Return New Grammar(finalChoice)
End Get
End Property ' Runs all of the Grammar functions below and returns a single GrammarBuilder
Expand Down Expand Up @@ -431,7 +439,6 @@ Public Class GrammarEngine

Dim targetCard As New GrammarBuilder
targetCard.Append(New SemanticResultKey("action", "target"))
targetCard.Append("card")
targetCard.Append(myHand)
targetChoices.Add(targetCard)

Expand Down Expand Up @@ -488,7 +495,7 @@ Public Class GrammarEngine
Return New GrammarBuilder(debugChoices)
End Function ' Debugger only commands

Public Sub StartNewGame()
Private Sub StartNewGame()
friendlyID = Nothing
opposingID = Nothing

Expand Down Expand Up @@ -587,19 +594,29 @@ Public Class GrammarEngine
Private ReadOnly Property Entities As Entity()
Get
' Clone entities from game and return as array
Return Helper.DeepClone(Core.Game.Entities).Values.ToArray
Dim EntArray = Helper.DeepClone(Core.Game.Entities).Values.ToArray
Return EntArray
End Get
End Property ' Clones Entites from HDT and creates an array
Private ReadOnly Property PlayerEntity As Entity
Get
' Return the Entity representing the player
Return Entities.FirstOrDefault(Function(x) x.IsPlayer())
Try
Return Entities.First(Function(x) x.IsPlayer())
Catch ex As Exception
Return Nothing
End Try
End Get
End Property ' Gets the player's current Entity
Private ReadOnly Property OpponentEntity As Entity
Get
' Return the Entity representing the player
Return Entities.FirstOrDefault(Function(x) x.IsOpponent())
Try
Return Entities.First(Function(x) x.IsOpponent())
Catch ex As Exception
Return Nothing
End Try

End Get
End Property ' Gets the opponent's current Entity
Private Function EntityKey(Type As GrammarEntityType, Key As Integer) As String
Expand Down
182 changes: 182 additions & 0 deletions HDT-Voice/HDTVoice/HDTMinionOverlay.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
Imports Hearthstone_Deck_Tracker
Imports Hearthstone_Deck_Tracker.API
Imports Hearthstone_Deck_Tracker.Enums
Imports Hearthstone_Deck_Tracker.Hearthstone.Entities
Imports System.Windows.Controls
Imports System.Threading
Imports System.Threading.Thread
Imports System.Windows.Threading
Imports System.ComponentModel

Public Class HDTMinionOverlay
Public friendlyID As Integer = 0
Public opposingID As Integer = 0
Private workerOverlay As BackgroundWorker
Private canvasHDT As Canvas
Public Sub New()
StartNewGame()
canvasHDT = Core.OverlayCanvas

workerOverlay = New BackgroundWorker
workerOverlay.WorkerSupportsCancellation = True
'AddHandler workerOverlay.DoWork, AddressOf workerOverlay_DoWork

GameEvents.OnGameStart.Add(New Action(AddressOf StartNewGame))
GameEvents.OnGameEnd.Add(New Action(AddressOf EndGame))
'workerOverlay.RunWorkerAsync()

'Dim overlayThread As New Thread(New ThreadStart(Sub()
'workerOverlay_DoWork()
'End Sub))
'overlayThread.SetApartmentState(Threading.ApartmentState.STA)
'overlayThread.Start()

End Sub
Public Sub Unload()
If Not IsNothing(workerOverlay) Then
workerOverlay.CancelAsync()
End If
End Sub

Private Sub workerOverlay_DoWork()

Dim canvasMinions As New Canvas
canvasMinions = New Canvas
Canvas.SetTop(canvasMinions, 200)
Canvas.SetLeft(canvasMinions, 200)
canvasHDT.Dispatcher.Invoke(Sub(cm)
canvasHDT.Children.Add(cm)
End Sub, canvasMinions)
Do
Sleep(200)

' If there is no current game in progress
If friendlyID = 0 Then
StartNewGame()
Continue Do
End If


' Clear all existing minions from overlay
Do
For Each child In canvasMinions.Children
canvasHDT.Children.Remove(child)
Continue Do
Next
Exit Do
Loop


Dim Friendlys = GetFriendlyMinions()

If Friendlys.Count = 0 Then _
Continue Do

Dim minionBlocks As New List(Of HearthstoneTextBlock)
For Each e In Friendlys
Dim fBlock As New HearthstoneTextBlock
fBlock.Text = e.Card.Name
minionBlocks.Add(fBlock)
Next

Dim UISize = HDTVoice.Mouse.HSUISize

Dim minionWidth As Integer = UISize.Width * 0.09
canvasMinions.Width = minionWidth * (minionBlocks.Count + 1)

For Each m In minionBlocks
Dim intMinNum As Integer = minionBlocks.IndexOf(m)
Dim min = m
Canvas.SetTop(min, 0)
Canvas.SetLeft(min, minionWidth * intMinNum)
canvasMinions.Children.Add(min)
Next



Loop While workerOverlay.CancellationPending = False
End Sub

Private Sub StartNewGame()
friendlyID = Nothing
opposingID = Nothing

If Not IsNothing(PlayerEntity) And Not IsNothing(OpponentEntity) Then
friendlyID = PlayerEntity.GetTag(GAME_TAG.CONTROLLER)
opposingID = OpponentEntity.GetTag(GAME_TAG.CONTROLLER)
End If
End Sub ' Re-initalizes controller IDs
Private Sub EndGame()
friendlyID = 0
opposingID = 0
workerOverlay.CancelAsync()
Do While workerOverlay.IsBusy
Sleep(10)
Loop
workerOverlay.Dispose()
End Sub
Private Function GetCardsInHand() As List(Of Entity)
Dim CardsInHand As New List(Of Entity)

For Each e In Entities
If e.IsInHand And e.GetTag(GAME_TAG.CONTROLLER) = friendlyID Then
' If entity is in player hand then add to list
CardsInHand.Add(e)
End If
Next

CardsInHand.Sort(Function(e1 As Entity, e2 As Entity)
Return e1.GetTag(GAME_TAG.ZONE_POSITION).CompareTo(e2.GetTag(GAME_TAG.ZONE_POSITION))
End Function)

Return CardsInHand
End Function ' Returns an ordered list of the current cards in hand
Private Function GetFriendlyMinions() As List(Of Entity)
Dim FriendlyMinions As New List(Of Entity)

For Each e In Entities
If e.IsInPlay And e.IsMinion And e.IsControlledBy(friendlyID) Then
FriendlyMinions.Add(e)
End If
Next

FriendlyMinions.Sort(Function(e1 As Entity, e2 As Entity)
Return e1.GetTag(GAME_TAG.ZONE_POSITION).CompareTo(e2.GetTag(GAME_TAG.ZONE_POSITION))
End Function)

Return FriendlyMinions
End Function ' Returns an ordered list of the current friendly minions
Private Function GetOpposingMinions() As List(Of Entity)
Dim OpposingMinions As New List(Of Entity)

For Each e In Entities
If e.IsInPlay And e.IsMinion And e.IsControlledBy(opposingID) Then
OpposingMinions.Add(e)
End If
Next

OpposingMinions.Sort(Function(e1 As Entity, e2 As Entity)
Return e1.GetTag(GAME_TAG.ZONE_POSITION).CompareTo(e2.GetTag(GAME_TAG.ZONE_POSITION))
End Function)

Return OpposingMinions
End Function ' Returns an ordered list of the current opposing minions
Private ReadOnly Property Entities As Entity()
Get
' Clone entities from game and return as array
Return Helper.DeepClone(Core.Game.Entities).Values.ToArray
End Get
End Property ' Clones Entites from HDT and creates an array
Private ReadOnly Property PlayerEntity As Entity
Get
' Return the Entity representing the player
Return Entities.FirstOrDefault(Function(x) x.IsPlayer())
End Get
End Property ' Gets the player's current Entity
Private ReadOnly Property OpponentEntity As Entity
Get
' Return the Entity representing the player
Return Entities.FirstOrDefault(Function(x) x.IsOpponent())
End Get
End Property ' Gets the opponent's current Entity
End Class
15 changes: 15 additions & 0 deletions HDT-Voice/HDTVoice/HDTMouse.vb
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,19 @@ Public Class Mouse

Sleep(100)
End Sub
Public ReadOnly Property HSUISize As Size
Get
Dim hWndHS As IntPtr = FindWindow(Nothing, "Hearthstone")
Dim rectHS As RECT
GetWindowRect(hWndHS, rectHS)

Dim windowWidth = rectHS.Right - rectHS.Left
Dim uiHeight = rectHS.Bottom - rectHS.Top
Dim uiWidth = ((uiHeight) / 3) * 4 ' A 4:3 square in the center

Dim UISize As New Size(uiWidth, uiHeight)
Return UISize
End Get
End Property
End Class

Loading

0 comments on commit 81047a3

Please sign in to comment.