Ludeon Forums

RimWorld => Mods => Help => Topic started by: vinny on October 25, 2020, 09:34:26 AM

Title: JobDriver overriding
Post by: vinny on October 25, 2020, 09:34:26 AM
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 ?
Title: Re: JobDriver overriding
Post by: RawCode on October 26, 2020, 02:26:55 AM
init done one time, it does not happen when you cut plants.
Title: Re: JobDriver overriding
Post by: vinny on October 26, 2020, 02:50:11 AM
yea, I know, but I should see message from PlantWorkDoneToil isn't it ? Any idea why it's not happen... please
Title: Re: JobDriver overriding
Post by: LWM on October 26, 2020, 05:44:59 PM
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?
Title: Re: JobDriver overriding
Post by: RawCode on October 27, 2020, 02:44:00 AM
rw does not care about numbers, you can ever name classes in your local language and they will work
Title: Re: JobDriver overriding
Post by: vinny on October 28, 2020, 12:14:54 AM
Thank you, guys. I just need better check it in game, it's work, I tested it like job was PlantCutDesignated