Example #1
0
        public static string TestConditionalActionSetCollections2(ScreenManager screenMan, out int errorsAdded)
        {
            int    num = 0;
            string str = "";

            using (FileStream fileStream1 = File.OpenRead("Content/Tests/DLCTests/TestConditionalActionSetCollection2.xml"))
            {
                XmlReader rdr = XmlReader.Create((Stream)fileStream1);
                RunnableConditionalActions conditionalActions1 = RunnableConditionalActions.Deserialize(rdr);
                if (!Directory.Exists("Content/Tests/Output/"))
                {
                    Directory.CreateDirectory("Content/Tests/Output");
                }
                File.WriteAllText("Content/Tests/Output/TestConditionalActionSetsOutput2.xml", conditionalActions1.GetSaveString());
                using (FileStream fileStream2 = File.OpenRead("Content/Tests/Output/TestConditionalActionSetsOutput2.xml"))
                {
                    RunnableConditionalActions conditionalActions2 = RunnableConditionalActions.Deserialize(XmlReader.Create((Stream)fileStream2));
                    if (conditionalActions1.Actions.Count != conditionalActions2.Actions.Count || conditionalActions1.Actions.Count != 1)
                    {
                        ++num;
                        str = str + "\r\n\r\nConditional Action Set Collections are Broken! Expected 1 actions, got " + (object)conditionalActions1.Actions.Count + " and " + (object)conditionalActions2.Actions.Count;
                    }
                    if (conditionalActions1.Actions[0].Actions.Count != 1)
                    {
                        ++num;
                        str += "\n\nSave on OS Conditional actions v2 failed! Incorrect action contents on original deserialization. \n\n";
                    }
                }
                rdr.Close();
            }
            errorsAdded = num;
            return(str);
        }
 internal static void RunStartingActions(ref OS __instance)
 {
     if (!OS.WillLoadSave && Settings.IsInExtensionMode && ExtensionLoader.ActiveExtensionInfo.StartingActionsPath != null)
     {
         RunnableConditionalActions.LoadIntoOS(ExtensionLoader.ActiveExtensionInfo.StartingActionsPath, __instance);
     }
 }
        internal static XElement GetConditionalActionsSaveElement(RunnableConditionalActions actions)
        {
            var result = new XElement("ConditionalActions");

            foreach (var action in actions.Actions)
            {
                result.Add(GetConditionalActionSetSaveElement(action));
            }
            return(result);
        }
        public static RunnableConditionalActions LoadConditionalActions(ElementInfo root)
        {
            var result = new RunnableConditionalActions();

            foreach (var info in root.Children)
            {
                result.Actions.Add(LoadConditionalActionSet(info));
            }
            return(result);
        }
Example #5
0
        public static string TestConditionalActionSetCollectionsOnOS(ScreenManager screenMan, out int errorsAdded)
        {
            int    num      = 0;
            string str      = "";
            string username = "******";
            string pass     = "******";

            SaveFileManager.AddUser(username, pass);
            string fileNameForUsername = SaveFileManager.GetSaveFileNameForUsername(username);

            OS.TestingPassOnly = true;
            OS os1 = new OS();

            os1.SaveGameUserName    = fileNameForUsername;
            os1.SaveUserAccountName = username;
            screenMan.AddScreen((GameScreen)os1, new PlayerIndex?(screenMan.controllingPlayer));
            os1.delayer.RunAllDelayedActions();
            RunnableConditionalActions conditionalActions = os1.ConditionalActions;

            os1.ConditionalActions.Actions.Add(new SerializableConditionalActionSet()
            {
                Condition = (SerializableCondition) new SCOnAdminGained(),
                Actions   = new List <SerializableAction>()
            });
            os1.ConditionalActions.Actions.Add(new SerializableConditionalActionSet()
            {
                Condition = (SerializableCondition) new SCOnAdminGained(),
                Actions   = new List <SerializableAction>()
            });
            os1.threadedSaveExecute(false);
            List <Computer> nodes = os1.netMap.nodes;

            screenMan.RemoveScreen((GameScreen)os1);
            OS.WillLoadSave = true;
            OS os2 = new OS();

            os2.SaveGameUserName    = fileNameForUsername;
            os2.SaveUserAccountName = username;
            screenMan.AddScreen((GameScreen)os2, new PlayerIndex?(screenMan.controllingPlayer));
            os2.delayer.RunAllDelayedActions();
            Game1.getSingleton().IsMouseVisible = true;
            List <string> stringList1           = new List <string>();
            List <string> stringList2           = new List <string>();

            if (os2.ConditionalActions.Actions.Count != conditionalActions.Actions.Count)
            {
                ++num;
                str = str + "Save on OS COnditional actions failed! Expected 2, got " + (object)os2.ConditionalActions.Actions.Count;
            }
            screenMan.RemoveScreen((GameScreen)os2);
            OS.TestingPassOnly = false;
            errorsAdded        = num;
            return(str);
        }
Example #6
0
        public void Update(float dt, object osobj)
        {
            OS os = (OS)osobj;

            if ((double)this.themeSwapTimeRemaining > 0.0)
            {
                this.themeSwapTimeRemaining -= dt;
                if ((double)this.themeSwapTimeRemaining <= 0.0)
                {
                    this.CompleteThemeSwap((object)os);
                    return;
                }
                bool    flag            = (double)Utils.randm(1f) > (double)this.themeSwapTimeRemaining / (double)this.originalThemeSwapTime;
                OSTheme theme           = flag ? this.newTheme : this.oldTheme;
                string  customThemePath = flag ? this.newThemePath : this.oldThemePath;
                ThemeManager.LastLoadedCustomTheme = flag ? this.newCustomTheme : this.oldCustomTheme;
                if (customThemePath != null)
                {
                    ThemeManager.switchTheme((object)os, customThemePath);
                }
                else
                {
                    ThemeManager.switchTheme((object)os, theme);
                }
            }
            if (this.ScreenBleedActive)
            {
                this.ScreenBleedTimeLeft -= dt;
                PostProcessor.dangerModePercentComplete = Math.Max(0.0f, Math.Min((float)(1.0 - (double)this.ScreenBleedTimeLeft / (double)this.ScreenBleedStartTime), 1f));
                PostProcessor.dangerModeEnabled         = true;
                if ((double)this.ScreenBleedTimeLeft <= 0.0)
                {
                    this.ScreenBleedActive = false;
                    PostProcessor.dangerModePercentComplete = 0.0f;
                    PostProcessor.dangerModeEnabled         = false;
                    if (!string.IsNullOrWhiteSpace(this.screenBleedCompleteAction))
                    {
                        RunnableConditionalActions.LoadIntoOS(this.screenBleedCompleteAction, (object)os);
                    }
                }
                else
                {
                    os.postFXDrawActions += (Action)(() => TraceDangerSequence.DrawCountdownOverlay(Utils.CheckStringIsTitleRenderable(this.screenBleedTitle) ? GuiData.titlefont : GuiData.font, GuiData.smallfont, (object)os, this.screenBleedTitle, this.screenBleedL1, this.screenBleedL2, this.screenBleedL3));
                }
            }
        }
        public static RunnableConditionalActions LoadConditionalActionsFromFile(string filename)
        {
            var executor = new EventExecutor(filename);
            RunnableConditionalActions result = null;

            executor.AddExecutor("ConditionalActions", (exec, info) =>
            {
                result = LoadConditionalActions(info);
            }, true);

            executor.Parse();

            if (result == null)
            {
                throw new LoadException("Conditional Actions File", "Incorrect root element");
            }

            return(result);
        }
Example #8
0
 public void Update(float dt)
 {
     this.flashInTimeLeft = Math.Max(0.0f, this.flashInTimeLeft - dt);
     this.timeElapsed    += dt;
     if (!this.IsMonitoringDLCEndingCases)
     {
         return;
     }
     if (this.CrashingAircraft != null)
     {
         if (this.CrashingAircraft.IsInCriticalFirmwareFailure)
         {
             this.TargetHasStartedCrashing = true;
             this.IsInPostSaveState        = false;
             double totalSeconds = MediaPlayer.PlayPosition.TotalSeconds;
             double num1         = 1.0 / (131.0 / 60.0);
             double num2         = num1 * 4.0;
             double num3         = num1 * 2.0;
             double num4         = totalSeconds < 58.0 ? 999.0 : (totalSeconds < 117.0 ? num2 : num3);
             if ((totalSeconds + num1 / 2.0) % num4 < num1 / 4.0)
             {
                 this.os.warningFlash();
             }
         }
         else if (this.TargetHasStartedCrashing)
         {
             if (!this.os.Flags.HasFlag("DLC_PlaneResult"))
             {
                 RunnableConditionalActions.LoadIntoOS("DLC/ActionScripts/FinaleSaveActions.xml", (object)this.os);
                 this.os.Flags.AddFlag("DLC_PlaneSaveResponseTriggered");
                 this.os.Flags.AddFlag("DLC_PlaneResult");
             }
             if (!this.CrashingAircraft.IsInCriticalDescent() && !MediaPlayer.IsRepeating)
             {
                 MusicManager.FADE_TIME = 6f;
                 MusicManager.transitionToSong("DLC/Music/RemiDrone");
                 MediaPlayer.IsRepeating = true;
                 this.os.delayer.Post(ActionDelayer.Wait(2.0), (Action)(() => this.AircraftSaveSound.Play()));
                 this.IsInPostSaveState = true;
             }
         }
     }
     else if (this.TargetHasStartedCrashing)
     {
         if (this.SecondaryAircraft == null || this.SecondaryAircraft.IsInCriticalFirmwareFailure)
         {
             if (!this.os.Flags.HasFlag("DLC_PlaneResult"))
             {
                 RunnableConditionalActions.LoadIntoOS("DLC/ActionScripts/FinaleDoubleCrashActions.xml", (object)this.os);
                 this.os.Flags.AddFlag("DLC_DoubleCrashResponseTriggered");
                 this.os.Flags.AddFlag("DLC_PlaneResult");
             }
         }
         else if (!this.os.Flags.HasFlag("DLC_PlaneResult"))
         {
             RunnableConditionalActions.LoadIntoOS("DLC/ActionScripts/FinaleCrashActions.xml", (object)this.os);
             this.os.Flags.AddFlag("DLC_PlaneCrashedResponseTriggered");
             this.os.Flags.AddFlag("DLC_PlaneResult");
         }
         if (MusicManager.currentSongName != "DLC\\Music\\CrashTrack")
         {
             MusicManager.playSongImmediatley("DLC\\Music\\CrashTrack");
             MediaPlayer.IsRepeating = false;
         }
     }
     if (!MediaPlayer.IsRepeating && MediaPlayer.State != MediaState.Playing && !this.IsInPostSaveState)
     {
         MusicManager.FADE_TIME = 6f;
         MissionFunctions.runCommand(7, "changeSongDLC");
         MediaPlayer.IsRepeating = true;
     }
 }
        public static RunnableConditionalActions LoadActionSets(ElementInfo root)
        {
            var ret = new RunnableConditionalActions();

            if (root.Name != "ConditionalActions")
            {
                throw new FormatException("Condtional actions root element wasn't named \"ConditionalActions\"!");
            }

            foreach (var conditionInfo in root.Children)
            {
                var set = new SerializableConditionalActionSet();

                #region Conditions

                if (ConditionManager.TryLoadCustomCondition(conditionInfo, out var customCondition))
                {
                    set.Condition = customCondition;
                }
                else
                {
                    switch (conditionInfo.Name)
                    {
                    case "OnAdminGained":
                        set.Condition = new SCOnAdminGained()
                        {
                            target = conditionInfo.Attributes.GetOrThrow("target", "No target found for OnAdminGained condition!")
                        };
                        break;

                    case "OnConnect":
                        set.Condition = new SCOnConnect()
                        {
                            target               = conditionInfo.Attributes.GetOrThrow("target", "No target found for OnConnect condition!"),
                            requiredFlags        = conditionInfo.Attributes.GetString("requiredFlags", null),
                            needsMissionComplete = conditionInfo.Attributes.GetBool("needsMissionComplete")
                        };
                        break;

                    case "HasFlags":
                        set.Condition = new SCHasFlags()
                        {
                            requiredFlags = conditionInfo.Attributes.GetString("requiredFlags", null)
                        };
                        break;

                    case "Instantly":
                        set.Condition = new SCInstantly()
                        {
                            needsMissionComplete = conditionInfo.Attributes.GetBool("needsMissionComplete")
                        };
                        break;

                    case "OnDisconnect":
                        set.Condition = new SCOnDisconnect()
                        {
                            target = conditionInfo.Attributes.GetOrDefault("target")
                        };
                        break;

                    case "DoesNotHaveFlags":
                        set.Condition = new SCDoesNotHaveFlags()
                        {
                            Flags = conditionInfo.Attributes.GetString("Flags", null)
                        };
                        break;
                    }
                }

                if (set.Condition == null)
                {
                    throw new FormatException($"Condition {conditionInfo.Name} could not be found!");
                }

                #endregion

                set.Actions.AddRange(conditionInfo.Children.Select(ReadAction));

                ret.Actions.Add(set);
            }

            return(ret);
        }
Example #10
0
 private static void LoadActions(OS os, string[] args)
 {
     RunnableConditionalActions.LoadIntoOS(string.Join(" ", args.Skip(1)), os);
 }
Example #11
0
        public static void LoadNewExtensionSession(ExtensionInfo info, object os_obj)
        {
            LocaleActivator.ActivateLocale(info.Language, Game1.getSingleton().Content);
            OS os = (OS)os_obj;

            People.ReInitPeopleForExtension();
            if (Directory.Exists(info.FolderPath + "/Nodes"))
            {
                Utils.ActOnAllFilesRevursivley(info.FolderPath + "/Nodes", (Action <string>)(filename =>
                {
                    if (!filename.EndsWith(".xml"))
                    {
                        return;
                    }
                    if (OS.TestingPassOnly)
                    {
                        try
                        {
                            Computer c = Computer.loadFromFile(filename);
                            if (c != null)
                            {
                                ExtensionLoader.CheckAndAssignCoreServer(c, os);
                            }
                        }
                        catch (Exception ex)
                        {
                            string format       = "COMPUTER LOAD ERROR:\nError loading computer \"{0}\"";
                            Exception exception = ex;
                            string message      = string.Format(format, (object)filename);
                            for (; exception != null; exception = exception.InnerException)
                            {
                                string str = string.Format("\r\nError: {0} - {1}", (object)exception.GetType().Name, (object)exception.Message);
                                message   += str;
                            }
                            throw new FormatException(message, ex);
                        }
                    }
                    else
                    {
                        Computer c = Computer.loadFromFile(filename);
                        if (c != null)
                        {
                            ExtensionLoader.CheckAndAssignCoreServer(c, os);
                        }
                    }
                }));
            }
            if (ComputerLoader.postAllLoadedActions != null)
            {
                ComputerLoader.postAllLoadedActions();
            }
            if (Programs.getComputer(os, "jmail") == null)
            {
                Computer c = new Computer("JMail Email Server", NetworkMap.generateRandomIP(), new Vector2(0.8f, 0.2f), 6, (byte)1, os);
                c.idName = "jmail";
                c.daemons.Add((Daemon) new MailServer(c, "JMail", os));
                MailServer.shouldGenerateJunk = false;
                c.users.Add(new UserDetail(os.defaultUser.name, "mailpassword", (byte)2));
                c.initDaemons();
                os.netMap.mailServer = c;
                os.netMap.nodes.Add(c);
            }
            for (int index = 0; index < info.StartingVisibleNodes.Length; ++index)
            {
                Computer computer = Programs.getComputer(os, info.StartingVisibleNodes[index]);
                if (computer != null)
                {
                    os.netMap.discoverNode(computer);
                }
            }
            for (int index = 0; index < info.FactionDescriptorPaths.Count; ++index)
            {
                string path = info.FolderPath + "/" + info.FactionDescriptorPaths[index];
                using (FileStream fileStream = File.OpenRead(path))
                {
                    try
                    {
                        Faction faction = Faction.loadFromSave(XmlReader.Create((Stream)fileStream));
                        os.allFactions.factions.Add(faction.idName, faction);
                    }
                    catch (Exception ex)
                    {
                        throw new FormatException("Error loading Faction: " + path, ex);
                    }
                }
            }
            OSTheme theme = OSTheme.Custom;
            bool    flag  = false;

            foreach (object obj in Enum.GetValues(typeof(OSTheme)))
            {
                if (obj.ToString().ToLower() == info.Theme)
                {
                    theme = (OSTheme)obj;
                    flag  = true;
                }
            }
            if (!flag)
            {
                if (File.Exists(info.FolderPath + "/" + info.Theme))
                {
                    ThemeManager.setThemeOnComputer((object)os.thisComputer, info.Theme);
                    ThemeManager.switchTheme((object)os, info.Theme);
                }
            }
            else
            {
                ThemeManager.setThemeOnComputer((object)os.thisComputer, theme);
                ThemeManager.switchTheme((object)os, theme);
            }
            ExtensionLoader.LoadExtensionStartTrackAsCurrentSong(info);
            if (info.StartingActionsPath != null)
            {
                RunnableConditionalActions.LoadIntoOS(info.StartingActionsPath, (object)os);
            }
            if (info.StartingMissionPath == null || info.StartsWithTutorial || info.HasIntroStartup)
            {
                return;
            }
            ExtensionLoader.SendStartingEmailForActiveExtensionNextFrame((object)os);
        }