public ITES5ValueCodeChunk ConvertFunction(ITES5Referencer calledOn, TES4Function function, TES5CodeScope codeScope, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope)
        {
            TES4FunctionArguments functionArguments = function.Arguments;
            ITES4StringValue      apiToken          = functionArguments[0];
            string       cellEditorID = apiToken.StringValue;
            string       locationPropertyNameWithoutSuffix = cellEditorID + "Location";
            string       locationPropertyNameWithSuffix    = TES5Property.AddPropertyNameSuffix(locationPropertyNameWithoutSuffix);
            TES5Property?locationProperty = globalScope.TryGetPropertyByName(locationPropertyNameWithSuffix);

            if (locationProperty == null)
            {
                int tes5LocationFormID;
                if (cellToLocationFinder.TryGetLocationFormID(cellEditorID, out tes5LocationFormID))
                {
                    locationProperty = TES5PropertyFactory.ConstructWithTES5FormID(locationPropertyNameWithoutSuffix, TES5BasicType.T_LOCATION, null, tes5LocationFormID);
                    globalScope.AddProperty(locationProperty);
                }
                else
                {
                    TES5ObjectCall getParentCell      = this.objectCallFactory.CreateObjectCall(calledOn, "GetParentCell");
                    TES5ObjectCall getParentCellName  = this.objectCallFactory.CreateObjectCall(getParentCell, "GetName");
                    TES4Record     cellRecord         = this.esmAnalyzer.GetRecordByEDIDInTES4Collection(cellEditorID);
                    string?        cellNameWithSpaces = cellRecord.TryGetSubrecordTrim("FULL");
                    if (cellNameWithSpaces == null || cellNameWithSpaces.IndexOf("Dummy", StringComparison.OrdinalIgnoreCase) != -1)
                    {
                        cellNameWithSpaces = cellEditorID;
                    }
                    TES5String cellNameTES5String         = new TES5String(cellNameWithSpaces);
                    TES5ObjectCallArguments findArguments = new TES5ObjectCallArguments()
                    {
                        getParentCellName,
                        cellNameTES5String
                    };
                    TES5ObjectCall substring = this.objectCallFactory.CreateObjectCall(TES5StaticReferenceFactory.StringUtil, "Find", findArguments);
                    return(TES5ExpressionFactory.CreateComparisonExpression(substring, TES5ComparisonExpressionOperator.OPERATOR_EQUAL, new TES5Integer(0)));
                }
            }
            TES5Reference locationReference = TES5ReferenceFactory.CreateReferenceToVariableOrProperty(locationProperty);

            return(this.objectCallFactory.CreateObjectCall(calledOn, "IsInLocation", new TES5ObjectCallArguments()
            {
                locationReference
            }));
        }
Esempio n. 2
0
        public ITES5ValueCodeChunk ConvertFunction(ITES5Referencer calledOn, TES4Function function, TES5CodeScope codeScope, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope)
        {
            const string seWorldLocationEditorID   = TES5TypeFactory.TES4Prefix + SEWorldLocationPropertyName;
            int          seWorldLocationTES5FormID = locationFinder.GetLocationFormIDByLocationEditorID(seWorldLocationEditorID);
            TES5Property?seWorldLocationProperty   = globalScope.TryGetPropertyByName(SEWorldLocationPropertyName);

            if (seWorldLocationProperty == null)
            {
                seWorldLocationProperty = TES5PropertyFactory.ConstructWithTES5FormID(SEWorldLocationPropertyName, TES5BasicType.T_LOCATION, SEWorldLocationPropertyName, seWorldLocationTES5FormID);
                globalScope.AddProperty(seWorldLocationProperty);
            }
            ITES5Referencer         seWorldLocationReference = TES5ReferenceFactory.CreateReferenceToVariableOrProperty(seWorldLocationProperty);
            TES5ObjectCallArguments arguments = new TES5ObjectCallArguments()
            {
                seWorldLocationReference
            };
            TES5ObjectCall isInLocation = this.objectCallFactory.CreateObjectCall(TES5ReferenceFactory.CreateReferenceToPlayer(globalScope), "IsInLocation", arguments);

            return(isInLocation);
        }