Reworked evolution system a bit. Now Held items are removed properly when a Trading + Held Item evolution condition occurs.

This commit is contained in:
CaptainSegis 2017-08-29 01:19:21 -05:00
parent 5bb1633633
commit 32a92eb7e3
4 changed files with 49 additions and 21 deletions

View File

@ -21,9 +21,9 @@ Public Class EvolutionCondition
Public Structure Condition Public Structure Condition
Dim ConditionType As ConditionTypes Dim ConditionType As ConditionTypes
Dim Argument As String Dim Argument As String
Dim Trigger As EvolutionTrigger
End Structure End Structure
Public Trigger As EvolutionTrigger
Public Evolution As Integer = 0 Public Evolution As Integer = 0
Public Conditions As New List(Of Condition) Public Conditions As New List(Of Condition)
@ -31,7 +31,7 @@ Public Class EvolutionCondition
Me.Evolution = evolution Me.Evolution = evolution
End Sub End Sub
Public Sub AddCondition(ByVal type As String, ByVal arg As String, ByVal trigger As String) Public Sub AddCondition(ByVal type As String, ByVal arg As String)
Dim c As New Condition Dim c As New Condition
c.Argument = arg c.Argument = arg
@ -67,19 +67,20 @@ Public Class EvolutionCondition
Case "weather" Case "weather"
c.ConditionType = ConditionTypes.Weather c.ConditionType = ConditionTypes.Weather
End Select End Select
Me.Conditions.Add(c)
End Sub
Public Sub SetTrigger(ByVal trigger As String)
Select Case trigger.ToLower() Select Case trigger.ToLower()
Case "none", "" Case "none", ""
c.Trigger = EvolutionTrigger.None Me.Trigger = EvolutionTrigger.None
Case "level", "levelup" Case "level", "levelup"
c.Trigger = EvolutionTrigger.LevelUp Me.Trigger = EvolutionTrigger.LevelUp
Case "trade", "trading" Case "trade", "trading"
c.Trigger = EvolutionTrigger.Trading Me.Trigger = EvolutionTrigger.Trading
Case "item", "itemuse" Case "item", "itemuse"
c.Trigger = EvolutionTrigger.ItemUse Me.Trigger = EvolutionTrigger.ItemUse
End Select End Select
Me.Conditions.Add(c)
End Sub End Sub
Public ReadOnly Property Count() As Integer Public ReadOnly Property Count() As Integer
@ -102,24 +103,31 @@ Public Class EvolutionCondition
''' <param name="trigger">The trigger that triggered the evolution.</param> ''' <param name="trigger">The trigger that triggered the evolution.</param>
''' <param name="arg">An argument (for example Item ID)</param> ''' <param name="arg">An argument (for example Item ID)</param>
Public Shared Function EvolutionNumber(ByVal p As Pokemon, ByVal trigger As EvolutionTrigger, ByVal arg As String) As Integer Public Shared Function EvolutionNumber(ByVal p As Pokemon, ByVal trigger As EvolutionTrigger, ByVal arg As String) As Integer
Dim e As EvolutionCondition = GetEvolutionCondition(p, trigger, arg)
If e Is Nothing Then
Return 0
Else
Return e.Evolution
End If
End Function
Public Shared Function GetEvolutionCondition(ByVal p As Pokemon, ByVal trigger As EvolutionTrigger, ByVal arg As String) As EvolutionCondition
If trigger = EvolutionTrigger.LevelUp Or trigger = EvolutionTrigger.Trading Then If trigger = EvolutionTrigger.LevelUp Or trigger = EvolutionTrigger.Trading Then
If Not p.Item Is Nothing Then If Not p.Item Is Nothing Then
If p.Item.ID = 112 Then If p.Item.ID = 112 Then
Return 0 Return Nothing
End If End If
End If End If
End If End If
Dim possibleEvolutions As New List(Of Integer) Dim possibleEvolutions As New List(Of EvolutionCondition)
For Each e As EvolutionCondition In p.EvolutionConditions For Each e As EvolutionCondition In p.EvolutionConditions
Dim canEvolve As Boolean = True Dim canEvolve As Boolean = True
For Each c As Condition In e.Conditions If trigger <> e.Trigger Then
If c.Trigger <> trigger Then canEvolve = False
canEvolve = False End If
End If
Next
If canEvolve = True Then If canEvolve = True Then
For Each c As Condition In e.Conditions For Each c As Condition In e.Conditions
@ -156,6 +164,8 @@ Public Class EvolutionCondition
Else Else
If p.Item.ID <> CInt(c.Argument) Then If p.Item.ID <> CInt(c.Argument) Then
canEvolve = False canEvolve = False
'ElseIf c.Trigger = EvolutionTrigger.Trading Then
'REMOVE HELD ITEM CHECK
End If End If
End If End If
Case ConditionTypes.InParty Case ConditionTypes.InParty
@ -220,15 +230,16 @@ Public Class EvolutionCondition
End If End If
If canEvolve = True Then If canEvolve = True Then
possibleEvolutions.Add(e.Evolution) possibleEvolutions.Add(e)
End If End If
Next Next
'Assuming there is never more than one possible evolution for trading + held item
If possibleEvolutions.Count > 0 Then If possibleEvolutions.Count > 0 Then
Return possibleEvolutions(Core.Random.Next(0, possibleEvolutions.Count)) Return possibleEvolutions(Core.Random.Next(0, possibleEvolutions.Count))
End If End If
Return 0 Return Nothing
End Function End Function
End Class End Class

View File

@ -1447,15 +1447,17 @@ Public Class Pokemon
Dim EvolutionExists As Boolean = False Dim EvolutionExists As Boolean = False
Dim e As EvolutionCondition = New EvolutionCondition Dim e As EvolutionCondition = New EvolutionCondition
e.SetTrigger(Trigger)
e.SetEvolution(Evolution)
For Each oldE As EvolutionCondition In Me.EvolutionConditions For Each oldE As EvolutionCondition In Me.EvolutionConditions
If Evolution = oldE.Evolution Then If e.Evolution = oldE.Evolution AndAlso e.Trigger = oldE.Trigger Then
e = oldE e = oldE
EvolutionExists = True EvolutionExists = True
End If End If
Next Next
e.SetEvolution(Evolution) e.AddCondition(Type, Argument)
e.AddCondition(Type, Argument, Trigger)
If EvolutionExists = False Then If EvolutionExists = False Then
EvolutionConditions.Add(e) EvolutionConditions.Add(e)

View File

@ -345,7 +345,7 @@
Case "moon ball" Case "moon ball"
For Each ev As EvolutionCondition In cp.EvolutionConditions For Each ev As EvolutionCondition In cp.EvolutionConditions
For Each con As EvolutionCondition.Condition In ev.Conditions For Each con As EvolutionCondition.Condition In ev.Conditions
If con.ConditionType = EvolutionCondition.ConditionTypes.Item And con.Argument = "8" And con.Trigger = EvolutionCondition.EvolutionTrigger.ItemUse Then If con.ConditionType = EvolutionCondition.ConditionTypes.Item And con.Argument = "8" And ev.Trigger = EvolutionCondition.EvolutionTrigger.ItemUse Then
BallRate = 4.0F BallRate = 4.0F
Exit For Exit For
End If End If

View File

@ -263,6 +263,21 @@
End If End If
End If End If
If Me.EvolutionTrigger = EvolutionCondition.EvolutionTrigger.Trading Then
Dim econ As EvolutionCondition = EvolutionCondition.GetEvolutionCondition(currentPokemon, Me.EvolutionTrigger, Me.EvolutionArg)
Dim removeItem As Boolean = False
If econ.Trigger = EvolutionCondition.EvolutionTrigger.Trading Then
For i = 0 To econ.Conditions.Count - 1
If econ.Conditions(i).ConditionType = EvolutionCondition.ConditionTypes.HoldItem Then
removeItem = True
End If
Next
End If
If removeItem Then
evolvedPokemon.Item = Nothing
End If
End If
Core.Player.AddPoints(10, "Evolved Pokémon.") Core.Player.AddPoints(10, "Evolved Pokémon.")
If ConnectScreen.Connected = True Then If ConnectScreen.Connected = True Then