Create Linked Hediffs - KonradHeinser/EBSGFramework GitHub Wiki

This ability comp allows you to create linked hediffs between pawns that don't require special gene classes. Linked hediffs, or HediffWithTarget for the proper hediffClass, are hediffs with a target pawn on the other end, and in the event that one of them dies, the hediff automatically goes away. The Word of Love Psycast is an example of this, as it creates a psychic love hediff with a target pawn to love. The basic comp and class looks like this:

        <hediffClass>HediffWithTarget</hediffClass>

        <comps>
            <li Class="EBSGFramework.CompProperties_CreateLinkedHediff">
            </li>
        </comps>

These are the tags available for use:

  • hediffOnCaster : Hediff applied to the caster. Technically not required if you want to make an ability that only applies a hediff to the target while the caster is alive

  • casterHediffOnBrain : Default (False) : Apply the hediff to the brain instead of the full body

  • hediffOnTarget : Hediff applied to the target. Technically not required if you want to make an ability that only applies a hediff to the caster while the target is alive

  • targetHediffOnBrain : Default (False) : Apply the hediff to the brain instead of the full body

  • successChance : A special item that dictates the chance of success. If you don't add this to the comp, then it will always work

    • baseSuccessChance : Default (1) : Chance of the ability to succeed, with 1 being 100%
    • casterStatChance : StatDef of the caster that is checked to determine success chance. Normally the higher above 0 this is, the higher the chance of success
    • casterStatEffect : Default (Multiply) : Dictates what the stat does to the chance. The options are Multiply, Divide, OneMinusMultiply, and OneMinusDivide. The OneMinus options mean 1 - Stat Value
    • targetStatChance : StatDef of the target that is checked to determine success chance. Normally the higher above 0 this is, the lower the chance of success
    • targetStatEffect : Default (Divide) : Dictates what the stat does to the chance. The options are Multiply, Divide, OneMinusMultiply, and OneMinusDivide. The OneMinus options mean 1 - Stat Value
    • successMessage : Optional. Message given if this comp succeeds and the caster is a player pawn
    • failureMessage : Optional. Message given if this comp fails and the caster is a player pawn

It is important to note that while I keep saying "until x dies", these hediffs follow standard hediff rules, so things like HediffCompProperties_Disappears will function as normal. The hediffs themselves aren't linked, so it is possible to have the target's hediff go away before the casters, or the reverse. The death of one of the pawns is just another way of causing

IMPORTANT STAT NOTE: I have yet to find a reliable way to figure out when a certain stat is disabled, so please make sure that any stat checks you do are on stats that have neverDisabled set to true. The Rimworld code is set up to just throw errors any time a disabled stat is retrieved


This example from SHG - Just the Radiomancer would create a link between the radiomancer and an enemy. While both were still alive, the enemy would have a constant debuff, and the Radiomancer would gain resource regen using DRG's conditional draining / regeneration. The ability parent just specifies what pawns can be targeted:

    <AbilityDef ParentName="SHG_Radiomancer_DrainLinkAbility">
        <defName>SHG_Radiomancer_DrainEnergy</defName>
        <label>drain energy</label>
        <description>Create a link between this radiomancer and another pawn to begin draining some of that pawn's energy in exchange for increasing the radiomancer's radiation regeneration. If the target survives for the entire duration, this ability will produce a total of 40 radiocative energy.</description>
        <iconPath>Radiomancer/Decay/Gene_Radiomancer_DrainEnergy</iconPath>
        <cooldownTicksRange>10000</cooldownTicksRange>
        <statBases>
            <Ability_Duration>168</Ability_Duration>
        </statBases>
        <comps>
            <li Class="EBSGFramework.CompProperties_CreateLinkedHediff">
                <hediffOnCaster>SHG_Radiomancer_DrainEnergy</hediffOnCaster>
                <hediffOnTarget>SHG_Radiomancer_DrainEnergy_Debuff</hediffOnTarget>
            </li>
        </comps>
    </AbilityDef>

    <HediffDef Name="SHG_Radiomancer_DecayLink" Abstract="True">
        <everCurableByItem>false</everCurableByItem>
        <initialSeverity>1</initialSeverity>
        <hediffClass>HediffWithTarget</hediffClass>
        <scenarioCanAdd>false</scenarioCanAdd>
        <maxSeverity>1.0</maxSeverity>
        <comps>
            <li Class="HediffCompProperties_Disappears">
                <disappearsAfterTicks>10000</disappearsAfterTicks>
                <showRemainingTime>true</showRemainingTime>
            </li>
            <li Class="HediffCompProperties_DisappearsOnDeath"/>
        </comps>
    </HediffDef>

    <HediffDef ParentName="SHG_Radiomancer_DecayLink">
        <defName>SHG_Radiomancer_DrainEnergy_Debuff</defName>
        <label>drain energy</label>
        <description>There was a description here.</description>
        <stages>
            <li>
                <hungerRateFactorOffset>2</hungerRateFactorOffset>
                <statFactors>
                    <RestFallRateFactor>2</RestFallRateFactor>
                </statFactors>
            </li>
        </stages>
    </HediffDef>

    <HediffDef ParentName="SHG_Radiomancer_DecayLink">
        <defName>SHG_Radiomancer_DrainEnergy</defName>
        <label>drain energy</label>
        <description>There was a description here.</description>
        <stages />
    </HediffDef>

This example is far more in-depth, and shows both how basic success chance stuff works and how you can use this comp to change opinions and moods. In this case, the ability has a 75% base chance to succeed, which becomes higher when the social impact of the caster is high, and lower when the target's social impact is high. If it succeeds, the target will have a higher opinion of the caster for however long the hediff lasts, and the caster will have a higher mood

    <AbilityDef>
        <defName>DevilsBargain_Might</defName>
        <label>devil's bargain (might)</label>
        <description>.</description>
        <iconPath>Things/Mote/SpeechSymbols/Speech</iconPath>
        <cooldownTicksRange>60000</cooldownTicksRange>
        <hostile>false</hostile>
        <verbProperties>
            <verbClass>Verb_CastAbility</verbClass>
            <range>10</range>
            <warmupTime>5</warmupTime>
            <requireLineOfSight>False</requireLineOfSight>
            <targetParams>
                <canTargetAnimals>false</canTargetAnimals>
                <canTargetSelf>false</canTargetSelf>
                <canTargetBuildings>false</canTargetBuildings>
                <canTargetMechs>false</canTargetMechs>
                <canTargetMutants>false</canTargetMutants>
                <onlyTargetColonistsOrPrisonersOrSlaves>true</onlyTargetColonistsOrPrisonersOrSlaves>
            </targetParams>
        </verbProperties>
        <comps>
            <li Class="EBSGFramework.CompProperties_AbilityAbilityValidator">
                <disableGizmo>True</disableGizmo>
                <casterHasNoneOfHediffs>
                    <li>DevilsBargain_Might</li>
                </casterHasNoneOfHediffs>
            </li>
            <li Class="EBSGFramework.CompProperties_CreateLinkedHediff">
                <hediffOnCaster>DevilsBargain_Might</hediffOnCaster>
                <hediffOnTarget>DevilsBargain_MightBuff</hediffOnTarget>
                <successChance>
                    <baseSuccessChance>0.75</baseSuccessChance>
                    <casterStatChance>SocialImpact</casterStatChance>
                    <targetStatChance>SocialImpact</targetStatChance>
                    <successMessage>BargainAccepted</successMessage>
                    <failureMessage>BargainRejected</failureMessage>
                </successChance>
            </li>
        </comps>
    </AbilityDef>

    <HediffDef Name="DevilsBargainHediff" Abstract="True">
        <everCurableByItem>false</everCurableByItem>
        <initialSeverity>1</initialSeverity>
        <hediffClass>HediffWithTarget</hediffClass>
        <scenarioCanAdd>false</scenarioCanAdd>
        <maxSeverity>1.0</maxSeverity>
        <comps>
            <li Class="HediffCompProperties_DisappearsOnDeath"/>
        </comps>
    </HediffDef>

    <HediffDef ParentName="DevilsBargainHediff">
        <defName>DevilsBargain_Might</defName>
        <label>devil's bargain (might)</label>
        <description>.</description>
        <stages>
            <li>
                <statFactors>
                    <MeleeDamageFactor>0.85</MeleeDamageFactor>
                </statFactors>
            </li>
        </stages>
    </HediffDef>

    <ThoughtDef>
        <defName>DevilsBargain_Might</defName>
        <workerClass>ThoughtWorker_Hediff</workerClass>
        <hediff>DevilsBargain_Might</hediff>
        <validWhileDespawned>true</validWhileDespawned>
        <developmentalStageFilter>Baby, Child, Adult</developmentalStageFilter>
        <stages>
            <li>
                <label>devil's bargain (might)</label>
                <description>A fool has accepted my bargain, and more servants means less work for me.</description>
                <baseMoodEffect>10</baseMoodEffect>
            </li>
        </stages>
    </ThoughtDef>

    <HediffDef ParentName="DevilsBargainHediff">
        <defName>DevilsBargain_MightBuff</defName>
        <label>devil's bargain (might)</label>
        <description>.</description>
        <stages>
            <li>
                <statFactors>
                    <MeleeDamageFactor>1.1</MeleeDamageFactor>
                </statFactors>
            </li>
        </stages>
    </HediffDef>

    <ThoughtDef>
        <defName>DevilsBargain_MightBuff</defName>
        <thoughtClass>Thought_SituationalSocial</thoughtClass>
        <workerClass>ThoughtWorker_HediffWithTarget</workerClass>
        <hediff>DevilsBargain_MightBuff</hediff>
        <validWhileDespawned>true</validWhileDespawned>
        <stages>
            <li>
                <label>devil's bargain (might)</label>
                <baseOpinionOffset>20</baseOpinionOffset>
            </li>
        </stages>
    </ThoughtDef>
⚠️ **GitHub.com Fallback** ⚠️