JobDriver overriding

Started by vinny, October 25, 2020, 09:34:26 AM

Previous topic - Next topic

vinny

Hi!
I am new in modding, I try to override any JobDriver. Create simple example.
In C# project create class:

namespace Test
{
    public class Class1 : JobDriver_PlantCut
    {
protected override void Init()
{
Log.Message("test2");
if (base.Plant.def.plant.harvestedThingDef != null && base.Plant.CanYieldNow())
{
xpPerTick = 0.085f;
}
else
{
xpPerTick = 0f;
}
}

protected override Toil PlantWorkDoneToil()
{
Log.Message("test1");
return base.PlantWorkDoneToil();
}
}
}

and then in xml I created this:

<Patch>

  <Operation Class="PatchOperationReplace">
  <xpath>Defs/JobDef[defName="CutPlant"]/driverClass</xpath>
  <value>
  <driverClass>Test.Class1</driverClass>
  </value>
  </Operation>

</Patch>

and even this:

<Defs>
 
  <JobDef>
    <defName>CutPlant</defName>
    <driverClass>Test.Class1</driverClass>
    <reportString>cutting TargetA.</reportString>
    <allowOpportunisticPrefix>true</allowOpportunisticPrefix>
  </JobDef>
 
</Defs>

But when I cut plants nothing happen. Log is clear. It's like I not use my code. What need to do to override JobDriver class ?

RawCode

init done one time, it does not happen when you cut plants.

vinny

yea, I know, but I should see message from PlantWorkDoneToil isn't it ? Any idea why it's not happen... please

LWM

Looks like you should at least see your debug message at least once.  If you want to be even more sure, you could make a constructor that logs a message:

public Class1() : base() {
  Log.Message("At least my class got called?");
}

Could we see your full directory structure? (github is awesome; having a license is super awesome)

Only thing I could possibly think is that sometimes RW doesn't like names ending in numerals?

RawCode

rw does not care about numbers, you can ever name classes in your local language and they will work

vinny

Thank you, guys. I just need better check it in game, it's work, I tested it like job was PlantCutDesignated