Exemplo n.º 1
0
        public static ActiveMission LoadContentMission(string filename)
        {
            if (ComputerLoader.MissionPreLoadComplete != null)
            {
                ComputerLoader.MissionPreLoadComplete();
            }

            mission = new ActiveMission(new List <MisisonGoal>(), null, default)
            {
                willSendEmail         = true,
                reloadGoalsSourceFile = filename
            };
            branches = new List <ActiveMission>();
            mission.email.attachments = new List <string>();

            hasMissionTag = false;

            executor.SetText(LocalizedFileLoader.GetLocalizedFilepath(filename), true);

            foreach (var custom in CustomExecutors)
            {
                var customInstance = (MissionExecutor)Activator.CreateInstance(custom.ExecutorType);
                customInstance.Init(OS.currentInstance, ref mission);
                executor.RegisterTempExecutor(custom.Element, customInstance.Execute, custom.Options);
            }

            if (!executor.TryParse(out var ex))
            {
                throw new FormatException($"{filename}: {ex.Message}", ex);
            }

            var ret = mission;

            mission  = null;
            branches = null;

            return(hasMissionTag ? ret : null);
        }
Exemplo n.º 2
0
        static MissionLoader()
        {
            EventManager.onPluginUnload += OnPluginUnload;

            executor.RegisterExecutor("mission", (exec, info) =>
            {
                hasMissionTag       = true;
                mission.activeCheck = info.Attributes.GetBool("activeCheck");
                mission.ShouldIgnoreSenderVerification = info.Attributes.GetBool("shouldIgnoreSenderVerification");
            });
            executor.RegisterExecutor("mission.generationKeys", (exec, info) =>
            {
                if (!string.IsNullOrEmpty(info.Content))
                {
                    info.Attributes.Add("Data", info.Content);
                }
                MissionGenerator.setMissionGenerationKeys(info.Attributes);
                if (ComputerLoader.MissionPreLoadComplete != null)
                {
                    ComputerLoader.MissionPreLoadComplete();
                }
            }, ParseOption.ParseInterior);
            executor.RegisterExecutor("mission.goals.goal", (exec, info) => mission.goals.Add(LoadGoal(info)), ParseOption.ParseInterior);
            executor.RegisterExecutor("mission.missionStart", (exec, info) =>
            {
                var function = info.Content ?? throw new FormatException("missionStart with no mission function!");
                var val      = info.Attributes.GetInt("val", 1);
                if (info.Attributes.GetBool("suppress", Settings.IsInExtensionMode))
                {
                    mission.addStartFunction(val, function);
                }
                else
                {
                    MissionFunctions.runCommand(val, function);
                }
            }, ParseOption.ParseInterior);
            executor.RegisterExecutor("mission.missionEnd", (exec, info) =>
            {
                mission.addEndFunction(info.Attributes.GetInt("val", 1), info.Content ?? throw new FormatException("missionEnd with no mission function!"));
            }, ParseOption.ParseInterior);
            executor.RegisterExecutor("mission.nextMission", (exec, info) =>
            {
                mission.willSendEmail = !info.Attributes.GetBool("IsSilent", false);
                mission.nextMission   = info.Content ?? "NONE";
            }, ParseOption.ParseInterior);
            executor.RegisterExecutor("mission.branchMissions.branch", (exec, info) =>
            {
                var filePrefix      = Settings.IsInExtensionMode ? ExtensionLoader.ActiveExtensionInfo.FolderPath + "/" : "Content/Missions/";
                var currentMission  = mission;
                var currentBranches = branches;
                mission             = null;
                branches            = null;
                exec.SaveState();
                currentBranches.Add(LoadContentMission(filePrefix + info.Content));
                exec.PopState();
                mission  = currentMission;
                branches = currentBranches;
            }, ParseOption.ParseInterior);
            executor.RegisterExecutor("mission.branchMissions", (exec, info) => OS.currentInstance.branchMissions = branches, ParseOption.FireOnEnd);
            executor.RegisterExecutor("mission.posting", (exec, info) =>
            {
                mission.postingTitle = info.Attributes.GetString("title", "UNKNOWN").Filter();
                mission.postingBody  = info.Content ?? "UNKNOWN";
                mission.postingAcceptFlagRequirements = info.Attributes.GetString("reqs").Split(Utils.commaDelim, StringSplitOptions.RemoveEmptyEntries);
                mission.requiredRank = info.Attributes.GetInt("requiredRank");
                mission.difficulty   = info.Attributes.GetInt("difficulty");
                mission.client       = info.Attributes.GetString("client").Filter();
                mission.target       = info.Attributes.GetString("target").Filter();
            }, ParseOption.ParseInterior);
            executor.RegisterExecutor("mission.email.sender", (exec, info) => mission.email.sender   = info.Content.Filter(), ParseOption.ParseInterior);
            executor.RegisterExecutor("mission.email.subject", (exec, info) => mission.email.subject = info.Content.Filter(), ParseOption.ParseInterior);
            executor.RegisterExecutor("mission.email.body", (exec, info) => mission.email.body       = info.Content.Filter(), ParseOption.ParseInterior);
            executor.RegisterExecutor("mission.email.attachments.link", (exec, info) =>
            {
                var comp = info.Attributes.GetComp("comp", SearchType.Id);
                if (comp != null)
                {
                    mission.email.attachments.Add($"link#%#{comp.name}#%#{comp.ip}");
                }
            });
            executor.RegisterExecutor("mission.email.attachments.account", (exec, info) =>
            {
                var comp = info.Attributes.GetComp("comp");
                mission.email.attachments.Add(
                    $"account#%#{comp.name}#%#{comp.ip}#%#{info.Attributes.GetString("user", "UNKNOWN").Filter()}#%#{info.Attributes.GetString("pass", "UNKNOWN").Filter()}"
                    );
            });
            executor.RegisterExecutor("mission.email.attachments.note", (exec, info) =>
            {
                mission.email.attachments.Add($"note#%#{info.Attributes.GetString("title", "Data").Filter()}#%#{info.Content.Filter()}");
            }, ParseOption.ParseInterior);
        }