Exemplo n.º 1
0
        static bool Prefix(Planetbase.Sandstorm __instance, ref float timeStep)
        {
            if (Multiplayer.Client == null)
            {
                return(true);
            }

            Player?simulationOwner = Multiplayer.Client.SimulationManager.GetSimulationOwner();

            if (simulationOwner == null || simulationOwner.Value != Multiplayer.Client.LocalPlayer)
            {
                return(false); // Player isn't the simulation owner
            }
            Type      sandstormType        = __instance.GetType();
            FieldInfo mSandstormInProgress = Reflection.GetPrivateFieldOrThrow(sandstormType, "mSandstormInProgress", true);
            bool      sandstormInProgress  = (bool)Reflection.GetInstanceFieldValue(__instance, mSandstormInProgress);

            if (sandstormInProgress)
            {
                FieldInfo  mTimeInfo          = Reflection.GetPrivateFieldOrThrow(sandstormType, "mTime", true);
                FieldInfo  mSandstormTimeInfo = Reflection.GetPrivateFieldOrThrow(sandstormType, "mSandstormTime", true);
                MethodInfo onEndInfo          = Reflection.GetPrivateMethodOrThrow(sandstormType, "onEnd", true);

                float mTime = (float)Reflection.GetInstanceFieldValue(__instance, mTimeInfo) + timeStep;
                Reflection.SetInstanceFieldValue(__instance, mTimeInfo, mTime);
                float mSandstormTime = (float)Reflection.GetInstanceFieldValue(__instance, mSandstormTimeInfo);

                if (mTime > mSandstormTime)
                {
                    // End sandstorm
                    Reflection.InvokeInstanceMethod(__instance, onEndInfo, new object[] { });
                }
            }
            else
            {
                // Create a new sandstorm
                MethodInfo updateDetectionInfo      = Reflection.GetPrivateMethodOrThrow(sandstormType, "updateDetection", true);
                MethodInfo decideNextSandstormInfo  = Reflection.GetPrivateMethodOrThrow(sandstormType, "decideNextSandstorm", true);
                FieldInfo  mTimeToNextSandstorminfo = Reflection.GetPrivateFieldOrThrow(sandstormType, "mTimeToNextSandstorm", true);
                float      mTimeToNextSandstorm     = (float)Reflection.GetInstanceFieldValue(__instance, mTimeToNextSandstorminfo);

                Reflection.InvokeInstanceMethod(__instance, updateDetectionInfo, new object[] { mTimeToNextSandstorm, timeStep });
                mTimeToNextSandstorm -= timeStep;
                Reflection.SetInstanceFieldValue(__instance, mTimeToNextSandstorminfo, mTimeToNextSandstorm);
                if (mTimeToNextSandstorm < 0f)
                {
                    // Trigger sandstorm
                    __instance.trigger();
                    Reflection.InvokeInstanceMethod(__instance, decideNextSandstormInfo, new object[] { });
                }
            }

            return(false);
        }
        static bool Prefix(Planetbase.Sandstorm __instance)
        {
            if (Multiplayer.Client == null)
            {
                return(true);
            }

            Player?simulationOwner = Multiplayer.Client.SimulationManager.GetSimulationOwner();

            if (simulationOwner == null || simulationOwner.Value != Multiplayer.Client.LocalPlayer)
            {
                return(false); // Player isn't the simulation owner
            }
            PlanetbaseMultiplayer.Client.Environment.DisasterManager disasterManager = Multiplayer.Client.DisasterManager;

            disasterManager.EndDisaster();

            return(false);
        }
        static bool Prefix(Planetbase.Sandstorm __instance)
        {
            if (Multiplayer.Client == null)
            {
                return(true);
            }

            Player?simulationOwner = Multiplayer.Client.SimulationManager.GetSimulationOwner();

            if (simulationOwner == null || simulationOwner.Value != Multiplayer.Client.LocalPlayer)
            {
                return(false); // Player isn't the simulation owner
            }
            PlanetbaseMultiplayer.Client.Environment.DisasterManager disasterManager = Multiplayer.Client.DisasterManager;

            float disasterLength = UnityEngine.Random.Range(90f, 180f);
            float currentTime    = 0f;

            disasterManager.CreateDisaster(DisasterType.Sandstorm, disasterLength, currentTime);

            return(false);
        }