2023-12-10 20:19:14 +01:00
Namespace BattleSystem
''' <summary>
''' Provides an interface to load additional GameMode moves.
''' </summary>
Public Class GameModeElementLoader
'The default relative path to load moves from (Content folder).
Const PATH As String = " Data\Types\ "
'List of loaded moves.
Shared LoadedElements As New List ( Of Element )
''' <summary>
''' Load the attack list for the loaded GameMode.
''' </summary>
''' <remarks>The game won't try to load the list if the default GameMode is selected.</remarks>
Public Shared Sub Load ( )
LoadedElements . Clear ( )
If GameModeManager . ActiveGameMode . IsDefaultGamemode = False Then
If System . IO . Directory . Exists ( GameController . GamePath & " \ " & GameModeManager . ActiveGameMode . ContentPath & " \ " & PATH ) = True Then
For Each file As String In System . IO . Directory . GetFiles ( GameController . GamePath & " \ " & GameModeManager . ActiveGameMode . ContentPath & PATH , " *.dat " )
LoadElement ( file )
Next
End If
End If
If LoadedElements . Count > 0 Then
For Each e As Element In LoadedElements
For Each id As Element In LoadedElements
If e . gmEffectivenessAttack . ContainsKey ( id . Type ) = False Then
e . gmEffectivenessAttack . Add ( id . Type , 1 . 0F )
End If
If e . gmEffectivenessDefense . ContainsKey ( id . Type ) = False Then
e . gmEffectivenessDefense . Add ( id . Type , 1 . 0F )
End If
Next
Next
Logger . Debug ( " Loaded " & LoadedElements . Count . ToString ( ) & " GameMode type(s). " )
End If
End Sub
''' <summary>
''' Loads a move from a file.
''' </summary>
''' <param name="file">The file to load the move from.</param>
Private Shared Sub LoadElement ( ByVal file As String )
Dim element As New Element ( ) 'Load a blank Element.
element . IsGameModeElement = True
Dim content ( ) As String = System . IO . File . ReadAllLines ( file )
Dim key As String = " "
Dim value As String = " "
Dim setID As Boolean = False 'Controls if the move sets its ID.
Dim nonCommentLines As Integer = 0
Try
'Go through lines of the file and set the properties depending on the content.
'Lines starting with # are comments.
For Each l As String In content
If l . Contains ( " | " ) = True And l . StartsWith ( " # " ) = False Then
nonCommentLines += 1
key = l . Remove ( l . IndexOf ( " | " ) )
value = l . Remove ( 0 , l . IndexOf ( " | " ) + 1 )
Select Case key . ToLower ( )
Case " id "
element . Type = CInt ( value )
setID = True
Case " name "
element . gmOriginalName = value
Case " typeimageoffset "
element . gmTypeRectangle = New Rectangle ( CInt ( value . GetSplit ( 0 , " , " ) ) , CInt ( value . GetSplit ( 1 , " , " ) ) , 48 , 16 )
Case " itemtexturesource "
element . gmMachineTextureSource = value
Case " itemtextureoffset "
element . gmMachineTextureRectangle = New Rectangle ( CInt ( value . GetSplit ( 0 , " , " ) ) , CInt ( value . GetSplit ( 1 , " , " ) ) , 24 , 24 )
Case " effectivenessattack "
Dim data ( ) As String = value . Split ( " ; " )
For i = 0 To data . Count - 1
Dim typeID As Integer = - 1
If StringHelper . IsNumeric ( data ( i ) . GetSplit ( 0 , " , " ) ) = True Then
typeID = CInt ( data ( i ) . GetSplit ( 0 , " , " ) )
Else
2023-12-12 09:57:53 +01:00
Select Case data ( i ) . GetSplit ( 0 , " , " ) . ToLower
2023-12-10 20:19:14 +01:00
Case " normal "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Normal
2023-12-10 20:19:14 +01:00
Case " fighting "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Fighting
2023-12-10 20:19:14 +01:00
Case " flying "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Flying
2023-12-10 20:19:14 +01:00
Case " poison "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Poison
2023-12-10 20:19:14 +01:00
Case " ground "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Ground
2023-12-10 20:19:14 +01:00
Case " rock "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Rock
2023-12-10 20:19:14 +01:00
Case " bug "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Bug
2023-12-10 20:19:14 +01:00
Case " ghost "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Ghost
2023-12-10 20:19:14 +01:00
Case " steel "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Steel
2023-12-10 20:19:14 +01:00
Case " fire "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Fire
2023-12-10 20:19:14 +01:00
Case " water "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Water
2023-12-10 20:19:14 +01:00
Case " grass "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Grass
2023-12-10 20:19:14 +01:00
Case " electric "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Electric
2023-12-10 20:19:14 +01:00
Case " psychic "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Psychic
2023-12-10 20:19:14 +01:00
Case " ice "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Ice
2023-12-10 20:19:14 +01:00
Case " dragon "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Dragon
2023-12-10 20:19:14 +01:00
Case " dark "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Dark
2023-12-10 20:19:14 +01:00
Case " fairy "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Fairy
2023-12-10 20:19:14 +01:00
Case " shadow "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Shadow
2023-12-10 20:19:14 +01:00
End Select
End If
element . gmEffectivenessAttack . Add ( typeID , CSng ( data ( i ) . GetSplit ( 1 , " , " ) . InsertDecSeparator ) )
Next
Case " effectivenessdefense "
Dim data ( ) As String = value . Split ( " ; " )
For i = 0 To data . Count - 1
Dim typeID As Integer = - 1
If StringHelper . IsNumeric ( data ( i ) . GetSplit ( 0 , " , " ) ) = True Then
typeID = CInt ( data ( i ) . GetSplit ( 0 , " , " ) )
Else
2023-12-12 09:57:53 +01:00
Select Case data ( i ) . GetSplit ( 0 , " , " ) . ToLower
2023-12-10 20:19:14 +01:00
Case " normal "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Normal
2023-12-10 20:19:14 +01:00
Case " fighting "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Fighting
2023-12-10 20:19:14 +01:00
Case " flying "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Flying
2023-12-10 20:19:14 +01:00
Case " poison "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Poison
2023-12-10 20:19:14 +01:00
Case " ground "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Ground
2023-12-10 20:19:14 +01:00
Case " rock "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Rock
2023-12-10 20:19:14 +01:00
Case " bug "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Bug
2023-12-10 20:19:14 +01:00
Case " ghost "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Ghost
2023-12-10 20:19:14 +01:00
Case " steel "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Steel
2023-12-10 20:19:14 +01:00
Case " fire "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Fire
2023-12-10 20:19:14 +01:00
Case " water "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Water
2023-12-10 20:19:14 +01:00
Case " grass "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Grass
2023-12-10 20:19:14 +01:00
Case " electric "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Electric
2023-12-10 20:19:14 +01:00
Case " psychic "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Psychic
2023-12-10 20:19:14 +01:00
Case " ice "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Ice
2023-12-10 20:19:14 +01:00
Case " dragon "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Dragon
2023-12-10 20:19:14 +01:00
Case " dark "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Dark
2023-12-10 20:19:14 +01:00
Case " fairy "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Fairy
2023-12-10 20:19:14 +01:00
Case " shadow "
2023-12-12 09:57:53 +01:00
typeID = Element . Types . Shadow
2023-12-10 20:19:14 +01:00
End Select
End If
element . gmEffectivenessDefense . Add ( typeID , CSng ( data ( i ) . GetSplit ( 1 , " , " ) . InsertDecSeparator ) )
Next
End Select
End If
Next
Catch ex As Exception
'If an error occurs loading a move, log the error.
Logger . Log ( Logger . LogTypes . ErrorMessage , " GameModeElementLoader.vb: Error loading GameMode element from file "" " & file & " "" : " & ex . Message & " ; Last Key/Value pair successfully loaded: " & key & " | " & value )
End Try
If nonCommentLines > 0 Then
If setID = True Then
If element . Type >= 20 Then
If Localization . TokenExists ( " element_name_ " & element . gmOriginalName . ToString ) = True Then
2023-12-12 10:00:54 +01:00
element . gmOriginalName = Localization . GetString ( " move_name_ " & element . gmOriginalName . ToString )
2023-12-10 20:19:14 +01:00
End If
For i = 0 To 18
If element . gmEffectivenessAttack . ContainsKey ( i ) = False Then
element . gmEffectivenessAttack . Add ( i , 1 . 0F )
End If
If element . gmEffectivenessDefense . ContainsKey ( i ) = False Then
element . gmEffectivenessDefense . Add ( i , 1 . 0F )
End If
Next
LoadedElements . Add ( element ) 'Add the element.
Else
Logger . Log ( Logger . LogTypes . ErrorMessage , " GameModeElementLoader.vb: User defined types are not allowed to have an ID of an already existing type or an ID below 20. The ID for the type loaded from "" " & file & " "" has the ID " & element . Type . ToString ( ) & " , which is smaller than 20. " )
End If
Else
Logger . Log ( Logger . LogTypes . ErrorMessage , " GameModeElementLoader.vb: User defined types must set their ID through the "" ID "" property, however the type loaded from "" " & file & " "" has no ID set so it will be ignored. " )
End If
Else
Debug . Print ( " GameModeElementLoader.vb: The type loaded from "" " & file & " "" has no valid lines so it will be ignored. " )
End If
End Sub
''' <summary>
''' Returns an element based on its ID.
''' </summary>
''' <param name="ID">The ID of the element.</param>
''' <returns>Returns an element or nothing.</returns>
Public Shared Function GetElementByID ( ByVal ID As Integer ) As Element
If ID <= 19 Then
Return New Element ( ID )
Else
For Each e As Element In LoadedElements
If e . Type = ID Then
Return e
End If
Next
End If
Return Nothing
End Function
''' <summary>
''' Returns an element based on its name.
''' </summary>
''' <param name="Name">The name of the element.</param>
''' <returns>Returns an element or nothing.</returns>
Public Shared Function GetElementByName ( ByVal Name As String ) As Element
Select Case Name . ToLower
Case " normal "
Return New Element ( Element . Types . Normal )
Case " fighting "
Return New Element ( Element . Types . Fighting )
Case " flying "
Return New Element ( Element . Types . Flying )
Case " poison "
Return New Element ( Element . Types . Poison )
Case " ground "
Return New Element ( Element . Types . Ground )
Case " rock "
Return New Element ( Element . Types . Rock )
Case " bug "
Return New Element ( Element . Types . Bug )
Case " ghost "
Return New Element ( Element . Types . Ghost )
Case " steel "
Return New Element ( Element . Types . Steel )
Case " fire "
Return New Element ( Element . Types . Fire )
Case " water "
Return New Element ( Element . Types . Water )
Case " grass "
Return New Element ( Element . Types . Grass )
Case " electric "
Return New Element ( Element . Types . Electric )
Case " psychic "
Return New Element ( Element . Types . Psychic )
Case " ice "
Return New Element ( Element . Types . Ice )
Case " dragon "
Return New Element ( Element . Types . Dragon )
Case " dark "
Return New Element ( Element . Types . Dark )
Case " fairy "
Return New Element ( Element . Types . Fairy )
Case " shadow "
Return New Element ( Element . Types . Shadow )
2023-12-12 09:57:53 +01:00
Case " blank " , " "
2023-12-10 20:19:14 +01:00
Return New Element ( Element . Types . Blank )
Case Else
For Each e As Element In LoadedElements
2023-12-12 09:57:53 +01:00
If e . gmOriginalName . ToLower = Name . ToLower Then
2023-12-10 20:19:14 +01:00
Return e
End If
Next
End Select
Return Nothing
End Function
End Class
End Namespace