From dae406f8872b05595dbb29098827924e20339010 Mon Sep 17 00:00:00 2001 From: JappaWakka Date: Sun, 29 Oct 2023 17:59:39 +0100 Subject: [PATCH] Added Step Script commands & constructs @Player.SetScriptSteps(stepAmount,scriptPath) Executes a script file after having moved the given amount of steps. @Player.ClearScriptSteps Clears the register created with @Player.SetScriptSteps, preventing the script from being executed. Returns the amount of steps before the script as defined by @Player.SetScriptSteps is executed. --- P3D/Player/Player.vb | 43 +++++++++++++++++++ .../V2/ScriptCommands/DoPlayer.vb | 12 ++++++ .../V2/ScriptConstructs/DoPlayer.vb | 2 + P3D/World/ActionScript/V2/ScriptLibrary.vb | 3 ++ 4 files changed, 60 insertions(+) diff --git a/P3D/Player/Player.vb b/P3D/Player/Player.vb index 669b93a4e..fb7778001 100644 --- a/P3D/Player/Player.vb +++ b/P3D/Player/Player.vb @@ -151,6 +151,15 @@ End Set End Property + Public Property ScriptSteps() As Integer + Get + Return _scriptSteps + End Get + Set(value As Integer) + _scriptSteps = value + End Set + End Property + Public Property SaveCreated() As String Get Return _saveCreated @@ -399,6 +408,7 @@ Private _lastSavePlace As String = "yourroom.dat" Private _lastSavePlacePosition As String = "1,0.1,3" Private _repelSteps As Integer = 0 + Private _scriptSteps As Integer = 0 Private _saveCreated As String = "Pre 0.21" Private _daycareSteps As Integer = 0 Private _poisonSteps As Integer = 0 @@ -849,6 +859,8 @@ End If Case "repelsteps" RepelSteps = CInt(Value) + Case "scriptsteps" + ScriptSteps = CInt(Value) Case "lastsaveplace" LastSavePlace = Value Case "lastsaveplaceposition" @@ -1347,6 +1359,7 @@ "LastRestPlacePosition|" & LastRestPlacePosition & Environment.NewLine & "DiagonalMovement|" & DiagonalMovement.ToNumberString() & Environment.NewLine & "RepelSteps|" & RepelSteps.ToString() & Environment.NewLine & + "ScriptSteps|" & ScriptSteps.ToString() & Environment.NewLine & "LastSavePlace|" & LastSavePlace & Environment.NewLine & "LastSavePlacePosition|" & LastSavePlacePosition & Environment.NewLine & "Difficulty|" & DifficultyMode.ToString() & Environment.NewLine & @@ -1779,6 +1792,7 @@ StepEventCheckTrainers() StepEventCheckEggHatching(stepAmount) StepEventCheckRepel(stepAmount) + StepEventCheckScript(stepAmount) StepEventWildPokemon() StepEventPokegearCall() Else @@ -1872,6 +1886,35 @@ End If End Sub + Private Sub StepEventCheckScript(ByVal stepAmount As Integer) + If ScriptSteps > 0 Then + ScriptSteps -= stepAmount + + If ScriptSteps <= 0 Then + If CurrentScreen.Identification = Screen.Identifications.OverworldScreen Then + If CanFireStepEvent() = True Then + Dim registerContent() As Object = ActionScript.GetRegisterValue("SCRIPTSTEPS") + + If registerContent(0) Is Nothing Or registerContent(1) Is Nothing Then + Logger.Log(Logger.LogTypes.Warning, "ScriptComparer.vb: No valid script has been set to be executed.") + ActionScript.UnregisterID("SCRIPTSTEPS", "str") + ActionScript.UnregisterID("SCRIPTSTEPS") + Exit Sub + End If + + Dim lValue As String = CStr(registerContent(0)) + + CType(CurrentScreen, OverworldScreen).ActionScript.StartScript(lValue, 0, False) + ActionScript.UnregisterID("SCRIPTSTEPS", "str") + ActionScript.UnregisterID("SCRIPTSTEPS") + Else + ScriptSteps = 1 + End If + End If + End If + End If + End Sub + Private Sub StepEventWildPokemon() If CanFireStepEvent() = True Then If Screen.Level.WildPokemonFloor = True And Screen.Level.Surfing = False Then diff --git a/P3D/World/ActionScript/V2/ScriptCommands/DoPlayer.vb b/P3D/World/ActionScript/V2/ScriptCommands/DoPlayer.vb index 179ea9682..974ee1187 100644 --- a/P3D/World/ActionScript/V2/ScriptCommands/DoPlayer.vb +++ b/P3D/World/ActionScript/V2/ScriptCommands/DoPlayer.vb @@ -376,6 +376,18 @@ Dim newOpacity As Single = sng(argument.Replace("~", Screen.Level.OwnPlayer.Opacity.ToString().Replace(".", GameController.DecSeparator))) Screen.Level.OwnPlayer.Opacity = newOpacity IsReady = True + Case "setscriptsteps" + If argument.Contains(",") = True Then + Dim args() As String = argument.Split(CChar(",")) + Core.Player.ScriptSteps = CInt(args(0)) + ActionScript.RegisterID("SCRIPTSTEPS", "str", args(1)) + End If + IsReady = True + Case "clearscriptsteps" + ActionScript.UnregisterID("SCRIPTSTEPS", "str") + ActionScript.UnregisterID("SCRIPTSTEPS") + Core.Player.ScriptSteps = 0 + IsReady = True Case Else IsReady = True End Select diff --git a/P3D/World/ActionScript/V2/ScriptConstructs/DoPlayer.vb b/P3D/World/ActionScript/V2/ScriptConstructs/DoPlayer.vb index 205fbbc02..6da561046 100644 --- a/P3D/World/ActionScript/V2/ScriptConstructs/DoPlayer.vb +++ b/P3D/World/ActionScript/V2/ScriptConstructs/DoPlayer.vb @@ -127,6 +127,8 @@ ReturnBoolean(Core.Player.IsGameJoltSave = True AndAlso GameJolt.LogInScreen.UserBanned(GameJoltSave.GameJoltID) = False) End If Return ReturnBoolean(Core.Player.IsGameJoltSave) + Case "scriptsteps" + Return Core.Player.ScriptSteps End Select Return DEFAULTNULL End Function diff --git a/P3D/World/ActionScript/V2/ScriptLibrary.vb b/P3D/World/ActionScript/V2/ScriptLibrary.vb index 6b1f89d96..c92bbfd04 100644 --- a/P3D/World/ActionScript/V2/ScriptLibrary.vb +++ b/P3D/World/ActionScript/V2/ScriptLibrary.vb @@ -518,6 +518,8 @@ Namespace ScriptVersion2 r(New ScriptCommand("player", "setrivalname", {New ScriptArgument("name", ScriptArgument.ArgumentTypes.Str)}.ToList(), "Sets the rival's name.")) r(New ScriptCommand("player", "setrivalskin", {New ScriptArgument("skin", ScriptArgument.ArgumentTypes.Str)}.ToList(), "Sets the rival's skin.")) r(New ScriptCommand("player", "setopacity", {New ScriptArgument("opacity", ScriptArgument.ArgumentTypes.Sng)}.ToList(), "Sets the player entity's opacity.")) + r(New ScriptCommand("player", "setscriptsteps", {New ScriptArgument("stepAmount", ScriptArgument.ArgumentTypes.Int), New ScriptArgument("scriptPath", ScriptArgument.ArgumentTypes.Str)}.ToList(), "Executes a script file after having moved the given amount of steps.")) + r(New ScriptCommand("player", "clearscriptsteps", "Clears the register created with @player.setscriptsteps, preventing the script from being executed.")) ' Constructs: r(New ScriptCommand("player", "position", "sngarr", {New ScriptArgument("coordinate", ScriptArgument.ArgumentTypes.StrArr, {"x", "y", "z"}, True, "")}.ToList(), "Returns the position of the player. The normal coordinate combination is ""X,Y,Z"".", ",", True)) @@ -543,6 +545,7 @@ Namespace ScriptVersion2 r(New ScriptCommand("player", "gamejoltid", "str", "Returns the player's GameJolt ID.", ",", True)) r(New ScriptCommand("player", "haspokedex", "bool", "Returns if the player received the Pokédex.", ",", True)) r(New ScriptCommand("player", "haspokegear", "bool", "Returns if the player received the Pokégear.", ",", True)) + r(New ScriptCommand("player", "scriptsteps", "int", "Returns the amount of steps before the script as defined by @player.setscriptsteps is executed.", ",", True)) End Sub Private Shared Sub DoNPC()