Imports P3D.Items
'''
''' An item the player stores in their inventory.
'''
Public MustInherit Class Item
Protected _textureSource As String = "Items\ItemSheet"
Protected _textureRectangle As Rectangle
Private _texture As Texture2D
Public ReadOnly Property TextureSource As String
Get
Return _textureSource & "," & _textureRectangle.X & "," & _textureRectangle.Y & "," & _textureRectangle.Width & "," & _textureRectangle.Height
End Get
End Property
Public Function GetDescription() As String
If Localization.TokenExists("item_desc_" & GetAttribute().Id) = True Then
Return Localization.GetString("item_desc_" & GetAttribute().Id)
Else
Return Me.Description
End If
End Function
Private _attribute As ItemAttribute
Private Function GetAttribute() As ItemAttribute
If _attribute Is Nothing Then
_attribute = CType([GetType]().GetCustomAttributes(GetType(ItemAttribute), False)(0), ItemAttribute)
End If
Return _attribute
End Function
'''
''' The singular item name.
'''
Public Overridable ReadOnly Property Name As String
Get
If Localization.TokenExists("item_name_" & GetAttribute().Id) = True Then
Return Localization.GetString("item_name_" & GetAttribute().Id)
Else
Return GetAttribute().Name
End If
End Get
End Property
'''
''' The ID of the item.
'''
Public Overridable ReadOnly Property ID As Integer
Get
Return GetAttribute().Id
End Get
End Property
'''
''' The plural name of the item.
'''
Public Overridable ReadOnly Property PluralName As String
Get
Return Name & "s" 'Default plural name with "s" at the end.
End Get
End Property
'''
''' The price of this item if the player purchases it in exchange for PokéDollars. This halves when selling an item to the store.
'''
Public Overridable ReadOnly Property PokeDollarPrice As Integer = 0
'''
''' The price of this item if the player purchases it exchange for BattlePoints.
'''
Public Overridable ReadOnly Property BattlePointsPrice As Integer = 1
'''
''' The type of this item. This also controls in which bag this item gets sorted.
'''
Public Overridable ReadOnly Property ItemType As ItemTypes = ItemTypes.Standard
'''
''' The default catch multiplier if the item gets used as a Pokéball.
'''
Public Overridable ReadOnly Property CatchMultiplier As Single = 1.0F
'''
''' The maximum amount of this item type (per ID) that can be stored in the bag.
'''
Public Overridable ReadOnly Property MaxStack As Integer = 999
'''
''' A value that can be used to sort items in the bag after. Lower values make items appear closer to the top.
'''
Public Overridable ReadOnly Property SortValue As Integer = 0
'''
''' The texture of this item.
'''
Public ReadOnly Property Texture As Texture2D
Get
If _texture Is Nothing Then
_texture = TextureManager.GetTexture(_textureSource, _textureRectangle, "")
End If
Return _texture
End Get
End Property
'''
''' The bag description of this item.
'''
Public Overridable ReadOnly Property Description As String = ""
'''
''' The additional data that is stored with this item.
'''
Public Property AdditionalData As String = ""
'''
''' The damage the Fling move does when this item is attached to a Pokémon.
'''
Public Overridable ReadOnly Property FlingDamage As Integer = 30
'''
''' If this item can be traded in for money.
'''
Public Overridable ReadOnly Property CanBeTraded As Boolean = True
'''
''' If this item can be given to a Pokémon.
'''
Public Overridable ReadOnly Property CanBeHold As Boolean = True
'''
''' If this item can be used from the bag.
'''
Public Overridable ReadOnly Property CanBeUsed As Boolean = True
'''
''' If this item can be used in battle.
'''
Public Overridable ReadOnly Property CanBeUsedInBattle As Boolean = True
'''
''' If this item can be tossed in the bag.
'''
Public Overridable ReadOnly Property CanBeTossed As Boolean = True
'''
''' If this item requires the player to select a Pokémon to use the item on in battle.
'''
Public Overridable ReadOnly Property BattleSelectPokemon As Boolean = True
'''
''' If this item is a Healing item.
'''
Public Overridable ReadOnly Property IsHealingItem As Boolean = False
'''
''' If this item is a Pokéball item.
'''
Public Overridable ReadOnly Property IsBall As Boolean
Get
Return [GetType]().IsSubclassOf(GetType(Items.Balls.BallItem))
End Get
End Property
'''
''' If this item is a Berry item.
'''
Public ReadOnly Property IsBerry As Boolean
Get
Return [GetType]().IsSubclassOf(GetType(Berry))
End Get
End Property
'''
''' If this item is a Mail item.
'''
Public ReadOnly Property IsMail As Boolean
Get
Return [GetType]().IsSubclassOf(GetType(MailItem))
End Get
End Property
'''
''' If this item is a Mega Stone.
'''
Public ReadOnly Property IsMegaStone As Boolean
Get
Return [GetType]().IsSubclassOf(GetType(MegaStone))
End Get
End Property
'''
''' If this item is a Plate.
'''
Public ReadOnly Property IsPlate As Boolean
Get
Return [GetType]().IsSubclassOf(GetType(PlateItem))
End Get
End Property
'''
''' The color for player dialogues.
'''
Public Shared ReadOnly Property PlayerDialogueColor As Color
Get
Return New Color(0, 128, 227)
End Get
End Property
'''
''' The item gets used from the bag.
'''
Public Overridable Sub Use()
Logger.Debug("PLACEHOLDER FOR ITEM USE")
End Sub
Public Sub UseItemhandler(ByVal params As Object())
If UseOnPokemon(CInt(params(0))) Then
Dim s As Screen = Core.CurrentScreen
While Not s.PreScreen Is Nothing And s.Identification <> Screen.Identifications.InventoryScreen
s = s.PreScreen
End While
If s.Identification = Screen.Identifications.InventoryScreen Then
CType(s, NewInventoryScreen).LoadItems()
End If
End If
End Sub
'''
''' A method that gets used when the item is applied to a Pokémon. Returns True if the action was successful.
'''
''' The Index of the Pokémon in party.
Public Overridable Function UseOnPokemon(ByVal PokeIndex As Integer) As Boolean
If PokeIndex < 0 Or PokeIndex > 5 Then
Throw New ArgumentOutOfRangeException("PokeIndex", PokeIndex, "The index for a Pokémon in a player's party can only be between 0 and 5.")
End If
Logger.Debug("PLACEHOLDER FOR ITEM USE ON POKEMON")
Return False
End Function
'''
''' Tries to remove a single item of this item type from the player's bag and returns a message which changes depending on if the item that got removed was the last one of its kind.
'''
Public Function RemoveItem() As String
Core.Player.Inventory.RemoveItem(Me.ID, 1)
If Core.Player.Inventory.GetItemAmount(Me.ID) = 0 Then
Return "*There are no~" & Me.PluralName & " left."
End If
Return ""
End Function
Private Shared _itemBuffer As Dictionary(Of ItemIdentifier, Type)
Private Shared Sub LoadItemBuffer()
_itemBuffer = GetType(Item).Assembly.GetTypes().Where(Function(t As Type)
Return t.GetCustomAttributes(GetType(ItemAttribute), False).Length = 1
End Function).ToDictionary(Function(tt As Type)
Dim attr = CType(tt.GetCustomAttributes(GetType(ItemAttribute), False)(0), ItemAttribute)
Return New ItemIdentifier() With
{
.Id = attr.Id,
.Name = attr.Name
}
End Function,
Function(tt As Type)
Return tt
End Function)
End Sub
'''
''' Returns an item instance based on the passed in ID.
'''
''' The desired item's ID.
Public Shared Function GetItemByID(ByVal ID As Integer) As Item
If _itemBuffer Is Nothing Then
LoadItemBuffer()
End If
Dim type = _itemBuffer.FirstOrDefault(Function(itemTypePair)
Return itemTypePair.Key.Id = ID
End Function).Value
If type IsNot Nothing Then
Return CType(Activator.CreateInstance(type), Item)
End If
Return Nothing
End Function
'''
''' Returns an item based on its name.
'''
''' The name of the item.
Public Shared Function GetItemByName(ByVal name As String) As Item
Dim type = _itemBuffer.FirstOrDefault(Function(itemTypePair)
Return itemTypePair.Key.Name.ToLowerInvariant() = name.ToLowerInvariant()
End Function).Value
If type IsNot Nothing Then
Return CType(Activator.CreateInstance(type), Item)
End If
Logger.Log(Logger.LogTypes.Warning, "Item.vb: Cannot find item with the name """ & name & """.")
Return Nothing
End Function
End Class