ApparelExtension - Vanilla-Expanded/VanillaExpandedFramework GitHub Wiki

<- Back

ApparelExtension adds a few new behaviours to apparel or weapons:

       public float priority = 0f;

       public float skillGainModifier = 1f;
       public WorkTags workDisables;
       public List<SkillDef> skillDisables;

       public List<StatModifier> equippedStatFactors;
       public List<TraitRequirement> traitsOnEquip;
       public List<TraitRequirement> traitsOnUnequip;
       public List<PawnCapacityMinLevel> pawnCapacityMinLevels;
       public bool preventDowning;
       public bool preventKilling;
       public float preventKillingUntilHealthHPPercentage = 1f;
       public bool preventKillingUntilBrainMissing;
       public bool preventBleeding;

       // Apparel-only. Doesn't apply to weapons.
       public List<ThingDef> secondaryApparelGraphics;
       public bool isUnifiedApparel;
       public bool hideHead;
       public bool showBodyInBedAlways;

ApparelExtension, despite what the name may suggest, support equipment (weapons/tools). The functionality was added later on, but the name was kept for backwards compatibility reasons.

PawnCapacityMinLevel is a container class:

       public class PawnCapacityMinLevel
       {
           public PawnCapacityDef capacity;
           public float minLevel;
       }

TraitRequirement is a vanilla class used in a couple places like MemeDef.agreeableTraits, MemeDef.disagreeableTraits, ThoughtDef.nullifyingTraitDegrees, and a few others. TraitRequirement allows for the same XML as TraitDef that was used previously if you don't specify a degree, with the added benefit of being able to specify a degree.

How do I use this code?

Def extensions are added to the <modExtensions> tag of a ThingDef. For example, this is added to the jester outfit in VFE Medieval 2

<modExtensions>
    <li Class="VEF.Apparels.ApparelExtension">
        <skillGainModifier>0</skillGainModifier>
    </li>
</modExtensions>

And this is the dame dress in the same mod:

<modExtensions>
    <li Class="VEF.Apparels.ApparelExtension">
        <workDisables>
            <li>ManualDumb</li>
        </workDisables>
    </li>
</modExtensions>

ApparelExtensions supports inheritance/merging - if a def has several of this extension present, they'll be merged into a single one:

<Def Name="MyParentDef">
    <modExtensions>
        <li Class="VEF.Apparels.ApparelExtension">
            <!-- When inheriting, this extension will be merged after any extensions that use a default priority of 1. -->
            <priority>-1000</priority>
            <workDisables>
                <li>ManualDumb</li>
            </workDisables>
            <skillGainModifier>1.5</skillGainModifier>
            <traitsOnEquip>
                <!-- Give pawns "chemical fascination" trait on equip. -->
                <!-- This will be replaced if another extension with a higher priority specifies a different degree. -->
                <DrugDesire>2</DrugDesire>
            </traitsOnEquip>
        </li>
    </modExtensions>
</Def>

<Def ParentName="MyParentDef">
    <modExtensions>
        <li Class="VEF.Apparels.ApparelExtension">
            <!-- The work disables will be taken from parent def's extension, and combined with the ones in here. -->
            <workDisables>
                <li>Intellectual</li>
                <li>Artistic</li>
                <!-- This will inherit ManualDumb from parent. -->
            </workDisables>
            <!-- Works with all properties. A value that does something (like true in here) will take precedence over one that does nothing. -->
            <preventDowning>true</preventDowning>
            <!-- skillGainModifier, preventKillingUntilHealthHPPercentage, and equippedStatFactors will be multiplied together. -->
            <!-- In this example, 1.5 from parent and 0.75 from here would result in 1.125 total skillGainModifier. -->
            <skillGainModifier>0.75</skillGainModifier>
            <traitsOnEquip>
                <!-- Give pawns "teetotaler" trait on equip. -->
                <!-- Since this extension has a higher <priority> than the one this def inherits, it'll replace the trait from the parent. -->
                <DrugDesire>-1</DrugDesire>
                <!-- Give pawns "Ascetic" trait on equip. -->
                <!-- Since this trait has no degrees it doesn't matter if parent def has this trait or not. -->
                <li>Ascetic</li>
            </traitsOnEquip>
        </li>
        <!-- The merging also works if there's multiple extensions in a single def directly, not only if it's inherited from a parent. -->
        <!-- This means that, for example, multiple mods can safely add this extension to the same def using XML patches. -->
    </modExtensions>
</Def>
⚠️ **GitHub.com Fallback** ⚠️