示例#1
0
        private void BuildDelayResult(JObject resultObject)
        {
            Main.LogDebug("[BuildDelayResult] Building 'Delay' result");
            string  name          = resultObject.ContainsKey("Name") ? resultObject["Name"].ToString() : "Unnamed Delay Result";
            float   time          = resultObject.ContainsKey("Time") ? (float)resultObject["Time"] : -1;
            int     rounds        = resultObject.ContainsKey("Rounds") ? (int)resultObject["Rounds"] : -1;
            int     phases        = resultObject.ContainsKey("Phases") ? (int)resultObject["Phases"] : -1;
            JObject skipIfTrigger = resultObject.ContainsKey("SkipIf") ? (JObject)resultObject["SkipIf"] : null;
            List <DesignConditional> childSkipIfConditionals = new List <DesignConditional>();

            JArray childResultsArray          = (JArray)resultObject["Results"];
            JArray childResultsIfSkippedArray = resultObject.ContainsKey("ResultsIfSkipped") ? (JArray)resultObject["ResultsIfSkipped"] : null;

            List <DesignResult> createdChildResults = new List <DesignResult>();
            ResultsBuilder      childResultsBuilder = new ResultsBuilder(this.contractTypeBuilder, childResultsArray);

            createdChildResults = childResultsBuilder.Build();

            List <DesignResult> createdChildResultsIfSkipped = new List <DesignResult>();

            if (childResultsIfSkippedArray != null)
            {
                ResultsBuilder childResultsIfSkippedBuilder = new ResultsBuilder(this.contractTypeBuilder, childResultsIfSkippedArray);
                createdChildResultsIfSkipped = childResultsIfSkippedBuilder.Build();
            }

            DelayResult result = ScriptableObject.CreateInstance <DelayResult>();

            result.Name             = name;
            result.Time             = time;
            result.Rounds           = rounds;
            result.Phases           = phases;
            result.Results          = createdChildResults;
            result.ResultsIfSkipped = createdChildResultsIfSkipped;

            results.Add(result);

            if (skipIfTrigger != null)
            {
                GenericTriggerBuilder          genericTrigger = new GenericTriggerBuilder(this.contractTypeBuilder, skipIfTrigger, "DelaySkipIfTrigger");
                ActivateDelaySkipResultsResult triggerResult  = ScriptableObject.CreateInstance <ActivateDelaySkipResultsResult>();
                triggerResult.DelayResult = result;
                genericTrigger.Results    = new List <DesignResult>()
                {
                    triggerResult
                };
                genericTrigger.Build();
            }
        }
示例#2
0
        private void BuildTriggerResultAtRandomResult(JObject resultObject)
        {
            Main.LogDebug("[BuildTriggerResultAtRandomResult] Building 'TriggerResultAtRandom' result");
            JArray childResultsArray = (JArray)resultObject["Results"];

            List <DesignResult> createdChildResults = new List <DesignResult>();
            ResultsBuilder      childResultsBuilder = new ResultsBuilder(this.contractTypeBuilder, childResultsArray);

            createdChildResults = childResultsBuilder.Build();

            TriggerResultAtRandomResult result = ScriptableObject.CreateInstance <TriggerResultAtRandomResult>();

            result.Results = createdChildResults;

            results.Add(result);
        }
        public GenericTriggerBuilder(ContractTypeBuilder contractTypeBuilder, JObject trigger, string name)
        {
            this.contractTypeBuilder = contractTypeBuilder;
            this.trigger             = trigger;

            this.name        = name;
            this.triggerOn   = trigger["TriggerOn"].ToString();
            this.description = (trigger.ContainsKey("Description")) ? trigger["Description"].ToString() : "";

            this.conditionalEvaluationString = (trigger.ContainsKey("SucceedOn")) ? trigger["SucceedOn"].ToString() : "All";
            this.conditionalEvaluation       = (LogicEvaluation)Enum.Parse(typeof(LogicEvaluation), conditionalEvaluationString);

            if (trigger.ContainsKey("Conditionals"))
            {
                ConditionalBuilder conditionalBuilder = new ConditionalBuilder(contractTypeBuilder, (JArray)trigger["Conditionals"]);
                this.conditional = conditionalBuilder.Build();
                this.conditional.whichMustBeTrue = this.conditionalEvaluation;
            }

            if (trigger.ContainsKey("Results"))
            {
                ResultsBuilder resultsBuilder = new ResultsBuilder(contractTypeBuilder, (JArray)trigger["Results"]);
                this.results = resultsBuilder.Build();
            }
            else
            {
                Main.Logger.LogError("[GenericTriggerBuilder] Generic Triggers require 'Results'");
            }

            if (!Enum.TryParse(this.triggerOn, out triggerMessageType))
            {
                MessageTypes messageType;
                if (!Enum.TryParse(this.triggerOn, out messageType))
                {
                    Main.Logger.LogError("[GenericTriggerBuilder] Invalid 'TriggerOn' provided.");
                }
                else
                {
                    triggerMessageType = (MessageCenterMessageType)messageType;
                }
            }
        }
示例#4
0
        private void BuildDelayResult(JObject resultObject)
        {
            Main.LogDebug("[BuildDelayResult] Building 'Delay' result");
            string name              = resultObject.ContainsKey("Name") ? resultObject["Name"].ToString() : "Unnamed Delay Result";
            float  time              = resultObject.ContainsKey("Time") ? (float)resultObject["Time"] : -1;
            int    rounds            = resultObject.ContainsKey("Rounds") ? (int)resultObject["Rounds"] : -1;
            int    phases            = resultObject.ContainsKey("Phases") ? (int)resultObject["Phases"] : -1;
            JArray childResultsArray = (JArray)resultObject["Results"];
            List <DesignResult> createdChildResults = new List <DesignResult>();
            ResultsBuilder      childResultsBuilder = new ResultsBuilder(this.contractTypeBuilder, childResultsArray);

            createdChildResults = childResultsBuilder.Build();

            DelayResult result = ScriptableObject.CreateInstance <DelayResult>();

            result.Name    = name;
            result.Time    = time;
            result.Rounds  = rounds;
            result.Phases  = phases;
            result.Results = createdChildResults;

            results.Add(result);
        }