public TES5CodeChunkCollection CreateCodeChunk(TES4VariableAssignation chunk, TES5CodeScope codeScope, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope)
        {
            TES5CodeChunkCollection codeChunkCollection = new TES5CodeChunkCollection();
            string          referenceName = chunk.Reference.StringValue;
            ITES5Referencer reference     = this.referenceFactory.CreateReference(referenceName, globalScope, multipleScriptsScope, codeScope.LocalScope);
            ITES5Value      value         = this.valueFactory.CreateValue(chunk.Value, codeScope, globalScope, multipleScriptsScope);

            if (reference.TES5Type == TES5BasicType.T_GLOBALVARIABLE)
            { //if the reference is in reality a global variable, we will need to convert it by creating a Reference.SetValue(value); call
                //Object call creation
                TES5ObjectCallArguments objectCallArguments = new TES5ObjectCallArguments()
                {
                    value
                };
                TES5ObjectCall objectCall = this.objectCallFactory.CreateObjectCall(reference, "SetValue", objectCallArguments);
                codeChunkCollection.Add(objectCall);
            }
            else
            {
                if (reference.ReferencesTo == null)
                {
                    throw new NullableException(nameof(reference.ReferencesTo));
                }
                if (!reference.ReferencesTo.TES5Type.IsPrimitive && value.TES5Type.IsPrimitive)
                {
                    //Hacky!
                    TES5IntegerOrFloat?valueNumber = value as TES5IntegerOrFloat;
                    if (valueNumber != null && valueNumber.ConvertedIntValue == 0)
                    {
                        value = new TES5None();
                    }
                }

                TES5VariableAssignation assignation = TES5VariableAssignationFactory.CreateAssignation(reference, value);
                this.typeInferencer.InferenceObjectByAssignation(reference, value);
                codeChunkCollection.Add(assignation);
                //post analysis.
                //Todo - rethink the prefix here
                ITES5Referencer?referencerValue = value as ITES5Referencer;
                if (referencerValue != null && referencerValue.Name == TES5Property.AddPropertyNameSuffix(TES5ReferenceFactory.MESSAGEBOX_VARIABLE_CONST))
                {
                    /*
                     * Create block:
                     * variable = this.TES4_MESSAGEBOX_RESULT; ; assignation
                     * if(variable != -1) ; branch, expression
                     *   this.TES4_MESSAGEBOX_RESULT = -1; ; reassignation
                     * endIf
                     */
                    TES5Integer negativeOne                = new TES5Integer(-1);
                    TES5ComparisonExpression expression    = TES5ExpressionFactory.CreateComparisonExpression(reference, TES5ComparisonExpressionOperator.OPERATOR_NOT_EQUAL, negativeOne);
                    TES5VariableAssignation  reassignation = TES5VariableAssignationFactory.CreateAssignation(referencerValue, negativeOne);
                    TES5Branch branch = TES5BranchFactory.CreateSimpleBranch(expression, codeScope.LocalScope);
                    branch.MainBranch.CodeScope.AddChunk(reassignation);
                    codeChunkCollection.Add(branch);
                }
            }

            return(codeChunkCollection);
        }
        public List <ITES5CodeChunk> GenerateObjectiveHandling(ITES5CodeBlock codeBlock, TES5GlobalScope globalScope, List <int> stageMap)
        {
            List <ITES5CodeChunk> result = new List <ITES5CodeChunk>();

            //WTM:  Change:
            if (!stageMap.Any())
            {
                return(result);
            }
            TES5LocalVariable       castedToQuest        = new TES5LocalVariable("__temp", TES5BasicType.T_QUEST);//WTM:  Note:  Why is this variable even necessary?
            TES5Reference           referenceToTemp      = TES5ReferenceFactory.CreateReferenceToVariableOrProperty(castedToQuest);
            TES5SelfReference       questSelfReference   = TES5ReferenceFactory.CreateReferenceToSelf(globalScope);
            TES5VariableAssignation tempQuestAssignation = TES5VariableAssignationFactory.CreateAssignation(referenceToTemp, questSelfReference);

            result.Add(tempQuestAssignation);
            TES5LocalScope localScope = codeBlock.CodeScope.LocalScope;

            localScope.AddVariable(castedToQuest);
            int i = 0;

            foreach (var stageTargetState in stageMap)
            {
                TES5Integer             targetIndex        = new TES5Integer(i);
                TES5ObjectCallArguments displayedArguments = new TES5ObjectCallArguments()
                {
                    targetIndex
                };
                TES5ObjectCall           isObjectiveDisplayed         = objectCallFactory.CreateObjectCall(referenceToTemp, "IsObjectiveDisplayed", displayedArguments, inference: false);
                int                      isObjectiveDisplayedArgument = stageTargetState != 0 ? 0 : 1;
                TES5ComparisonExpression expression = TES5ExpressionFactory.CreateComparisonExpression(isObjectiveDisplayed, TES5ComparisonExpressionOperator.OPERATOR_EQUAL, new TES5Integer(isObjectiveDisplayedArgument));
                TES5ObjectCallArguments  arguments  = new TES5ObjectCallArguments()
                {
                    targetIndex, new TES5Integer(1)
                };
                string         setObjectiveFunction   = stageTargetState != 0 ? "SetObjectiveDisplayed" : "SetObjectiveCompleted";
                TES5ObjectCall setObjectiveObjectCall = objectCallFactory.CreateObjectCall(referenceToTemp, setObjectiveFunction, arguments, inference: false);
                TES5Branch     branch = TES5BranchFactory.CreateSimpleBranch(expression, localScope);
                branch.MainBranch.CodeScope.AddChunk(setObjectiveObjectCall);
                result.Add(branch);
                ++i;
            }

            return(result);
        }