How to change pawn's work effectiveness

Started by Garwel, June 11, 2020, 05:21:21 AM

Previous topic - Next topic


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" ?>
   <Operation Class="PatchOperationAdd">
         <li Class="MyNamespace.StatPart_MyClass"/>

And you're good to go!