public ITES5ValueCodeChunk ConvertFunction(ITES5Referencer calledOn, TES4Function function, TES5CodeScope codeScope, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope) { TES5LocalScope localScope = codeScope.LocalScope; TES4FunctionArguments functionArguments = function.Arguments; ITES5Referencer fameReference = this.referenceFactory.CreateReadReference("Fame", globalScope, multipleScriptsScope, localScope); TES5ObjectCallArguments fameArguments = new TES5ObjectCallArguments(); TES5ArithmeticExpression arithmeticExpression = TES5ExpressionFactory.CreateArithmeticExpression(fameReference, TES5ArithmeticExpressionOperator.OPERATOR_ADD, new TES5Integer(((TES4Integer)functionArguments[0]).IntValue)); fameArguments.Add(arithmeticExpression); return(this.objectCallFactory.CreateObjectCall(this.referenceFactory.CreateReference("Fame", globalScope, multipleScriptsScope, localScope), "SetValue", multipleScriptsScope, fameArguments)); }
public ITES5ValueCodeChunk ConvertFunction(ITES5Referencer calledOn, TES4Function function, TES5CodeScope codeScope, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope) { globalScope.AddFunction(GetGetArmorRatingOfWornFormFunctionCodeBlock(calledOn, codeScope)); ITES5ValueCodeChunk?accumulatedStatement = null; for (int slotMask = 0x00000004; slotMask <= 0x00000200; slotMask *= 2)//From body to shield { TES5ObjectCallCustom objectCall = GetGetArmorRatingOfWornFormObjectCall(globalScope, slotMask); if (accumulatedStatement == null) { accumulatedStatement = objectCall; } else { accumulatedStatement = TES5ExpressionFactory.CreateArithmeticExpression(accumulatedStatement, TES5ArithmeticExpressionOperator.OPERATOR_ADD, objectCall); } } if (accumulatedStatement == null) { throw new NullableException(nameof(accumulatedStatement)); } return(accumulatedStatement); }
public ITES5ValueCodeChunk ConvertFunction(ITES5Referencer calledOn, TES4Function function, TES5CodeScope codeScope, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope) { TES4FunctionArguments functionArguments = function.Arguments; TES5LocalScope localScope = codeScope.LocalScope; if (function.FunctionCall.FunctionName.Equals("modpcskill", StringComparison.OrdinalIgnoreCase)) { /* * MODPCSkill means we will need to call upon the player object */ calledOn = TES5ReferenceFactory.CreateReferenceToPlayer(); } TES5ObjectCallArguments convertedArguments = new TES5ObjectCallArguments(); var actorValueMap = ActorValueMap.Map; string firstArgString = functionArguments[0].StringValue; string firstArgStringLower = firstArgString.ToLower(); switch (firstArgStringLower) { case "strength": case "intelligence": case "willpower": case "agility": case "speed": case "endurance": case "personality": case "luck": { if (!TES5PlayerReference.EqualsPlayer(calledOn.Name)) { //We can"t convert those.. and shouldn"t be any, too. throw new ConversionException(nameof(ModActorValueFactory) + ": Cannot set attributes on non-player. Name: " + calledOn.Name + ", Argument: " + firstArgString); } const string functionName = "SetValue"; string tes4AttrFirstArg = TES5ReferenceFactory.TES4Attr + PHPFunction.UCWords(firstArgStringLower); /* * Switch out callee with the reference to attr */ ITES5Referencer newCalledOn = this.referenceFactory.CreateReference(tes4AttrFirstArg, globalScope, multipleScriptsScope, localScope); ITES4StringValue secondArg = functionArguments[1]; ITES5Value addedValue = this.valueFactory.CreateValue(secondArg, codeScope, globalScope, multipleScriptsScope); convertedArguments.Add(TES5ExpressionFactory.CreateArithmeticExpression(addedValue, TES5ArithmeticExpressionOperator.OPERATOR_ADD, this.referenceFactory.CreateReadReference(tes4AttrFirstArg, globalScope, multipleScriptsScope, localScope))); return(this.objectCallFactory.CreateObjectCall(newCalledOn, functionName, multipleScriptsScope, convertedArguments)); } case "fatigue": case "armorer": case "security": case "acrobatics": case "mercantile": case "mysticism": //It doesn"t exist in Skyrim - defaulting to Illusion.. case "blade": case "blunt": case "encumbrance": case "spellabsorbchance": case "resistfire": case "resistfrost": case "resistdisease": case "resistmagic": case "resistpoison": case "resistshock": { const string functionName = "ModActorValue"; convertedArguments.Add(new TES5String(actorValueMap[firstArgStringLower])); ITES4StringValue secondArg = functionArguments[1]; convertedArguments.Add(this.valueFactory.CreateValue(secondArg, codeScope, globalScope, multipleScriptsScope)); return(this.objectCallFactory.CreateObjectCall(calledOn, functionName, multipleScriptsScope, convertedArguments)); } case "aggression": { const string functionName = "ModActorValue"; ITES4StringValue secondArg = functionArguments[1]; int secondArgData = (int)secondArg.Data; int newValue; if (secondArgData < -80) { newValue = -3; } else if (secondArgData >= -80 && secondArgData < -50) { newValue = -2; } else if (secondArgData >= -50 && secondArgData < 0) { newValue = -1; } else if (secondArgData == 0) { newValue = 0; } else if (secondArgData > 0 && secondArgData < 50) { newValue = 1; } else if (secondArgData >= 50 && secondArgData < 80) { newValue = 2; } else { newValue = 3; } convertedArguments.Add(new TES5String(firstArgString)); convertedArguments.Add(new TES5Float(newValue)); return(this.objectCallFactory.CreateObjectCall(calledOn, functionName, multipleScriptsScope, convertedArguments)); } case "confidence": { const string functionName = "ModActorValue"; ITES4StringValue secondArg = functionArguments[1]; int secondArgData = (int)secondArg.Data; int newValue; if (secondArgData == -100) { newValue = -4; } else if (secondArgData <= -70 && secondArgData > -100) { newValue = -3; } else if (secondArgData <= -30 && secondArgData > -70) { newValue = -2; } else if (secondArgData < 0 && secondArgData > -30) { newValue = -1; } else if (secondArgData == 0) { newValue = 0; } else if (secondArgData > 0 && secondArgData < 30) { newValue = 1; } else if (secondArgData >= 30 && secondArgData < 70) { newValue = 2; } else if (secondArgData >= 70 && secondArgData < 99) { newValue = 3; } else { newValue = 4; } convertedArguments.Add(new TES5String(firstArgString)); convertedArguments.Add(new TES5Float(newValue)); return(this.objectCallFactory.CreateObjectCall(calledOn, functionName, multipleScriptsScope, convertedArguments)); } default: { const string functionName = "ModActorValue"; convertedArguments.Add(new TES5String(firstArgString)); ITES4StringValue secondArg = functionArguments[1]; convertedArguments.Add(this.valueFactory.CreateValue(secondArg, codeScope, globalScope, multipleScriptsScope)); return(this.objectCallFactory.CreateObjectCall(calledOn, functionName, multipleScriptsScope, convertedArguments)); } } }