Hi there. I'm looking for a way to dynamically (from C#) change effectiveness of certain jobs done by a pawn (a colonist, if it matters). For instance, I want to add a modifier to a pawn that will make it cook (or harvest plants, or perform operations) better than it normally does, but without permanently changing their skill. How can I do it?
I figured it out myself. Just in case someone needs it too, here is a quick explanation:
1. Create a class that extends StatPart, e.g.:
public class StatPart_MyClass : StatPart
2. Override its two methods: ExplanationPart and TransformValue
3. In ExplanationPart, return a string that will show the player how this modifier affects the value. Like this:
public override string ExplanationPart(StatRequest req) => "My modifier: x1.50";
4. In TransformValue, modify the provided value as needed, e.g.:
public override void TransformValue(StatRequest req, ref float val) => val *= 1.5f;
5. Add your class to a part via an XML patch (it should go into Patches folder in your mod's folder):
<?xml version="1.0" encoding="utf-8" ?>
<Patch>
<Operation Class="PatchOperationAdd">
<xpath>/Defs/StatDef[defName="WorkSpeedGlobal"]/parts</xpath>
<value>
<li Class="MyNamespace.StatPart_MyClass"/>
</value>
</Operation>
</Patch>
And you're good to go!