Shield Hediffs - SmArtKar/AthenaFramework GitHub Wiki

By adding HediffCompProperties_Shield you can make your hediff apply a shield. Preventing pawns from using ranged weapons isn't supported at the moment. In addition to the fields below, shield hediffs can use all the features of normal renderable hediffs. ParentColor and ParentGradient mask types in additional graphic packages use shield's percentage of remaining health, allowing you to color them based on how much HP they have left.

    public class HediffCompProperties_Shield : HediffCompProperties_Renderable
    {
        // Maximum amount of energy that the shield can hold
        public float maxEnergy = 0f;
        // How much energy is recharged every tick
        public float energyRechargeRate = 0f;
        // How much energy is lost per unit of damage
        public float energyPerDamageModifier = 0.33f;
        // How long(in ticks) it takes for a shield to go back online after it has been destroyed
        public int resetDelay = 1;
        // What fraction of shield's max energy it has after resetting
        public float energyOnReset = 0.2f;
        // What fraction of shield's max energy should it start after being applied
        public float energyOnStart = 1f;
        // Whenever the shield blocks all damage/stun from the attack that breaks it or not
        public bool blockOverdamage = true;
        // Whenever the shield reduces damage/stun of the attack that broke it by what energy it had left(considering energyPerDamageModifier and energyPerStunModifier)
        public bool consumeOverdamage = false;
        // Whenever the shield hediff should be removed upon being broken
        public bool removeOnBreak = false;
        // If the shield is affected by parent's shield health and recharge speed stats
        public bool affectedByStats = true;

        // Whenever the shield blocks ranged/explosive/melee damage
        public bool blocksRangedDamage = true;
        public bool blocksExplosions = true;
        public bool blocksMeleeDamage = false;

        // List of whitelisted DamageDefs. When set, DamageDefs that are not in this list won't be affected.
        public List<DamageDef> whitelistedDamageDefs;
        // List of blacklisted DamageDefs. When set, DamageDefs that are in this list won't be affected.
        public List<DamageDef> blacklistedDamageDefs;

        // List of DamageInfoPack with additional energy cosumption modifiers and overrides for block types for certain DamageDefs
        public List<DamageInfoPack> damageInfoPacks;

        // What types of damage should cause the shield to instantly shatter
        public List<DamageDef> shatterOn;
        // If the shield should create an explosion upon being destroyed
        public bool explosionOnShieldBreak = false;
        // Damage type and radius of the explosion
        public DamageDef explosionDef;
        public float explosionRadius = 2.9f;

        // Shield sounds and flecks
        public SoundDef absorbSound;
        public SoundDef resetSound;

        public FleckDef absorbFleck;
        public FleckDef breakFleck;
        // Effecter that's used upon shield shattering
        public EffecterDef shieldBreakEffecter;

        // Whenever the shield should display a charge gizmo and what text and hover tip should it have
        public bool displayGizmo = true;
        public string gizmoTitle = "";
        public string gizmoTip = "";

        // Shield scale based on amount of energy left
        public float minDrawSize = 1.2f;
        public float maxDrawSize = 1.55f;
        // Whenever the shield should scale with owner's draw size
        public bool scaleWithOwner = true;
        // Whenever the shield should have the vanilla spinning effect. Turn off in case you're using custom asymmetric textures
        public bool spinning = true;
    }

    public struct DamageInfoPack
    {
        public DamageDef damageDef;
        public float energyModifier = 1f;

        public bool blocksRangedDamage = true;
        public bool blocksExplosions = true;
        public bool blocksMeleeDamage = false;

        public DamageInfoPack() { }
    }

You can adjust block parameters of certain damage types via DamageInfoPack. Consumption modifier of each pack is used along with the default energy modifier, while block settings override the default ones.

Here's an example of a hediff that applies a shield with EMP blocking and a glow mote effect

  <HediffDef>
    <defName>ShieldWithEMPBlock</defName>
    <label>shield with an EMP block</label>
    <description>A shield hediff that has 200 energy and blocks EMPs.</description>
    <hediffClass>HediffWithComps</hediffClass>
    <comps>
      <li Class="AthenaFramework.HediffCompProperties_Shield">
        <maxEnergy>200</maxEnergy>
        <energyRechargeRate>0.14</energyRechargeRate>
        <resetDelay>3200</resetDelay>

        <whitelistedDamageDefs>
          <li>EMP</li>
        </whitelistedDamageDefs>
        <energyPerDamageModifier>0</energyPerDamageModifier>
        <shatterOn /> <!-- This makes shatterOn into an empty list, overriding the default behavior of breaking upon being EMPed -->

        <absorbFleck>ExplosionFlash</absorbFleck>
        <breakFleck>ExplosionFlash</breakFleck>
        <shieldBreakEffecter>Shield_Break</shieldBreakEffecter>

        <absorbSound>EnergyShield_AbsorbDamage</absorbSound>
        <resetSound>EnergyShield_Reset</resetSound>

        <displayGizmo>true</displayGizmo>
        <gizmoTitle>shield with an EMP block</gizmoTitle>
        <gizmoTip>A shield hediff that has 200 energy and blocks EMPs.</gizmoTip>

        <minDrawSize>1.2</minDrawSize>
        <maxDrawSize>1.55</maxDrawSize>
        <scaleWithOwner>true</scaleWithOwner>
        <graphicData>
          <texPath>Other/ShieldBubble</texPath>
          <graphicClass>Graphic_Single</graphicClass>
          <shaderType>Transparent</shaderType>
          <color>(1.0, 0.9, 0.5)</color>
        </graphicData>
        <attachedMoteDef>AM_Mote_MechApotheosisGlow</attachedMoteDef>
      </li>
    </comps>
  </HediffDef>
⚠️ **GitHub.com Fallback** ⚠️