From daef33a8862dde7ce0874713a2d64721f0441e6e Mon Sep 17 00:00:00 2001 From: JappaWakka Date: Sun, 26 Feb 2023 15:26:07 +0100 Subject: [PATCH] =?UTF-8?q?Prevent=20wild=20&=20trainer=20battles=20withou?= =?UTF-8?q?t=20pok=C3=A9mon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit when the player has no Pokémon in their team, wild and trainer battle commands don't do anything --- .../V2/ScriptCommands/DoBattle.vb | 247 +++++++++--------- P3D/World/Level.vb | 4 +- 2 files changed, 132 insertions(+), 119 deletions(-) diff --git a/P3D/World/ActionScript/V2/ScriptCommands/DoBattle.vb b/P3D/World/ActionScript/V2/ScriptCommands/DoBattle.vb index 3e5bec03e..b1f00fe6f 100644 --- a/P3D/World/ActionScript/V2/ScriptCommands/DoBattle.vb +++ b/P3D/World/ActionScript/V2/ScriptCommands/DoBattle.vb @@ -12,162 +12,173 @@ Select Case command.ToLower() Case "starttrainer" - Dim t As New Trainer(argument) - If t.IsBeaten() = False Then - If ScriptV2.started = False Then - CType(Core.CurrentScreen, OverworldScreen).TrainerEncountered = True + If Core.Player.Pokemons.Count > 0 Then + Dim t As New Trainer(argument) + If t.IsBeaten() = False Then + If ScriptV2.started = False Then + CType(Core.CurrentScreen, OverworldScreen).TrainerEncountered = True - If t.GetInSightMusic() <> "" And t.GetInSightMusic() <> "nomusic" Then - MusicManager.Play(t.GetInSightMusic(), True, 0.0F) - End If + If t.GetInSightMusic() <> "" And t.GetInSightMusic() <> "nomusic" Then + MusicManager.Play(t.GetInSightMusic(), True, 0.0F) + End If - If t.IntroMessage <> "" Then - Screen.TextBox.reDelay = 0.0F - Screen.TextBox.Show(t.IntroMessage, {}) + If t.IntroMessage <> "" Then + Screen.TextBox.reDelay = 0.0F + Screen.TextBox.Show(t.IntroMessage, {}) + End If + ScriptV2.started = True End If - ScriptV2.started = True + If Screen.TextBox.Showing = False Then + CType(Core.CurrentScreen, OverworldScreen).TrainerEncountered = False + + Dim method As Integer = 0 + If Screen.Level.Surfing = True Then + method = 2 + End If + + Dim b As New BattleSystem.BattleScreen(New Trainer(argument), Core.CurrentScreen, method) + Core.SetScreen(New BattleIntroScreen(Core.CurrentScreen, b, t, t.GetIniMusicName(), t.IntroType)) + End If + Else + Screen.TextBox.reDelay = 0.0F + Screen.TextBox.Show(t.DefeatMessage, {}) + + IsReady = True End If + If Screen.TextBox.Showing = False Then - CType(Core.CurrentScreen, OverworldScreen).TrainerEncountered = False - - Dim method As Integer = 0 - If Screen.Level.Surfing = True Then - method = 2 - End If - - Dim b As New BattleSystem.BattleScreen(New Trainer(argument), Core.CurrentScreen, method) - Core.SetScreen(New BattleIntroScreen(Core.CurrentScreen, b, t, t.GetIniMusicName(), t.IntroType)) + IsReady = True End If + + CanContinue = False Else - Screen.TextBox.reDelay = 0.0F - Screen.TextBox.Show(t.DefeatMessage, {}) - IsReady = True End If - - If Screen.TextBox.Showing = False Then - IsReady = True - End If - - CanContinue = False Case "trainer" - Dim ID As String = argument + If Core.Player.Pokemons.Count > 0 Then + Dim ID As String = argument - If argument.CountSeperators(",") > 0 Then - ID = argument.GetSplit(0) + If argument.CountSeperators(",") > 0 Then + ID = argument.GetSplit(0) - For Each v As String In argument.Split(CChar(",")) - Select Case v - Case "generate_pokemon_tower" - Dim level As Integer = 0 - For Each p As Pokemon In Core.Player.Pokemons - If p.Level > level Then - level = p.Level - End If - Next + For Each v As String In argument.Split(CChar(",")) + Select Case v + Case "generate_pokemon_tower" + Dim level As Integer = 0 + For Each p As Pokemon In Core.Player.Pokemons + If p.Level > level Then + level = p.Level + End If + Next - While CStr(level)(CStr(level).Length - 1) <> "0" - level += 1 - End While - End Select - Next + While CStr(level)(CStr(level).Length - 1) <> "0" + level += 1 + End While + End Select + Next + End If + + Dim t As New Trainer(ID) + + Dim method As Integer = 0 + If Screen.Level.Surfing = True Then + method = 2 + End If + + Dim b As New BattleSystem.BattleScreen(t, Core.CurrentScreen, method) + Core.SetScreen(New BattleIntroScreen(Core.CurrentScreen, b, t, t.GetIniMusicName(), t.IntroType)) + + IsReady = True + + CanContinue = False + Else + IsReady = True End If - - Dim t As New Trainer(ID) - - Dim method As Integer = 0 - If Screen.Level.Surfing = True Then - method = 2 - End If - - Dim b As New BattleSystem.BattleScreen(t, Core.CurrentScreen, method) - Core.SetScreen(New BattleIntroScreen(Core.CurrentScreen, b, t, t.GetIniMusicName(), t.IntroType)) - - IsReady = True - - CanContinue = False Case "wild" ' ID, Level, [shiny], [musicloop], [introtype] ' int int -1 or bool string int ' optional: ' {pokemondata}, [musicloop], [introtype] + If Core.Player.Pokemons.Count > 0 Then + Dim p As Pokemon = Nothing + Dim musicLoop As String = "" + Dim introType As Integer = Core.Random.Next(0, 10) - Dim p As Pokemon = Nothing - Dim musicLoop As String = "" - Dim introType As Integer = Core.Random.Next(0, 10) + Dim method As Integer = 0 + If Screen.Level.Surfing = True Then + method = 2 + End If - Dim method As Integer = 0 - If Screen.Level.Surfing = True Then - method = 2 - End If + If argument.StartsWith("{") = True And argument.Contains("}") = True Then + If argument.EndsWith("}") = True Then + p = Pokemon.GetPokemonByData(argument) + Else + Dim pokemonData As String = argument.Remove(argument.LastIndexOf("}") + 1) + p = Pokemon.GetPokemonByData(pokemonData) - If argument.StartsWith("{") = True And argument.Contains("}") = True Then - If argument.EndsWith("}") = True Then - p = Pokemon.GetPokemonByData(argument) + argument = argument.Remove(0, argument.LastIndexOf("}") + 1) + + If argument.Length > 1 And argument.StartsWith(",") = True Then + argument = argument.Remove(0, 1) + Dim args() As String = argument.Split(CChar(",")) + + For i = 0 To args.Length - 1 + Select Case i + Case 0 + musicLoop = args(i) + Case 1 + introType = int(args(i)) + End Select + Next + End If + End If Else - Dim pokemonData As String = argument.Remove(argument.LastIndexOf("}") + 1) - p = Pokemon.GetPokemonByData(pokemonData) + If argument.Length > 0 Then + Dim ID As Integer = int(argument.GetSplit(0).Split(CChar("_"))(0)) + Dim AD As String = "" + If argument.GetSplit(0).Contains(CChar("_")) Then + AD = argument.GetSplit(0).Split(CChar("_"))(1) + End If + Dim Level As Integer = int(argument.GetSplit(1)) + + If AD IsNot "" Then + p = Pokemon.GetPokemonByID(ID, AD) + p.Generate(Level, True, AD) + Else + p = Pokemon.GetPokemonByID(ID) + p.Generate(Level, True) + + End If - argument = argument.Remove(0, argument.LastIndexOf("}") + 1) - If argument.Length > 1 And argument.StartsWith(",") = True Then - argument = argument.Remove(0, 1) Dim args() As String = argument.Split(CChar(",")) For i = 0 To args.Length - 1 Select Case i - Case 0 + Case 2 + If args(i) <> "-1" Then + p.IsShiny = CBool(args(i)) + End If + Case 3 musicLoop = args(i) - Case 1 + Case 4 introType = int(args(i)) End Select Next End If End If + + Core.Player.PokedexData = Pokedex.ChangeEntry(Core.Player.PokedexData, p.Number, 1) + Dim b As New BattleSystem.BattleScreen(p, Core.CurrentScreen, method) + Core.SetScreen(New BattleIntroScreen(Core.CurrentScreen, b, introType, musicLoop)) + + IsReady = True + + CanContinue = False Else - If argument.Length > 0 Then - Dim ID As Integer = int(argument.GetSplit(0).Split(CChar("_"))(0)) - Dim AD As String = "" - If argument.GetSplit(0).Contains(CChar("_")) Then - AD = argument.GetSplit(0).Split(CChar("_"))(1) - End If - Dim Level As Integer = int(argument.GetSplit(1)) - - If AD IsNot "" Then - p = Pokemon.GetPokemonByID(ID, AD) - p.Generate(Level, True, AD) - Else - p = Pokemon.GetPokemonByID(ID) - p.Generate(Level, True) - - End If - - - Dim args() As String = argument.Split(CChar(",")) - - For i = 0 To args.Length - 1 - Select Case i - Case 2 - If args(i) <> "-1" Then - p.IsShiny = CBool(args(i)) - End If - Case 3 - musicLoop = args(i) - Case 4 - introType = int(args(i)) - End Select - Next - End If + IsReady = True End If - - Core.Player.PokedexData = Pokedex.ChangeEntry(Core.Player.PokedexData, p.Number, 1) - Dim b As New BattleSystem.BattleScreen(p, Core.CurrentScreen, method) - Core.SetScreen(New BattleIntroScreen(Core.CurrentScreen, b, introType, musicLoop)) - - IsReady = True - - CanContinue = False Case "setvar" Dim varname As String = argument.GetSplit(0) Dim varvalue As String = argument.GetSplit(1) diff --git a/P3D/World/Level.vb b/P3D/World/Level.vb index ee3cf091d..735df3245 100644 --- a/P3D/World/Level.vb +++ b/P3D/World/Level.vb @@ -849,7 +849,9 @@ Public Class Level Me._backdropRenderer.Update() Me.UpdatePlayerWarp() - Me._pokemonEncounter.TriggerBattle() + If Core.Player.Pokemons.Count > 0 Then + Me._pokemonEncounter.TriggerBattle() + End If ' Reload map from file (Debug or Sandbox Mode): If GameController.IS_DEBUG_ACTIVE = True Or Core.Player.SandBoxMode = True Then