public ITES5ValueCodeChunk ConvertFunction(ITES5Referencer calledOn, TES4Function function, TES5CodeScope codeScope, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope) { //WTM: Note: Just like DisablePlayerControlsFactory, I want to emulate this: //https://cs.elderscrolls.com/index.php?title=DisablePlayerControls //Player cannot move, wait, activate anything, or access his journal interface. string[] functionNames = new string[] { "IsMovementControlsEnabled", "IsMenuControlsEnabled" /*closest to "IsWaitControlsEnabled" I could find*/, "IsActivateControlsEnabled", "IsJournalControlsEnabled" }; TES5ObjectCall[] objectCalls = functionNames.Select(f => objectCallFactory.CreateObjectCall(TES5StaticReferenceFactory.Game, f)).ToArray(); ITES5ValueCodeChunk?accumulatedStatement = null; foreach (TES5ObjectCall objectCall in objectCalls) { if (accumulatedStatement == null) { accumulatedStatement = objectCall; } else { accumulatedStatement = TES5ExpressionFactory.CreateLogicalExpression(accumulatedStatement, TES5LogicalExpressionOperator.OPERATOR_AND, objectCall); } } if (accumulatedStatement == null) { throw new NullableException(nameof(accumulatedStatement)); } TES5ComparisonExpression negatedExpression = TES5ExpressionFactory.CreateComparisonExpression(accumulatedStatement, TES5ComparisonExpressionOperator.OPERATOR_NOT_EQUAL, new TES5Bool(true)); return(negatedExpression); }
public ITES5ValueCodeChunk ConvertFunction(ITES5Referencer calledOn, TES4Function function, TES5CodeScope codeScope, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope) { TES5LocalScope localScope = codeScope.LocalScope; TES4FunctionArguments functionArguments = function.Arguments; //WARNING: This is not an exact implementation //According to cs.elderscrolls.com, its about being in the faction AND having an attack on them ( violent crime ) //It"s similar but groups all violent wrongdoings ( including assaults, murders etc ). ITES5Referencer factionReference = this.referenceFactory.CreateReadReference(functionArguments[0].StringValue, globalScope, multipleScriptsScope, localScope); TES5ObjectCallArguments arguments = new TES5ObjectCallArguments() { factionReference }; TES5ObjectCall isInFaction = this.objectCallFactory.CreateObjectCall(TES5ReferenceFactory.CreateReferenceToPlayer(), "IsInFaction", multipleScriptsScope, arguments); TES5TrueBooleanExpression leftExpression = TES5ExpressionFactory.CreateTrueBooleanExpression(isInFaction); TES5ObjectCall crimeGoldViolent = this.objectCallFactory.CreateObjectCall(factionReference, "GetCrimeGoldViolent", multipleScriptsScope); TES5ComparisonExpression rightExpression = TES5ExpressionFactory.CreateComparisonExpression(crimeGoldViolent, TES5ComparisonExpressionOperator.OPERATOR_GREATER, new TES5Integer(0)); TES5LogicalExpression logicalExpression = TES5ExpressionFactory.CreateLogicalExpression(leftExpression, TES5LogicalExpressionOperator.OPERATOR_AND, rightExpression); return(logicalExpression); }
public ITES5ValueCodeChunk ConvertFunction(ITES5Referencer calledOn, TES4Function function, TES5CodeScope codeScope, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope) { //WTM: Note: I'd prefer a single method call obviously, but this is the best solution I can imagine. TES5ObjectCall calledOnRaceName = objectCallFactory.CreateObjectCall(objectCallFactory.CreateObjectCall(calledOn, "GetRace", multipleScriptsScope), "GetName", multipleScriptsScope); string[] playableRaces = new string[] { "Altmer", "Argonian", "Bosmer", "Breton", "Dunmer", "Imperial", "Khajiit", "Nord", "Orc", "Redguard" }; ITES5Expression completeStatement = null; foreach (string race in playableRaces) { TES5ComparisonExpression newExpression = TES5ExpressionFactory.CreateComparisonExpression(calledOnRaceName, TES5ComparisonExpressionOperator.OPERATOR_EQUAL, new TES5String(race)); if (completeStatement == null) { completeStatement = newExpression; } else { completeStatement = TES5ExpressionFactory.CreateLogicalExpression(completeStatement, TES5LogicalExpressionOperator.OPERATOR_OR, newExpression); } } return(completeStatement); }