Equipment Restricting - KonradHeinser/EBSGFramework GitHub Wiki
This started with me making some apparel only equippable by a specific xenotype, and has now been expanded to cover a lot more. The EquipRestrictExtension allows you to stop pawns from equipping things if they lack/have specific genes, a specific xenotype, or a specific hediff. It also allows you to go the other direction, limiting a xenotype/carriers of a gene to only use a specific set of equipment, or only forbidding certain equipment.
This works by creating lists of defs that are checked whenever Rimworld needs to verify if equipment is equippable. All of these require the following extension:
<modExtensions>
<li Class="EBSGFramework.EquipRestrictExtension">
</li>
</modExtensions>
In that extension goes tags with lists inside of them. For example, the Grimworld code has Ratling apparel only equippable by the Ratling xenotype, the adapted version of it looking like this:
<modExtensions>
<li Class="EBSGFramework.EquipRestrictExtension">
<requireOneOfXenotypeToEquip>
<li>GW_Ratling</li>
</requireOneOfXenotypeToEquip>
</li>
</modExtensions>
Rimworld's inheritance system sometimes causes xenotypes to be lost after a generation or two. One way to avoid this is to attempt to condense a lot of the xenotype's effects into a singular gene, and making that gene the restriction determiner. There are still xenotype options for those who do not wish to, or simply cannot, use that method, but please be aware that Rimworld may pull a Randy on you.
These categories can be mixed as desired, though if you use multiple lists test thoroughly to ensure you don't accidentally make an item impossible to equip. The categories that can be attached to things are:
- requiredGenesToEquip : The pawn must have all of these genes
- requireOneOfGenesToEquip : The pawn must have any one of these genes
- forbiddenGenesToEquip : The pawn must have none of these genes
- requireOneOfXenotypeToEquip : The pawn must be one of these xenotypes
- forbiddenXenotypesToEquip : The pawn is not allowed to be any of these xenotypes
- requiredHediffsToEquip : The pawn must have all of these hediffs
- requireOneOfHediffsToEquip : The pawn must have any one of these hediffs
- forbiddenHediffsToEquip : The pawn must have none of these hediffs
These categories don't really mix well together (apparels and weapons can if you really, really want to). The mod first checks the pawn's xenotype, then their genes. Note that if you are using this on a gene, it's recommended to add the Hediff Adder geneClass if possible so it can check some edge case scenarios when the gene is added. If your gene is using a geneClass not from this framework it should still be fine as the issue in question is just a bug where pawns won't remove clothing/weapons if they gain the gene mid-game, which is something you can warn players about. The categories that can be attached to genes and xenotypes are:
- limitedToEquipments : The only equipment the pawn can use at all are items on this list. If you want them to be able to equip it, it must be on this list
- limitedToApparels : The only apparel the pawn can use are items on this list
- limitedToWeapons : The only weapons the pawn can use are items on this list
- forbiddenEquipments : The pawn cannot equip items on this list
These last few completely disable equipping anything in that category. Only use these if you never want the pawn to equip any of the covered equipment:
- restrictedLayers : A list of ApparelLayerDefs that the gene/xenotype restricts
- layerEquipExceptions : A list of ThingDefs that can be equipped despite the restricted layer
- noEquipment : Default (False) : Completely stops the pawn from equipping anything
- noApparel : Default (False) : Completely stops the pawn from equipping anything that Rimworld calls apparel
- noWeapons : Default (False) : Completely stops the pawn from equipping anything that Rimworld calls a weapon
- onlyRanged : Default (False) : Completely stops the pawn from equipping anything that Rimworld calls a ranged weapon. Will not stop ranged abilities from being used
- onlyMelee: Default (False) : Completely stops the pawn from equipping anything that Rimworld calls a melee weapon. Will not stop pawns from using unarmed attacks or ranged weapon tools to avoid potential errors
This example could be added to a gene or xenotype to stop pawns from equipping any weapon that is not a vanilla club
<modExtensions>
<li Class="EBSGFramework.EquipRestrictExtension">
<limitedToWeapons>
<li>MeleeWeapon_Club</li>
</limitedToWeapons>
</li>
</modExtensions>