Implement Custom Types

This commit is contained in:
JappaWakka 2023-12-10 20:19:14 +01:00
parent 705e0b9725
commit a5e68a153a
15 changed files with 1227 additions and 868 deletions

View File

@ -28766,6 +28766,7 @@
<Compile Include="Pokemon\Abilities\Galvanize.vb" />
<Compile Include="Pokemon\Abilities\SurgeSurfer.vb" />
<Compile Include="Pokemon\Abilities\ParentalBond.vb" />
<Compile Include="Pokemon\Attacks\AttackSpecialBasePower.vb" />
<Compile Include="Pokemon\Attacks\Bug\PollenPuff.vb" />
<Compile Include="Pokemon\Attacks\Bug\FirstImpression.vb" />
<Compile Include="Pokemon\Attacks\Bug\FellStinger.vb" />
@ -28920,6 +28921,7 @@
<Compile Include="Pokemon\Items\Standard\ExpertBelt.vb" />
<Compile Include="Pokemon\Items\Stones\IceStone.vb" />
<Compile Include="Pokemon\Items\Stones\BlackAurugite.vb" />
<Compile Include="Pokemon\Monster\GameModeElementLoader.vb" />
<Compile Include="Resources\Blur\BlurHandler.vb" />
<Content Include="Content\Data\Scripts\faraway\mewtwonite_y.dat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

View File

@ -543,6 +543,7 @@
End If
GameModeManager.SetGameModePointer(GameMode)
BattleSystem.GameModeElementLoader.Load()
BattleSystem.GameModeAttackLoader.Load()
GameModeItemLoader.Load()

View File

@ -84,7 +84,11 @@
Case "accuracy", "acc"
move.Accuracy = CInt(value)
Case "type"
move.Type = New Element(value)
If StringHelper.IsNumeric(value) = False Then
move.Type = GameModeElementLoader.GetElementByName(value)
Else
move.Type = GameModeElementLoader.GetElementByID(CInt(value))
End If
Case "category"
Select Case value.ToLower()
Case "physical"

View File

@ -90,7 +90,7 @@ Namespace BattleSystem.Moves.Normal
If Not p.Item Is Nothing Then
If p.Item.isBerry = True Then
Return New Element(CType(p.Item, Items.Berry).Type)
Return BattleSystem.GameModeElementLoader.GetElementByID(CType(p.Item, Items.Berry).Type)
End If
End If

View File

@ -31,7 +31,7 @@
Public SummerGrow As Integer = 2
Public FallGrow As Integer = 1
Public Type As Element.Types
Public Type As Integer
Public Power As Integer = 80
Public JuiceColor As String = "red"

View File

@ -197,6 +197,7 @@ Public Class GameModeItem
Public Sub SetTeachMoveTextureRectangle()
Dim r As New Rectangle(144, 168, 24, 24)
If gmTeachMove.Type.IsGameModeElement = False Then
Select Case gmTeachMove.Type.Type
Case Element.Types.Blank, Element.Types.Normal
@ -236,6 +237,9 @@ Public Class GameModeItem
Case Element.Types.Water
r = New Rectangle(192, 168, 24, 24)
End Select
Else
r = gmTeachMove.Type.gmMachineTextureRectangle
End If
gmTextureRectangle = r
End Sub

View File

@ -200,7 +200,12 @@ Public Class GameModeItemLoader
ElseIf item.gmName.StartsWith("HM") Then
item.gmSortValue = -100000 + CInt(item.gmName.Remove(0, 2))
End If
If item.gmTeachMove.Type.IsGameModeElement = False Then
item.gmTextureSource = "Items\ItemSheet"
Else
item.gmTextureSource = item.gmTeachMove.Type.gmMachineTextureSource
End If
item.SetTeachMoveTextureRectangle()
End If

View File

@ -3,6 +3,8 @@
''' </summary>
Public Class Element
Public IsGameModeElement As Boolean = False
''' <summary>
''' The Type an Element can be.
''' </summary>
@ -30,18 +32,41 @@ Public Class Element
End Enum
Private _type As Types = Types.Blank
'GameMode Element Properties
Private gmType As Integer = 0
Public gmName As String = "Normal"
Public gmOriginalName As String = "Normal"
Public gmTypeRectangle As Rectangle = New Rectangle(0, 0, 48, 16)
Public gmMachineTextureSource As String = "Items\ItemSheet"
Public gmMachineTextureRectangle As Rectangle = New Rectangle(144, 168, 24, 24)
Public gmEffectivenessAttack As New Dictionary(Of Integer, Single)
Public gmEffectivenessDefense As New Dictionary(Of Integer, Single)
''' <summary>
''' The Type of this Element.
''' </summary>
Public Property Type As Types
Public Property Type As Integer
Get
If Me.IsGameModeElement = True Then
Return Me.gmType
Else
Return Me._type
End If
End Get
Set(value As Types)
Me._type = value
Set(value As Integer)
If Me.IsGameModeElement = True Then
Me.gmType = value
Else
Me._type = CType(value, Types)
End If
End Set
End Property
''' <summary>
''' Creates a new instance of the Element class for GameMode Elements.
''' </summary>
'''
Public Sub New()
End Sub
''' <summary>
''' Creates a new instance of the Element class.
@ -162,13 +187,15 @@ Public Class Element
Return 1
End If
If d._type = Types.Blank Or a._type = Types.Blank Then
If d.Type = Types.Blank Or a.Type = Types.Blank Then
Return 1
End If
Select Case a._type
If a.IsGameModeElement = False Then
If d.IsGameModeElement = False Then
Select Case a.Type
Case Types.Normal
Select Case d._type
Select Case d.Type
Case Types.Normal
Return 1
Case Types.Fighting
@ -207,7 +234,7 @@ Public Class Element
Return 1
End Select
Case Types.Fighting
Select Case d._type
Select Case d.Type
Case Types.Normal
Return 2
Case Types.Fighting
@ -248,7 +275,7 @@ Public Class Element
Return 1
End Select
Case Types.Flying
Select Case d._type
Select Case d.Type
Case Types.Normal
Return 1
Case Types.Fighting
@ -287,7 +314,7 @@ Public Class Element
Return 1
End Select
Case Types.Poison
Select Case d._type
Select Case d.Type
Case Types.Normal
Return 1
Case Types.Fighting
@ -328,7 +355,7 @@ Public Class Element
Return 1
End Select
Case Types.Ground
Select Case d._type
Select Case d.Type
Case Types.Normal
Return 1
Case Types.Fighting
@ -367,7 +394,7 @@ Public Class Element
Return 1
End Select
Case Types.Rock
Select Case d._type
Select Case d.Type
Case Types.Normal
Return 1
Case Types.Fighting
@ -406,7 +433,7 @@ Public Class Element
Return 1
End Select
Case Types.Bug
Select Case d._type
Select Case d.Type
Case Types.Normal
Return 1
Case Types.Fighting
@ -447,7 +474,7 @@ Public Class Element
Return 1
End Select
Case Types.Ghost
Select Case d._type
Select Case d.Type
Case Types.Normal
Return 0
Case Types.Fighting
@ -486,7 +513,7 @@ Public Class Element
Return 1
End Select
Case Types.Steel
Select Case d._type
Select Case d.Type
Case Types.Normal
Return 1
Case Types.Fighting
@ -527,7 +554,7 @@ Public Class Element
Return 1
End Select
Case Types.Fire
Select Case d._type
Select Case d.Type
Case Types.Normal
Return 1
Case Types.Fighting
@ -566,7 +593,7 @@ Public Class Element
Return 1
End Select
Case Types.Water
Select Case d._type
Select Case d.Type
Case Types.Normal
Return 1
Case Types.Fighting
@ -605,7 +632,7 @@ Public Class Element
Return 1
End Select
Case Types.Grass
Select Case d._type
Select Case d.Type
Case Types.Normal
Return 1
Case Types.Fighting
@ -644,7 +671,7 @@ Public Class Element
Return 1
End Select
Case Types.Electric
Select Case d._type
Select Case d.Type
Case Types.Normal
Return 1
Case Types.Fighting
@ -683,7 +710,7 @@ Public Class Element
Return 1
End Select
Case Types.Psychic
Select Case d._type
Select Case d.Type
Case Types.Normal
Return 1
Case Types.Fighting
@ -722,7 +749,7 @@ Public Class Element
Return 1
End Select
Case Types.Ice
Select Case d._type
Select Case d.Type
Case Types.Normal
Return 1
Case Types.Fighting
@ -761,7 +788,7 @@ Public Class Element
Return 1
End Select
Case Types.Dragon
Select Case d._type
Select Case d.Type
Case Types.Normal
Return 1
Case Types.Fighting
@ -802,7 +829,7 @@ Public Class Element
Return 1
End Select
Case Types.Dark
Select Case d._type
Select Case d.Type
Case Types.Normal
Return 1
Case Types.Fighting
@ -843,7 +870,7 @@ Public Class Element
Return 1
End Select
Case Types.Fairy
Select Case d._type
Select Case d.Type
Case Types.Fire
Return 0.5F
Case Types.Fighting
@ -858,7 +885,7 @@ Public Class Element
Return 0.5F
End Select
Case Types.Shadow
Select Case d._type
Select Case d.Type
Case Types.Shadow
Return 0.5F
Case Else
@ -867,6 +894,16 @@ Public Class Element
Case Else
Return 1
End Select
Else
If d.gmEffectivenessDefense.ContainsKey(a.Type) Then
Return d.gmEffectivenessDefense(a.Type)
End If
End If
Else
If a.gmEffectivenessDefense.ContainsKey(d.Type) Then
Return a.gmEffectivenessDefense(d.Type)
End If
End If
Return 1
End Function
@ -876,7 +913,7 @@ Public Class Element
''' </summary>
Public Function GetElementImage() As Rectangle
Dim r As New Rectangle(0, 0, 0, 0)
If Me.IsGameModeElement = False Then
Select Case Me._type
Case Types.Normal
r = New Rectangle(0, 0, 48, 16)
@ -921,11 +958,15 @@ Public Class Element
Case Else
r = New Rectangle(48, 112, 48, 16)
End Select
Else
r = gmTypeRectangle
End If
Return r
End Function
Public Overrides Function ToString() As String
If IsGameModeElement = False Then
Select Case Me._type
Case Types.Blank
Return "Blank"
@ -970,14 +1011,18 @@ Public Class Element
Case Else
Return "Blank"
End Select
Else
Return gmName
End If
End Function
Public Shared Operator =(ByVal Element1 As Element, ByVal Element2 As Element) As Boolean
Return Element1._type = Element2._type
Return Element1.Type = Element2.Type
End Operator
Public Shared Operator <>(ByVal Element1 As Element, ByVal Element2 As Element) As Boolean
Return Element1._type <> Element2._type
Return Element1.Type <> Element2.Type
End Operator
End Class

View File

@ -207,7 +207,7 @@ Public Class EvolutionCondition
Case ConditionTypes.InPartyType
Dim isInParty As Boolean = False
For Each pokemon As Pokemon In Core.Player.Pokemons
If pokemon.IsType(New Element(c.Argument).Type) = True Then
If pokemon.IsType(BattleSystem.GameModeElementLoader.GetElementByName(c.Argument).Type) = True Then
isInParty = True
Exit For
End If

View File

@ -0,0 +1,291 @@
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
Select Case data(i).GetSplit(0, ",")
Case "normal"
typeID = element.Types.Normal
Case "fighting"
typeID = element.Types.Fighting
Case "flying"
typeID = element.Types.Flying
Case "poison"
typeID = element.Types.Poison
Case "ground"
typeID = element.Types.Ground
Case "rock"
typeID = element.Types.Rock
Case "bug"
typeID = element.Types.Bug
Case "ghost"
typeID = element.Types.Ghost
Case "steel"
typeID = element.Types.Steel
Case "fire"
typeID = element.Types.Fire
Case "water"
typeID = element.Types.Water
Case "grass"
typeID = element.Types.Grass
Case "electric"
typeID = element.Types.Electric
Case "psychic"
typeID = element.Types.Psychic
Case "ice"
typeID = element.Types.Ice
Case "dragon"
typeID = element.Types.Dragon
Case "dark"
typeID = element.Types.Dark
Case "fairy"
typeID = element.Types.Fairy
Case "shadow"
typeID = element.Types.Shadow
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
Select Case data(i).GetSplit(0, ",")
Case "normal"
typeID = element.Types.Normal
Case "fighting"
typeID = element.Types.Fighting
Case "flying"
typeID = element.Types.Flying
Case "poison"
typeID = element.Types.Poison
Case "ground"
typeID = element.Types.Ground
Case "rock"
typeID = element.Types.Rock
Case "bug"
typeID = element.Types.Bug
Case "ghost"
typeID = element.Types.Ghost
Case "steel"
typeID = element.Types.Steel
Case "fire"
typeID = element.Types.Fire
Case "water"
typeID = element.Types.Water
Case "grass"
typeID = element.Types.Grass
Case "electric"
typeID = element.Types.Electric
Case "psychic"
typeID = element.Types.Psychic
Case "ice"
typeID = element.Types.Ice
Case "dragon"
typeID = element.Types.Dragon
Case "dark"
typeID = element.Types.Dark
Case "fairy"
typeID = element.Types.Fairy
Case "shadow"
typeID = element.Types.Shadow
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
element.gmName = Localization.GetString("move_name_" & element.gmOriginalName.ToString)
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)
Case "blank"
Return New Element(Element.Types.Blank)
Case Else
For Each e As Element In LoadedElements
If e.ToString.ToLower = Name.ToLower Then
Return e
End If
Next
End Select
Return Nothing
End Function
End Class
End Namespace

View File

@ -2951,7 +2951,7 @@ Public Class Pokemon
''' Checks if the Pokémon is of a certain type.
''' </summary>
''' <param name="CheckType">The type to check.</param>
Public Function IsType(ByVal CheckType As Element.Types) As Boolean
Public Function IsType(ByVal CheckType As Integer) As Boolean
If Type1.Type = CheckType Or Type2.Type = CheckType Then
Return True
End If

View File

@ -721,7 +721,7 @@
Public Daytime As Integer = -1
Public Weather As Integer = -1
Public Season As Integer = -1
Public Types As New List(Of Element.Types)
Public Types As New List(Of Integer)
Public Probability As Integer = 100
Public Sub New(ByVal dataLine As String)
@ -758,7 +758,7 @@
If dataParts(5) <> "-1" Then
For Each typePart As String In dataParts(5).Split(CChar(","))
Me.Types.Add(New Element(typePart).Type)
Me.Types.Add(BattleSystem.GameModeElementLoader.GetElementByName(typePart).Type)
Next
End If
@ -856,7 +856,7 @@
End If
If Me.Types.Count > 0 Then
For Each t As Element.Types In Me.Types
For Each t As Integer In Me.Types
If p.IsType(t) = False Then
Return False
End If

View File

@ -80,6 +80,8 @@ Public Class PokemonForms
form.WildFormTriggers.Add(arguments(10))
End If
If arguments.Count >= 12 Then
If StringHelper.IsNumeric(arguments(11)) = False Then
Select Case arguments(11).ToLower
Case "normal"
form.TypeChange = Element.Types.Normal
@ -122,6 +124,9 @@ Public Class PokemonForms
Case Else
form.TypeChange = Element.Types.Blank
End Select
Else
form.TypeChange = BattleSystem.GameModeElementLoader.GetElementByID(CInt(arguments(11))).Type
End If
If arguments.Count >= 13 Then
If arguments(12) <> "" Then
form.IncludeBaseFormInDexCount = CBool(arguments(12))
@ -562,7 +567,7 @@ Public Class PokemonForms
Public OverworldSpriteFileSuffix As String = ""
Public CryFileSuffix As String = ""
Public WildFormTriggers As New List(Of String)
Public TypeChange As Element.Types = Element.Types.Blank
Public TypeChange As Integer = Element.Types.Blank
Public IncludeBaseFormInDexCount As Boolean = False
Public Overridable Function GetInitialAdditionalData(ByVal P As Pokemon) As String
@ -587,13 +592,13 @@ Public Class PokemonForms
ElseIf trigger(0).ToLower = "gender" Then
If GetGenderFormMatch(P, True) = "match" Then
If TypeChange <> Element.Types.Blank Then
Return TypeChange.ToString
Return BattleSystem.GameModeElementLoader.GetElementByName(TypeChange).ToString
Else
Return AdditionalValue
End If
End If
ElseIf trigger(0).ToLower = "season" Then
If GetSeasonFormMatch(true) = "match" Then
If GetSeasonFormMatch(True) = "match" Then
If TypeChange <> Element.Types.Blank Then
Return TypeChange.ToString
Else

View File

@ -21,6 +21,7 @@
ContentPackManager.Load(GameController.GamePath & "\ContentPacks\" & s & "\exceptions.dat")
Next
BattleSystem.GameModeElementLoader.Load()
BattleSystem.GameModeAttackLoader.Load()
GameModeItemLoader.Load()

View File

@ -49,6 +49,7 @@
ContentPackManager.Load(GameController.GamePath & "\ContentPacks\" & s & "\exceptions.dat")
Next
BattleSystem.GameModeElementLoader.Load()
BattleSystem.GameModeAttackLoader.Load()
SmashRock.Load()