2018-02-21 16:34:06 +01:00
Imports P3D . Items
2016-09-20 02:18:12 +02:00
2016-09-19 03:26:44 +02:00
''' <summary>
2016-09-07 18:50:38 +02:00
''' An item the player stores in their inventory.
''' </summary>
2016-09-20 02:18:12 +02:00
Public MustInherit Class Item
2016-09-07 18:50:38 +02:00
2016-09-20 02:18:12 +02:00
Protected _textureSource As String = " Items\ItemSheet "
Protected _textureRectangle As Rectangle
Private _texture As Texture2D
2021-08-22 16:47:26 +02:00
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
2016-09-20 02:18:12 +02:00
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
2016-09-07 18:50:38 +02:00
2023-01-02 15:27:59 +01:00
Public Function OriginalName ( ) As String
Return GetAttribute ( ) . Name
End Function
2016-09-07 18:50:38 +02:00
''' <summary>
''' The singular item name.
''' </summary>
2016-09-20 02:18:12 +02:00
Public Overridable ReadOnly Property Name As String
2016-09-07 18:50:38 +02:00
Get
2021-08-22 16:47:26 +02:00
If Localization . TokenExists ( " item_name_ " & GetAttribute ( ) . Id ) = True Then
Return Localization . GetString ( " item_name_ " & GetAttribute ( ) . Id )
Else
Return GetAttribute ( ) . Name
End If
2016-09-07 18:50:38 +02:00
End Get
End Property
''' <summary>
''' The ID of the item.
''' </summary>
2016-09-20 02:18:12 +02:00
Public Overridable ReadOnly Property ID As Integer
2016-09-07 18:50:38 +02:00
Get
2016-09-20 02:18:12 +02:00
Return GetAttribute ( ) . Id
2016-09-07 18:50:38 +02:00
End Get
End Property
''' <summary>
''' The plural name of the item.
''' </summary>
2016-09-20 02:18:12 +02:00
Public Overridable ReadOnly Property PluralName As String
2016-09-07 18:50:38 +02:00
Get
2016-09-20 02:18:12 +02:00
Return Name & " s " 'Default plural name with "s" at the end.
2016-09-07 18:50:38 +02:00
End Get
End Property
''' <summary>
''' The price of this item if the player purchases it in exchange for PokéDollars. This halves when selling an item to the store.
''' </summary>
2016-09-20 02:18:12 +02:00
Public Overridable ReadOnly Property PokeDollarPrice As Integer = 0
2016-09-07 18:50:38 +02:00
''' <summary>
''' The price of this item if the player purchases it exchange for BattlePoints.
''' </summary>
2016-09-20 02:18:12 +02:00
Public Overridable ReadOnly Property BattlePointsPrice As Integer = 1
2016-09-07 18:50:38 +02:00
''' <summary>
''' The type of this item. This also controls in which bag this item gets sorted.
''' </summary>
2016-09-20 02:18:12 +02:00
Public Overridable ReadOnly Property ItemType As ItemTypes = ItemTypes . Standard
2016-09-07 18:50:38 +02:00
''' <summary>
''' The default catch multiplier if the item gets used as a Pokéball.
''' </summary>
2016-09-20 02:18:12 +02:00
Public Overridable ReadOnly Property CatchMultiplier As Single = 1 . 0F
2016-09-07 18:50:38 +02:00
''' <summary>
''' The maximum amount of this item type (per ID) that can be stored in the bag.
''' </summary>
2016-09-20 02:18:12 +02:00
Public Overridable ReadOnly Property MaxStack As Integer = 999
2016-09-07 18:50:38 +02:00
''' <summary>
''' A value that can be used to sort items in the bag after. Lower values make items appear closer to the top.
''' </summary>
2016-09-20 02:18:12 +02:00
Public Overridable ReadOnly Property SortValue As Integer = 0
2016-09-07 18:50:38 +02:00
''' <summary>
''' The texture of this item.
''' </summary>
2016-09-20 02:18:12 +02:00
Public ReadOnly Property Texture As Texture2D
2016-09-07 18:50:38 +02:00
Get
2016-09-20 02:18:12 +02:00
If _texture Is Nothing Then
_texture = TextureManager . GetTexture ( _textureSource , _textureRectangle , " " )
End If
Return _texture
2016-09-07 18:50:38 +02:00
End Get
End Property
''' <summary>
''' The bag description of this item.
''' </summary>
2016-09-20 02:18:12 +02:00
Public Overridable ReadOnly Property Description As String = " "
2016-09-07 18:50:38 +02:00
''' <summary>
''' The additional data that is stored with this item.
''' </summary>
2016-09-20 02:18:12 +02:00
Public Property AdditionalData As String = " "
2016-09-07 18:50:38 +02:00
''' <summary>
''' The damage the Fling move does when this item is attached to a Pokémon.
''' </summary>
2016-09-20 02:18:12 +02:00
Public Overridable ReadOnly Property FlingDamage As Integer = 30
2016-09-07 18:50:38 +02:00
''' <summary>
''' If this item can be traded in for money.
''' </summary>
2016-09-20 02:18:12 +02:00
Public Overridable ReadOnly Property CanBeTraded As Boolean = True
2016-09-07 18:50:38 +02:00
''' <summary>
''' If this item can be given to a Pokémon.
''' </summary>
2016-09-20 02:18:12 +02:00
Public Overridable ReadOnly Property CanBeHold As Boolean = True
2016-09-07 18:50:38 +02:00
''' <summary>
''' If this item can be used from the bag.
''' </summary>
2016-09-20 02:18:12 +02:00
Public Overridable ReadOnly Property CanBeUsed As Boolean = True
2016-09-07 18:50:38 +02:00
''' <summary>
''' If this item can be used in battle.
''' </summary>
2016-09-20 02:18:12 +02:00
Public Overridable ReadOnly Property CanBeUsedInBattle As Boolean = True
2016-09-07 18:50:38 +02:00
''' <summary>
''' If this item can be tossed in the bag.
''' </summary>
2016-09-20 02:18:12 +02:00
Public Overridable ReadOnly Property CanBeTossed As Boolean = True
2016-09-07 18:50:38 +02:00
''' <summary>
''' If this item requires the player to select a Pokémon to use the item on in battle.
''' </summary>
2016-09-20 02:18:12 +02:00
Public Overridable ReadOnly Property BattleSelectPokemon As Boolean = True
2016-09-07 18:50:38 +02:00
''' <summary>
2016-09-20 05:34:00 +02:00
''' If this item is a Healing item.
2016-09-07 18:50:38 +02:00
''' </summary>
2016-09-20 05:34:00 +02:00
Public Overridable ReadOnly Property IsHealingItem As Boolean = False
2016-09-07 18:50:38 +02:00
''' <summary>
2016-09-20 05:34:00 +02:00
''' If this item is a Pokéball item.
2016-09-07 18:50:38 +02:00
''' </summary>
2016-09-20 05:34:00 +02:00
Public Overridable ReadOnly Property IsBall As Boolean
Get
Return [ GetType ] ( ) . IsSubclassOf ( GetType ( Items . Balls . BallItem ) )
End Get
End Property
2016-09-07 18:50:38 +02:00
''' <summary>
2016-09-20 02:18:12 +02:00
''' If this item is a Berry item.
2016-09-07 18:50:38 +02:00
''' </summary>
2016-09-20 02:18:12 +02:00
Public ReadOnly Property IsBerry As Boolean
2016-09-07 18:50:38 +02:00
Get
2016-09-20 02:18:12 +02:00
Return [ GetType ] ( ) . IsSubclassOf ( GetType ( Berry ) )
2016-09-07 18:50:38 +02:00
End Get
End Property
''' <summary>
''' If this item is a Mail item.
''' </summary>
2016-09-20 02:18:12 +02:00
Public ReadOnly Property IsMail As Boolean
2016-09-07 18:50:38 +02:00
Get
2016-09-20 02:18:12 +02:00
Return [ GetType ] ( ) . IsSubclassOf ( GetType ( MailItem ) )
2016-09-07 18:50:38 +02:00
End Get
End Property
''' <summary>
''' If this item is a Mega Stone.
''' </summary>
2016-09-20 02:18:12 +02:00
Public ReadOnly Property IsMegaStone As Boolean
2016-09-07 18:50:38 +02:00
Get
2016-09-20 02:18:12 +02:00
Return [ GetType ] ( ) . IsSubclassOf ( GetType ( MegaStone ) )
2016-09-07 18:50:38 +02:00
End Get
End Property
''' <summary>
''' If this item is a Plate.
''' </summary>
2016-09-20 02:18:12 +02:00
Public ReadOnly Property IsPlate As Boolean
2016-09-07 18:50:38 +02:00
Get
2016-09-20 02:18:12 +02:00
Return [ GetType ] ( ) . IsSubclassOf ( GetType ( PlateItem ) )
2016-09-07 18:50:38 +02:00
End Get
End Property
''' <summary>
''' The color for player dialogues.
''' </summary>
2016-09-20 02:18:12 +02:00
Public Shared ReadOnly Property PlayerDialogueColor As Color
2016-09-07 18:50:38 +02:00
Get
Return New Color ( 0 , 128 , 227 )
End Get
End Property
''' <summary>
''' The item gets used from the bag.
''' </summary>
Public Overridable Sub Use ( )
Logger . Debug ( " PLACEHOLDER FOR ITEM USE " )
End Sub
2017-08-11 09:01:17 +02:00
Public Sub UseItemhandler ( ByVal params As Object ( ) )
2019-01-30 04:49:09 +01:00
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
2017-08-11 09:01:17 +02:00
End Sub
2016-09-07 18:50:38 +02:00
''' <summary>
''' A method that gets used when the item is applied to a Pokémon. Returns True if the action was successful.
''' </summary>
''' <param name="PokeIndex">The Index of the Pokémon in party.</param>
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
''' <summary>
''' 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.
''' </summary>
Public Function RemoveItem ( ) As String
Core . Player . Inventory . RemoveItem ( Me . ID , 1 )
2023-02-23 12:09:53 +01:00
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
If Core . Player . Inventory . GetItemAmount ( Me . ID ) <= 0 Then
2016-09-19 04:34:12 +02:00
Return " *There are no~ " & Me . PluralName & " left. "
2016-09-07 18:50:38 +02:00
End If
Return " "
End Function
2016-09-19 04:34:12 +02:00
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
2016-09-07 18:50:38 +02:00
''' <summary>
''' Returns an item instance based on the passed in ID.
''' </summary>
''' <param name="ID">The desired item's ID.</param>
Public Shared Function GetItemByID ( ByVal ID As Integer ) As Item
2016-09-19 04:34:12 +02:00
If _itemBuffer Is Nothing Then
LoadItemBuffer ( )
End If
2016-09-07 18:50:38 +02:00
2016-09-19 04:34:12 +02:00
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
2016-09-07 18:50:38 +02:00
2016-09-19 04:34:12 +02:00
Return Nothing
2016-09-07 18:50:38 +02:00
End Function
''' <summary>
''' Returns an item based on its name.
''' </summary>
''' <param name="name">The name of the item.</param>
Public Shared Function GetItemByName ( ByVal name As String ) As Item
2016-09-19 04:34:12 +02:00
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 )
2016-09-07 18:50:38 +02:00
End If
2016-09-19 04:34:12 +02:00
2016-09-07 18:50:38 +02:00
Logger . Log ( Logger . LogTypes . Warning , " Item.vb: Cannot find item with the name "" " & name & " "" . " )
Return Nothing
End Function
2016-09-19 03:26:44 +02:00
End Class