Attribute VB_Name = "ItemModule"
Option Explicit
Private Type item
    ItemName As String
    itemPrice As Long
    ItemDesc As String
    Sprite As Direct3DTexture8
End Type
Public GameItem(1 To 9) As item

Public Sub InitializeItems()
'item1
    GameItem(1).ItemName = "Guava Leaves"
    GameItem(1).itemPrice = 1
    GameItem(1).ItemDesc = "Heals 1 HP"
'item2
    GameItem(2).ItemName = "Steamed Rice"
    GameItem(2).itemPrice = 2
    GameItem(2).ItemDesc = "Heals 2 HP"
'item3
    GameItem(3).ItemName = "Mango"
    GameItem(3).itemPrice = 5
    GameItem(3).ItemDesc = "Heals 4 HP"
'item4
    GameItem(4).ItemName = "Apple"
    GameItem(4).itemPrice = 10
    GameItem(4).ItemDesc = "Heals 8 HP"
'item5
    GameItem(5).ItemName = "Banana"
    GameItem(5).itemPrice = 20
    GameItem(5).ItemDesc = "Heals 16 HP"
'item6
    GameItem(6).ItemName = "Fried Fish"
    GameItem(6).itemPrice = 40
    GameItem(6).ItemDesc = "Heals 32 HP"
'item7
    GameItem(7).ItemName = "Sweet Ham"
    GameItem(7).itemPrice = 70
    GameItem(7).ItemDesc = "Heals 65 HP"
'item8
    GameItem(8).ItemName = "Herb"
    GameItem(8).itemPrice = 120
    GameItem(8).ItemDesc = "Heals 120 HP"
'item9
    GameItem(9).ItemName = "Medicine"
    GameItem(9).itemPrice = 230
    GameItem(9).ItemDesc = "Heals 230 HP"
AssignItemTexture
End Sub

Public Sub DestroyItems()
Dim x As Integer
    For x = 1 To 9
        Set GameItem(x).Sprite = Nothing
    Next
End Sub
Public Sub BuyWinItems()
    'item1
    Dev.SetTexture 0, GameItem(1).Sprite
    Set_Vertex GameMapScreenWidth - 211, GameMapScreenY + 100 + 40, 20, 20, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'item2
    Dev.SetTexture 0, GameItem(2).Sprite
    Set_Vertex GameMapScreenWidth - 211 + 41, GameMapScreenY + 100 + 40, 20, 20, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'item3
    Dev.SetTexture 0, GameItem(3).Sprite
    Set_Vertex GameMapScreenWidth - 211 + 82, GameMapScreenY + 100 + 40, 20, 20, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'item4
    Dev.SetTexture 0, GameItem(4).Sprite
    Set_Vertex GameMapScreenWidth - 211, GameMapScreenY + 100 + 80, 20, 20, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'item5
    Dev.SetTexture 0, GameItem(5).Sprite
    Set_Vertex GameMapScreenWidth - 211 + 41, GameMapScreenY + 100 + 80, 20, 20, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'item6
    Dev.SetTexture 0, GameItem(6).Sprite
    Set_Vertex GameMapScreenWidth - 211 + 82, GameMapScreenY + 100 + 80, 20, 20, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'item7
    Dev.SetTexture 0, GameItem(7).Sprite
    Set_Vertex GameMapScreenWidth - 211, GameMapScreenY + 100 + 120, 20, 20, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'item8
    Dev.SetTexture 0, GameItem(8).Sprite
    Set_Vertex GameMapScreenWidth - 211 + 41, GameMapScreenY + 100 + 120, 20, 20, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'item9
    Dev.SetTexture 0, GameItem(9).Sprite
    Set_Vertex GameMapScreenWidth - 211 + 82, GameMapScreenY + 100 + 120, 20, 20, 16777215, 16777215, 16777215, 16777215
    Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
    'updates the belt
    DrawBeltItem 0
    DrawBeltItem 1
    DrawBeltItem 2
    DrawBeltItem 3
End Sub
Private Sub DrawBeltItem(iNum As Integer)
Dim z As Long
    For z = 1 To 9
        If iNum = 0 Then
            If PlayerBelt.Slot(0) = z Then
                Dev.SetTexture 0, GameItem(z).Sprite
                Set_Vertex GameMapScreenX + 12, GameMapScreenY - 23, 16, 16, 16777215, 16777215, 16777215, 16777215
                Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
            End If
        End If
        If iNum = 1 Then
            If PlayerBelt.Slot(1) = z Then
                Dev.SetTexture 0, GameItem(z).Sprite
                Set_Vertex GameMapScreenX + 34, GameMapScreenY - 23, 16, 16, 16777215, 16777215, 16777215, 16777215
                Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
            End If
        End If
        If iNum = 2 Then
            If PlayerBelt.Slot(2) = z Then
                Dev.SetTexture 0, GameItem(z).Sprite
                Set_Vertex GameMapScreenX + 56, GameMapScreenY - 23, 16, 16, 16777215, 16777215, 16777215, 16777215
                Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
            End If
        End If
        If iNum = 3 Then
            If PlayerBelt.Slot(3) = z Then
                Dev.SetTexture 0, GameItem(z).Sprite
                Set_Vertex GameMapScreenX + 78, GameMapScreenY - 23, 16, 16, 16777215, 16777215, 16777215, 16777215
                Dev.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex(0), Len(Vertex(0))
            End If
        End If
    Next
End Sub

Public Sub Refreshbelt()
    DrawBeltItem 0
    DrawBeltItem 1
    DrawBeltItem 2
    DrawBeltItem 3
End Sub
Public Function GetItemEffect(iNum As Integer) As Long
    If iNum = 1 Then
        GetItemEffect = 1
    ElseIf iNum = 2 Then
        GetItemEffect = 2
    ElseIf iNum = 3 Then
        GetItemEffect = 4
    ElseIf iNum = 4 Then
        GetItemEffect = 8
    ElseIf iNum = 5 Then
        GetItemEffect = 16
    ElseIf iNum = 6 Then
        GetItemEffect = 32
    ElseIf iNum = 7 Then
        GetItemEffect = 65
    ElseIf iNum = 8 Then
        GetItemEffect = 120
    ElseIf iNum = 9 Then
        GetItemEffect = 230
    End If
End Function
Public Sub PlayerUseItem(itmp As Integer)
Dim lNum As Integer
    If PlayerBelt.Slot(itmp) = 1 Then
        lNum = GetItemEffect(1)
        If (PlayerStats.Life + lNum) > PlayerStats.LifeMax Then
            PlayerStats.Life = PlayerStats.LifeMax
        Else
            PlayerStats.Life = PlayerStats.Life + lNum
        End If
    End If
    If PlayerBelt.Slot(itmp) = 2 Then
        lNum = GetItemEffect(2)
        If (PlayerStats.Life + lNum) > PlayerStats.LifeMax Then
            PlayerStats.Life = PlayerStats.LifeMax
        Else
            PlayerStats.Life = PlayerStats.Life + lNum
        End If
    End If
    If PlayerBelt.Slot(itmp) = 3 Then
        lNum = GetItemEffect(3)
        If (PlayerStats.Life + lNum) > PlayerStats.LifeMax Then
            PlayerStats.Life = PlayerStats.LifeMax
        Else
            PlayerStats.Life = PlayerStats.Life + GetItemEffect(3)
        End If
    End If
    If PlayerBelt.Slot(itmp) = 4 Then
        lNum = GetItemEffect(4)
        If (PlayerStats.Life + lNum) > PlayerStats.LifeMax Then
            PlayerStats.Life = PlayerStats.LifeMax
        Else
            PlayerStats.Life = PlayerStats.Life + GetItemEffect(4)
        End If
    End If
    If PlayerBelt.Slot(itmp) = 5 Then
        lNum = GetItemEffect(5)
        If (PlayerStats.Life + lNum) > PlayerStats.LifeMax Then
            PlayerStats.Life = PlayerStats.LifeMax
        Else
            PlayerStats.Life = PlayerStats.Life + GetItemEffect(5)
        End If
    End If
    If PlayerBelt.Slot(itmp) = 6 Then
        lNum = GetItemEffect(6)
        If (PlayerStats.Life + lNum) > PlayerStats.LifeMax Then
            PlayerStats.Life = PlayerStats.LifeMax
        Else
            PlayerStats.Life = PlayerStats.Life + GetItemEffect(6)
        End If
    End If
    If PlayerBelt.Slot(itmp) = 7 Then
        lNum = GetItemEffect(7)
        If (PlayerStats.Life + lNum) > PlayerStats.LifeMax Then
            PlayerStats.Life = PlayerStats.LifeMax
        Else
            PlayerStats.Life = PlayerStats.Life + GetItemEffect(7)
        End If
    End If
    If PlayerBelt.Slot(itmp) = 8 Then
        lNum = GetItemEffect(8)
        If (PlayerStats.Life + lNum) > PlayerStats.LifeMax Then
            PlayerStats.Life = PlayerStats.LifeMax
        Else
            PlayerStats.Life = PlayerStats.Life + GetItemEffect(8)
        End If
    End If
    If PlayerBelt.Slot(itmp) = 9 Then
        lNum = GetItemEffect(9)
        If (PlayerStats.Life + lNum) > PlayerStats.LifeMax Then
            PlayerStats.Life = PlayerStats.LifeMax
        Else
            PlayerStats.Life = PlayerStats.Life + GetItemEffect(9)
        End If
    End If
End Sub
