Properly implemented after faint switch by using query objects. Fixed small bug related to offline saves.

This commit is contained in:
CaptainSegis 2017-09-28 22:23:35 -05:00
parent 2068159522
commit 326916231a
7 changed files with 47 additions and 60 deletions

View File

@ -4416,8 +4416,7 @@
BattleScreen.OwnFaint = True BattleScreen.OwnFaint = True
If BattleScreen.IsRemoteBattle AndAlso BattleScreen.IsHost Then If BattleScreen.IsRemoteBattle AndAlso BattleScreen.IsHost Then
Logger.Debug("[Battle]: The host's pokemon faints") Logger.Debug("[Battle]: The host's pokemon faints")
Core.ServersManager.ServerConnection.SendPackage(New Servers.Package(Servers.Package.PackageTypes.BattleHostData, BattleScreen.BattleQuery.Add(New AfterFaintQueryObject(True))
Core.ServersManager.ID, Servers.Package.ProtocolTypes.TCP, {BattleScreen.PartnerNetworkID.ToString(), "-HostFainted-"}.ToList()))
End If End If
SwitchOutOwn(BattleScreen, -1, -1) SwitchOutOwn(BattleScreen, -1, -1)
End If End If
@ -4426,8 +4425,7 @@
BattleScreen.OppFaint = True BattleScreen.OppFaint = True
If BattleScreen.IsRemoteBattle AndAlso BattleScreen.IsHost Then If BattleScreen.IsRemoteBattle AndAlso BattleScreen.IsHost Then
Logger.Debug("[Battle]: The client's pokemon faints") Logger.Debug("[Battle]: The client's pokemon faints")
Core.ServersManager.ServerConnection.SendPackage(New Servers.Package(Servers.Package.PackageTypes.BattleHostData, BattleScreen.BattleQuery.Add(New AfterFaintQueryObject(False))
Core.ServersManager.ID, Servers.Package.ProtocolTypes.TCP, {BattleScreen.PartnerNetworkID.ToString(), "-ClientFainted-"}.ToList()))
End If End If
If BattleScreen.IsTrainerBattle = True Then If BattleScreen.IsTrainerBattle = True Then
If BattleScreen.Trainer.HasBattlePokemon() = True Then If BattleScreen.Trainer.HasBattlePokemon() = True Then
@ -6610,8 +6608,8 @@
End Enum End Enum
Public Sub EndBattle(ByVal reason As EndBattleReasons, ByVal BattleScreen As BattleScreen, ByVal AddPVP As Boolean) Public Sub EndBattle(ByVal reason As EndBattleReasons, ByVal BattleScreen As BattleScreen, ByVal AddPVP As Boolean)
BattleSystem.BattleScreen.OwnFaint = False BattleScreen.OwnFaint = False
BattleSystem.BattleScreen.OppFaint = False BattleScreen.OppFaint = False
IsAfterFaint = False IsAfterFaint = False
If AddPVP = True Then If AddPVP = True Then
Select Case reason Select Case reason

View File

@ -944,7 +944,7 @@
Else Else
If TempBattleScreen.OwnPokemonIndex <> PokeIndex Then If TempBattleScreen.OwnPokemonIndex <> PokeIndex Then
If TempBattleScreen.IsRemoteBattle = True And TempBattleScreen.IsHost = False Then If TempBattleScreen.IsRemoteBattle = True And TempBattleScreen.IsHost = False Then
BattleScreen.OppFaint = False TempBattleScreen.OppFaint = False
TempBattleScreen.OwnStatistics.Switches += 1 TempBattleScreen.OwnStatistics.Switches += 1
TempBattleScreen.BattleQuery.Clear() TempBattleScreen.BattleQuery.Clear()
TempBattleScreen.BattleQuery.Add(TempBattleScreen.FocusBattle()) TempBattleScreen.BattleQuery.Add(TempBattleScreen.FocusBattle())

View File

@ -5,8 +5,8 @@
Inherits Screen Inherits Screen
'Used for after fainting switching 'Used for after fainting switching
Public Shared OwnFaint As Boolean = False Public OwnFaint As Boolean = False
Public Shared OppFaint As Boolean = False Public OppFaint As Boolean = False
'Used for lead picking in PvP Battles 'Used for lead picking in PvP Battles
Public Shared OwnLeadIndex As Integer = 0 Public Shared OwnLeadIndex As Integer = 0
@ -118,9 +118,6 @@
Me.IsTrainerBattle = False Me.IsTrainerBattle = False
Me.MouseVisible = False Me.MouseVisible = False
Me.PVPGameJoltID = "" Me.PVPGameJoltID = ""
OppFaint = False
OwnFaint = False
End Sub End Sub
Public Sub New(ByVal Trainer As Trainer, ByVal OverworldScreen As Screen, ByVal defaultMapType As Integer) Public Sub New(ByVal Trainer As Trainer, ByVal OverworldScreen As Screen, ByVal defaultMapType As Integer)
@ -130,9 +127,6 @@
Me.IsTrainerBattle = True Me.IsTrainerBattle = True
Me.MouseVisible = False Me.MouseVisible = False
Me.PVPGameJoltID = "" Me.PVPGameJoltID = ""
OppFaint = False
OwnFaint = False
End Sub End Sub
#Region "Initialize" #Region "Initialize"
@ -1307,8 +1301,6 @@ nextIndex:
Battle.Won = True Battle.Won = True
EndBattle(False) EndBattle(False)
PVPLobbyScreen.BattleSuccessful = False PVPLobbyScreen.BattleSuccessful = False
OwnFaint = False
OppFaint = False
Return False Return False
End If End If
Else Else
@ -1318,8 +1310,6 @@ nextIndex:
Battle.Won = False Battle.Won = False
EndBattle(False) EndBattle(False)
PVPLobbyScreen.BattleSuccessful = False PVPLobbyScreen.BattleSuccessful = False
OwnFaint = False
OppFaint = False
Return False Return False
End If End If
End If End If
@ -1435,15 +1425,6 @@ nextIndex:
s = s.PreScreen s = s.PreScreen
End While End While
If s.Identification = Identifications.BattleScreen Then If s.Identification = Identifications.BattleScreen Then
If data = "-HostFainted-" Then
Logger.Debug("[Battle]: The host's pokemon faints")
OppFaint = True
Exit Sub
ElseIf data = "-ClientFainted-" Then
Logger.Debug("[Battle]: The client's pokemon faints")
OwnFaint = True
Exit Sub
Else
If GameController.IS_DEBUG_ACTIVE Then If GameController.IS_DEBUG_ACTIVE Then
If Directory.Exists(GameController.GamePath & "\PvP Log\") = False Then If Directory.Exists(GameController.GamePath & "\PvP Log\") = False Then
Directory.CreateDirectory(GameController.GamePath & "\PvP Log\") Directory.CreateDirectory(GameController.GamePath & "\PvP Log\")
@ -1452,7 +1433,6 @@ nextIndex:
IO.File.WriteAllText(GameController.GamePath & "\PvP Log\HostData.dat", shownData) IO.File.WriteAllText(GameController.GamePath & "\PvP Log\HostData.dat", shownData)
End If End If
End If End If
End If
While cData.Length > 0 While cData.Length > 0
If cData(0).ToString() = "|" AndAlso tempData(tempData.Length - 1).ToString() = "}" Then If cData(0).ToString() = "|" AndAlso tempData(tempData.Length - 1).ToString() = "}" Then
@ -1519,13 +1499,14 @@ nextIndex:
s = s.PreScreen s = s.PreScreen
End While End While
CType(s, BattleScreen).BattleMenu.Visible = False Dim BV2Screen As BattleScreen = CType(s, BattleScreen)
BV2Screen.BattleMenu.Visible = False
'prevents multi turn action to take place in an after fainting switching turn 'prevents multi turn action to take place in an after fainting switching turn
If Not (OppFaint And CType(s, BattleScreen).IsRemoteBattle) Then If Not (BV2Screen.OppFaint And BV2Screen.IsRemoteBattle) Then
CType(s, BattleScreen).Battle.StartMultiTurnAction(CType(s, BattleScreen)) BV2Screen.Battle.StartMultiTurnAction(BV2Screen)
Else Else
CType(s, BattleScreen).BattleMenu.Visible = True BV2Screen.BattleMenu.Visible = True
End If End If
End Sub End Sub

View File

@ -4,39 +4,49 @@
Inherits QueryObject Inherits QueryObject
Private _delay As Integer = 0 Private _isHost As Boolean
Private _ready As Boolean = False
Public Sub New(ByVal Delay As Integer) Public Sub New(ByVal IsHost As Boolean)
MyBase.New(QueryTypes.Delay) MyBase.New(QueryTypes.AfterFaint)
_isHost = IsHost
Me._delay = Delay
End Sub End Sub
Public Overrides Sub Update(BV2Screen As BattleScreen) Public Overrides Sub Update(BV2Screen As BattleScreen)
If Me._delay > 0 Then If BV2Screen.IsHost Then
Me._delay -= 1 If _isHost Then
BV2Screen.OwnFaint = True
Else
BV2Screen.OppFaint = True
End If End If
Else
If _isHost Then
Logger.Debug("[Battle]: The host's pokemon faints")
BV2Screen.OppFaint = True
Else
Logger.Debug("[Battle]: The client's pokemon faints")
BV2Screen.OwnFaint = True
End If
End If
Me._ready = True
End Sub End Sub
Public Overrides ReadOnly Property IsReady As Boolean Public Overrides ReadOnly Property IsReady As Boolean
Get Get
If Me._delay = 0 Then Return _ready
Return True
End If
Return False
End Get End Get
End Property End Property
Public Overrides Function NeedForPVPData() As Boolean Public Overrides Function NeedForPVPData() As Boolean
Return True Return False
End Function End Function
Public Shared Shadows Function FromString(input As String) As QueryObject Public Shared Shadows Function FromString(input As String) As QueryObject
Return New DelayQueryObject(CInt(input)) Return New AfterFaintQueryObject(CBool(input))
End Function End Function
Public Overrides Function ToString() As String Public Overrides Function ToString() As String
Return "{DELAY|" & Me._delay.ToString() & "}" Return "{FAINT|" & Me._isHost.ToString() & "}"
End Function End Function
End Class End Class

View File

@ -22,6 +22,7 @@
DisplayLevelUp DisplayLevelUp
PlaySound PlaySound
MoveAnimation MoveAnimation
AfterFaint
End Enum End Enum
Public QueryType As QueryTypes = QueryTypes.CameraMovement Public QueryType As QueryTypes = QueryTypes.CameraMovement
@ -88,6 +89,8 @@
Return ToggleMenuQueryObject.FromString(Data) Return ToggleMenuQueryObject.FromString(Data)
Case "TRIGGERNEWROUNDPVP" Case "TRIGGERNEWROUNDPVP"
Return TriggerNewRoundPVPQueryObject.FromString(Data) Return TriggerNewRoundPVPQueryObject.FromString(Data)
Case "FAINT"
Return AfterFaintQueryObject.FromString(Data)
End Select End Select
Catch ex As Exception Catch ex As Exception
Logger.Debug("QueryObject.vb: Wrong data received, could not convert to [" & Type & "] query object. Return Nothing.") Logger.Debug("QueryObject.vb: Wrong data received, could not convert to [" & Type & "] query object. Return Nothing.")

View File

@ -628,8 +628,6 @@
MusicManager.PlayMusic("lobby", False) MusicManager.PlayMusic("lobby", False)
Core.Player.Pokemons.Clear() Core.Player.Pokemons.Clear()
Core.Player.Pokemons.AddRange(TempOriginalTeam.ToArray()) Core.Player.Pokemons.AddRange(TempOriginalTeam.ToArray())
BattleSystem.BattleScreen.OwnFaint = False
BattleSystem.BattleScreen.OppFaint = False
End If End If
End Sub End Sub
@ -682,8 +680,6 @@
Else Else
PlayerStatistics.Track("PVP Losses", 1) PlayerStatistics.Track("PVP Losses", 1)
End If End If
BattleSystem.BattleScreen.OwnFaint = False
BattleSystem.BattleScreen.OppFaint = False
End Sub End Sub
Private Sub DrawBattleResults() Private Sub DrawBattleResults()

View File

@ -257,10 +257,9 @@
Core.ServersManager.ServerConnection.Disconnect() Core.ServersManager.ServerConnection.Disconnect()
End If End If
Chat.ClearChat() Chat.ClearChat()
If Core.Player.loadedSave = True And Me.canCreateAutosave = True Then 'If Core.Player.loadedSave = True And Me.canCreateAutosave = True Then
'Core.Player.SaveGame(True) ' Core.Player.SaveGame(False)
Core.Player.SaveGame(False) 'End If
End If
ScriptStorage.Clear() ScriptStorage.Clear()
Core.SetScreen(New PressStartScreen()) Core.SetScreen(New PressStartScreen())
Core.Player.loadedSave = False Core.Player.loadedSave = False