User:Mehni

From RimWorld Wiki
Revision as of 16:42, 7 February 2019 by Mehni (talk | contribs) (sandbox)
Jump to navigation Jump to search
<?xml version="1.0" encoding="utf-8" ?>
<Defs>

    <!-- The Class="Plague.ThingDef_PlagueBullet links this XML Def to a Class. -->
    <!-- Our class is named ThingDef_PlagueBullet, and is found in the Plague namespace." -->
    <!-- Tags with an empty comment behind them are changed from their original values. -->

    <ThingDef Class="Plague.ThingDef_PlagueBullet" ParentName="BaseBullet">
        <defName>TST_Bullet_PlagueGun</defName> <!-- -->
        <label>plague bullet</label> <!-- -->
        <graphicData>
            <texPath>Things/Projectile/Bullet_Small</texPath>
            <graphicClass>Graphic_Single</graphicClass>
        </graphicData>
        <projectile>
            <flyOverhead>false</flyOverhead>
            <damageDef>Bullet</damageDef>
            <damageAmountBase>12</damageAmountBase>
            <stoppingPower>1</stoppingPower>
            <speed>55</speed>
        </projectile>
        <!-- The below three lines are added for the C# portion of the mod. -->
        <AddHediffChance>0.05</AddHediffChance>
        <HediffToAdd>Plague</HediffToAdd>
        <thingClass>Plague.Projectile_PlagueBullet</thingClass>
    </ThingDef>
</Defs>

<source lang="csharp">
using RimWorld;
using Verse;

namespace Plague
{
    public class ThingDef_PlagueBullet : ThingDef
    {
        public float AddHediffChance = 0.05f;
        public HediffDef HediffToAdd;

        public override void ResolveReferences()
        {
            HediffToAdd = HediffDefOf.Plague;
        }
    }
}


using Verse;
using RimWorld;

namespace Plague
{
    public class Projectile_PlagueBullet : Bullet
    {
        #region Properties
        public ThingDef_PlagueBullet Def
        {
            get
            {
                //Case sensitive! If you use Def it will return Def, which is this getter. This will cause a never ending cycle and a stack overflow.
                return this.def as ThingDef_PlagueBullet;
            }
        }
        #endregion

        #region Overrides
        protected override void Impact(Thing hitThing)
        {
            /* This is a call to the Impact method of the class we're inheriting from.
             * You can use your favourite decompiler to see what it does, but suffice to say
             * there are useful things in there, like damaging/killing the hitThing.
             */
            base.Impact(hitThing);

        }
        #endregion Overrides
    }
}