Need Help adding a new Thought from social interraction

Started by Goldor, March 03, 2023, 12:40:02 PM

Previous topic - Next topic

Goldor

Hello All,
I am getting started with modding and I want to learn the bases of social interraction and memory/thought so I'm trying to creat a new thought called "Saw someone naked" that occure when a pawn see another pawn naked,
this is a simple mod idea to learn the bases,But I'm strugling as i can't do it properly.
at first I created the thought def xml as it follow.
<?xml version="1.0" encoding="utf-8"?>
<Defs>
  <ThoughtDef>
    <defName>SawNakedBodyPart</defName>
    <workerClass>SawSN.ThoughtWorker_SawSN</workerClass>
    <durationDays>0.1</durationDays>
    <stackLimit>6</stackLimit>
    <stages>
      <li>
        <description>I saw someone naked, it's embarrassing.</description>
        <label>Saw Someone naked</label>
        <baseMoodEffect>-3</baseMoodEffect>
      </li>
    </stages>
  </ThoughtDef>
</Defs>
and here is the c# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using RimWorld;
using Verse;

namespace SawSN
{
   
    public class ThoughtWorker_SawSN : ThoughtWorker_Precept_GroinOrChestUncovered_Social
    {
        protected override ThoughtState ShouldHaveThought(Pawn p, Pawn otherPawn)
        {

            if (otherPawn == null)
            {
                return ThoughtState.Inactive;
            }
            if (otherPawn.apparel != null && otherPawn.apparel.BodyPartGroupIsCovered(BodyPartGroupDefOf.Torso) && otherPawn.apparel.BodyPartGroupIsCovered(BodyPartGroupDefOf.Legs))
            {
                return ThoughtState.Inactive;
            }

            ThoughtState.ActiveAtStage(0);
            return base.ShouldHaveThought(p,otherPawn);
           
        }   
    }
}


(At first I was using the ThoughtWorker_Precept_Social but i found this subclass and thought it was better to use the ThoughtWorker_Precept_GroinOrChestUncovered_Social)

the first probleme is that when loading the game it tells me that SawNakedBodyPart has a workerClass but is a memory and workerClass only work for situational thought, But the workerClass is the only method i know to connect the c# and xml part.

the second problem is that even if I found a way to connect the xml and c# I don't think the code will work because I don't know if the conditions are met Who will get the Tought.
can anyone tells me if I'm doing something wrong please.
also if there is another way to connect the xml and c# without using the workerClass I would really love to know it, I already heard of a [DefOf] methode but I didn't understand it.