SHORTUTORIAL: JecsTools.CompAbilityUser - roxxploxx/RimWorldModGuide GitHub Wiki

!!!In Progress!!!

"RimWorld Pawn Component. This allows developers to create their own "verbs" that can be added to pawns as buttons. Spells with cooldowns? Check. Original credit goes to Cpt. Ohu for creating the original code. This was primarily extracted from the Warhammer 40k project with select changes. https://ludeon.com/forums/index.php?topic=28422.0"

Github Location: jecrell/JecsTools


See this example of a Spellbook created using this mod : Unifica Magica Wizard Spellbook


  1. Extend CompAbilityUser
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Verse;
using Verse.AI;
using AbilityUser;

namespace UnificaMagica
{

    public class MyCompAbilityUser : CompAbilityUser
    {
        public override void CompTick() {
            base.CompTick();
            if ( IsInitialized ) {
              // any custom code
            }
        }

        public override void PostInitialize() {
            base.PostInitialize();

            // add Abilities
            this.AddPawnAbility(MyNamespaceDefOf.MyAbility);
        }

        public override bool TryTransformPawn() {
          // if true, transforms this pawn into this AbilityUser (i.e. initialize)
          // So, you can have it check for a trait before initializing 
          // by default, it returns true
        }
    }
}
  1. Create a file to define the ability
using System;
using Verse;
using RimWorld;
using AbilityUser;

namespace MyNamespace
{
    [DefOf]
    public static class MyNamespaceDefOf
    {
        public static AbilityDef MyAbility;
    }
}
  1. Define Abilities in XML
<?xml version="1.0" encoding="utf-8" ?>
<ThingDefs>

    <ThingDef ParentName="BaseBullet" Class="AbilityUser.ProjectileDef_AbilityLaser">
        <thingClass>AbilityUser.Projectile_AbilityLaser</thingClass>
        <defName>Projectile_MyAbility</defName>
        <label>my ability projectile</label>
        <graphicData>
            <texPath>Things/Projectile/Bullet_Small</texPath>
            <graphicClass>Graphic_Single</graphicClass>
        </graphicData>
        <projectile>
            <flyOverhead>false</flyOverhead>
            <damageDef>Bullet</damageDef>
            <damageAmountBase>10</damageAmountBase>
            <speed>70</speed>
        </projectile>
        <preFiringInitialIntensity>0</preFiringInitialIntensity>
        <preFiringFinalIntensity>20</preFiringFinalIntensity>
        <postFiringInitialIntensity>20</postFiringInitialIntensity>
        <postFiringFinalIntensity>0</postFiringFinalIntensity>
        <preFiringDuration>10</preFiringDuration>
        <postFiringDuration>83</postFiringDuration>
        <StartFireChance>0.000</StartFireChance>
    </ThingDef>

    <ThingDef Class="AbiltyUser.AbilityDef" ParentName="BaseAbility">
        <defName>MyAbility</defName>
        <label>my ability</label>
        <uiIconPath>UI/Glow_Corrupt</uiIconPath>
        <description>Drain another entity of lifeforce.</description>
        <MainVerb Class="AbilityUser.VerbProperties_Ability">
            <verbClass>AbilityUser.Verb_UseAbility</verbClass>
            <tooltipShowProjectileDamage>true</tooltipShowProjectileDamage>
            <tooltipShowExtraDamages>false</tooltipShowExtraDamages>
            <tooltipShowHediffsToApply>false</tooltipShowHediffsToApply>
            <tooltipShowMentalStatesToApply>false</tooltipShowMentalStatesToApply>
            <hasStandardCommand>true</hasStandardCommand>
            <projectileDef>Projectile_MyAbility</projectileDef>
            <abilityDef>MyAbility</abilityDef>
            <warmupTime>1</warmupTime>
            <SecondsToRecharge>10.0</SecondsToRecharge>
            <range>24</range>
            <burstShotCount>1</burstShotCount>
            <ticksBetweenBurstShots>2</ticksBetweenBurstShots>
            <soundCast>MessageBenefit</soundCast>
            <muzzleFlashScale>20</muzzleFlashScale>
            <isPrimary>false</isPrimary>
        </MainVerb>
    </ThingDef>
</ThingDefs>
  1. To cover:
  • loading values from file
  • look at the Star Wars mods for examples
  • defining new Abilities in C# code
⚠️ **GitHub.com Fallback** ⚠️