Imports P3D.Items ''' ''' Provides an interface to load additional GameMode items. ''' Public Class GameModeItemLoader 'The default relative path to load items from (Content folder). Const PATH As String = "Data\Items\" 'List of loaded items. Shared LoadedItems As New List(Of GameModeItem) ''' ''' Load the attack list for the loaded GameMode. ''' ''' The game won't try to load the list if the default GameMode is selected. Public Shared Sub Load() LoadedItems.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") LoadItem(file) Next End If End If If LoadedItems.Count > 0 Then Logger.Debug("Loaded " & LoadedItems.Count.ToString() & " GameMode item(s).") End If End Sub ''' ''' Loads a item from a file. ''' ''' The file to load the item from. Private Shared Sub LoadItem(ByVal file As String) Dim item As New GameModeItem 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 item sets its ID. Dim setName As Boolean = False 'Controls if the item sets its ID. 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 key = l.Remove(l.IndexOf("|")) value = l.Remove(0, l.IndexOf("|") + 1) Select Case key.ToLower() Case "id" item.gmID = "gm" & CInt(value).ToString Dim itemX As Integer = CInt(value) Dim itemY As Integer = 0 Dim sheetWidth As Integer = CInt(TextureManager.GetTexture(item.gmTextureSource).Width / 24) While itemX > sheetWidth - 1 itemX -= sheetWidth itemY += 1 End While item.gmTextureRectangle = New Rectangle(CInt(itemX * 24), CInt(itemY * 24), 24, 24) setID = True Case "name" item.gmName = value setName = True Case "pluralname" item.gmPluralName = value Case "description" item.gmDescription = value Case "type" Select Case value.ToLower() Case "standard", "0" item.gmItemType = ItemTypes.Standard Case "medicine", "1" item.gmItemType = ItemTypes.Medicine Case "plants", "2" item.gmItemType = ItemTypes.Plants Case "balls", "pokeballs", "3" item.gmItemType = ItemTypes.Pokéballs Case "machines", "4" item.gmItemType = ItemTypes.Machines Case "keyitems", "5" item.gmItemType = ItemTypes.KeyItems Case "mail", "6" item.gmItemType = ItemTypes.Mail Case "battleitems", "7" item.gmItemType = ItemTypes.BattleItems End Select Case "canbeused" item.gmCanBeUsed = CBool(value) Case "canbeusedinbattle" item.gmCanBeUsedInBattle = CBool(value) Case "useonpokemoninbattle" item.gmBattleSelectPokemon = CBool(value) Case "canbetossed" item.gmCanBeTossed = CBool(value) Case "canbeheld" item.gmCanBeHeld = CBool(value) Case "canbetraded" item.gmCanBeTraded = CBool(value) Case "price" item.gmPrice = CInt(value) Case "battlepointsprice" item.gmBattlePointsPrice = CInt(value) Case "catchmultiplier" item.gmCatchMultiplier = CSng(value.ReplaceDecSeparator) Case "maxstack" item.gmMaxStack = CInt(value) Case "flingdamage" item.gmFlingDamage = CInt(value) Case "ishealingitem" item.gmIsHealingItem = CBool(value) Case "healhpamount" item.gmHealHPAmount = CInt(value) Case "curestatuseffects" Dim StatusEffectList As New List(Of String) Dim valueSplit As String() = value.Split(",") For i = 0 To valueSplit.Count - 1 Select Case valueSplit(i).ToLower Case "brn", "frz", "prz", "psn", "bpsn", "slp", "fnt", "confusion", "allwithoutfnt", "all" StatusEffectList.Add(valueSplit(i)) End Select Next If item.gmCureStatusEffects Is Nothing Then item.gmCureStatusEffects = StatusEffectList Else item.gmCureStatusEffects.AddRange(StatusEffectList) End If Case "isevolutionitem" item.gmIsEvolutionItem = CBool(value) Case "evolutionpokemon" Dim PokemonList As New List(Of Integer) Dim valueSplit As String() = value.Split(",") For i = 0 To valueSplit.Count - 1 If Pokemon.PokemonDataExists(CInt(valueSplit(i))) Then PokemonList.Add(CInt(valueSplit(i))) End If Next If item.gmEvolutionPokemon Is Nothing Then item.gmEvolutionPokemon = PokemonList Else item.gmEvolutionPokemon.AddRange(PokemonList) End If End Select End If Next Catch ex As Exception 'If an error occurs loading a item, log the error. Logger.Log(Logger.LogTypes.ErrorMessage, "GameModeItemLoader.vb: Error loading GameMode Item from file """ & file & """: " & ex.Message & "; Last Key/Value pair successfully loaded: " & key & "|" & value) End Try If setID = True AndAlso setName = True Then If item.gmIsMegaStone = True AndAlso item.gmMegaPokemonNumber <> Nothing AndAlso item.gmDescription = "" Then Dim MegaPokemonName As String = Pokemon.GetPokemonByID(item.gmMegaPokemonNumber, item.AdditionalData).GetName item.gmDescription = "One variety of the mysterious Mega Stones. Have " & MegaPokemonName & " hold it, and this stone will enable it to Mega Evolve during battle." item.gmCanBeTossed = False item.gmCanBeTraded = False item.gmCanBeUsed = False item.gmCanBeUsedInBattle = False End If LoadedItems.Add(item) 'Add the item. Else Logger.Log(Logger.LogTypes.ErrorMessage, "GameModeItemLoader.vb: User defined Items must set their ID through the ""ID"" property and their Name through the ""Name"" property, however the item loaded from """ & file & """ has no ID or Name set so it will be ignored.") End If End Sub ''' ''' Returns a custom item based on its ID. ''' ''' The ID of the custom item. ''' Returns a item or nothing. Public Shared Function GetItemByID(ByVal ID As String) As GameModeItem For Each i As GameModeItem In LoadedItems If i.gmID = ID Then Return i End If Next Return Nothing End Function Public Shared Function GetItemByName(ByVal Name As String) As GameModeItem For Each i As GameModeItem In LoadedItems If i.gmName.ToLowerInvariant() = Name.ToLowerInvariant() Then Return i End If Next Return Nothing End Function End Class