Custom Added-Part based thought not working

Started by Ekarus, December 16, 2017, 05:02:03 PM

Previous topic - Next topic

Ekarus

So I'm trying to give a pawn a thought if it's got a certain bionic, similar in functionality (I would think) to how the joywire works.

I've created the entry in the item definition, the hediff definition, the surgery definition, and the thought definition. Those entries are correctly implemented to the best of my knowledge (no spelling errors, unclosed tags, etc)

Am I missing something? Because even when I pawn has the part and meets the conditions to get the thought it doesn't show up on the list.

Attached below are the various definitions mentioned above. On the off chance I missed something.


Thought
  <ThoughtDef>
    <defName>testbionichappyThought</defName>
    <workerClass>ThoughtWorker_Hediff</workerClass>
    <hediff>testbionichappy</hediff>
    <validWhileDespawned>true</validWhileDespawned>
    <nullifyingTraits>
      <li>Prosthophobe</li>
  <li>Prosthophile</li>
    </nullifyingTraits>
    <stages>
      <li>
        <label>to be filled</label>
        <description>to be filled</description>
        <baseMoodEffect>7</baseMoodEffect>
      </li>
    </stages>
  </ThoughtDef>

Hediff
  <HediffDef ParentName="EAFAddedBodyPartBase">
    <defName>testbionichappy</defName>
    <label>to be filled</label>
    <labelNoun>to be filled</labelNoun>
    <addedPartProps>
      <isBionic>true</isBionic>
      <isSolid>true</isSolid>
    </addedPartProps>
  </HediffDef>

Surgery
  <RecipeDef ParentName="EAFSurgeryFlesh">
<defName>Installtestbionichappy</defName>
<label>to be filled</label>
<description>to be filled</description>
<workerClass>Recipe_InstallArtificialBodyPart</workerClass>
<jobString>to be filled</jobString>
<workAmount>2800</workAmount>
<skillRequirements>
<Medicine>6</Medicine>
</skillRequirements>
<ingredients>
<li>
<filter>
          <categories>
<li>Medicine</li>
</categories>
</filter>
<count>1</count>
</li>
<li>
<filter>
<thingDefs>
<li>testbionichappy</li>
</thingDefs>
</filter>
<count>1</count>
</li>
</ingredients>
<fixedIngredientFilter>
      <categories>
        <li>Medicine</li>
      </categories>
      <thingDefs>
<li>testbionichappy</li>
</thingDefs>
</fixedIngredientFilter>
<appliedOnFixedBodyParts>
<li>BackHardpoint</li>
</appliedOnFixedBodyParts>
<addsHediff>testbionichappy</addsHediff>
</RecipeDef>

Item
  <ThingDef ParentName="EAFBodyPartArtificialBase">
    <defName>testbionichappy</defName>
    <label>To be filled</label>
    <description>To be filled</description>
    <graphicData>
      <texPath>Things/Item/BodyPart/ArtificialOrgan</texPath>
      <graphicClass>Graphic_Single</graphicClass>
    </graphicData>
    <itemGeneratorTags>
      <li>SpecialReward</li>
    </itemGeneratorTags>
    <statBases>
      <MarketValue>1500</MarketValue>
      <Mass>8</Mass>
    </statBases>
    <techHediffsTags>
      <li>Advanced</li>
    </techHediffsTags>
  </ThingDef>

BrokenValkyrie

I realise its 3 days late for an answer but I hope this can still help.

I looked through rimworld source code and found you need to add stages to your HediffDef for ThoughWoker_Hediff to take effect.

So your code needs to look like this

<!--HeDiff item-->
  <HediffDef ParentName="EAFAddedBodyPartBase">
    <defName>testbionichappy</defName>
    <label>to be filled</label>
    <labelNoun>to be filled</labelNoun>
    <stages>
      <li>
<partEfficiencyOffset>0</partEfficiencyOffset>
      </li>
    </stages>
    <addedPartProps>
      <isBionic>true</isBionic>
      <isSolid>true</isSolid>
    </addedPartProps>
  </HediffDef>


Here is rimworld source code that is responsible for Hediff thought worker.


  public class ThoughtWorker_Hediff : ThoughtWorker
  {
    protected override ThoughtState CurrentStateInternal(Pawn p)
    {
      Hediff firstHediffOfDef = p.health.hediffSet.GetFirstHediffOfDef(this.def.hediff, false);
      if (firstHediffOfDef == null || firstHediffOfDef.def.stages == null)
        return ThoughtState.Inactive;
      return ThoughtState.ActiveAtStage(Mathf.Min(firstHediffOfDef.CurStageIndex, firstHediffOfDef.def.stages.Count - 1, this.def.stages.Count - 1));
    }
  }



This part of the code is important, I initially misread it as checking for stage on thoughdef, its actually checking for stage of hediff. If hediff does not have stage it will return state of the thought as inactive.

      if (firstHediffOfDef == null || firstHediffOfDef.def.stages == null)
        return ThoughtState.Inactive;