Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a DefModExtension to support custom Undead hediffdef #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Defs/HediffDefs/Hediffs_Necro.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
<maxSeverity>4.0</maxSeverity>
<initialSeverity>0.95</initialSeverity>
<isBad>false</isBad>
<!--<modExtensions>
<li Class="TorannMagic.DefModExtension_NecroStarvation"> Uncomment this to make humanlike undead recieve a hediff when no necrotic energy is available
<effect>RayofHope</effect> The hediff will be cured when a Necro or Lich comes nearby, but not by necrotic orbs.
</li> Not tested with severity-based hediff
</modExtensions>-->
<comps>
<li>
<compClass>TorannMagic.HediffComp_Undead</compClass>
Expand Down
18 changes: 18 additions & 0 deletions Source/TMagic/TMagic/DefModExtension_NecroStarvation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using RimWorld;
using AbilityUser;
using Verse;
using UnityEngine;

namespace TorannMagic
{
class DefModExtension_NecroStarvation : DefModExtension
{
public HediffDef effect;
public DefModExtension_NecroStarvation() : base()
{
}
}
}
21 changes: 17 additions & 4 deletions Source/TMagic/TMagic/HediffComp_Undead.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace TorannMagic
[StaticConstructorOnStartup]
class HediffComp_Undead : HediffComp
{
public HediffDef starvationEffect;
private bool necroValid = true;
private int lichStrike = 0;
private bool initializing = true;
Expand All @@ -37,7 +38,11 @@ private void Initialize()
if (spawned)
{
//MoteMaker.ThrowLightningGlow(base.Pawn.TrueCenter(), base.Pawn.Map, 3f);
}
}
if (this.Def.HasModExtension<DefModExtension_NecroStarvation>())
{
this.starvationEffect = this.Def.GetModExtension<DefModExtension_NecroStarvation>().effect;
}
}

public override void CompPostTick(ref float severityAdjustment)
Expand Down Expand Up @@ -129,6 +134,10 @@ public override void CompPostTick(ref float severityAdjustment)
//necromancer alive to sustain undead
necroValid = true;
lichStrike = 0;
if (starvationEffect != null && base.Pawn.health.hediffSet.HasHediff(starvationEffect))
{
HealthUtility.CureHediff(base.Pawn.health.hediffSet.GetFirstHediffOfDef(starvationEffect));
}
}
}
}
Expand Down Expand Up @@ -168,13 +177,17 @@ public override void CompPostTick(ref float severityAdjustment)

if (!necroValid && orbEnergy <= 0)
{
if (base.Pawn.Map != null)
if (starvationEffect != null)
{
TM_MoteMaker.ThrowScreamMote(base.Pawn.Position.ToVector3(), base.Pawn.Map, .8f, 255, 255, 255);
base.Pawn.Kill(null, null);
ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef();
HealthUtility.AdjustSeverity(base.Pawn, starvationEffect, settingsRef.undeadUpkeepMultiplier);
}
else
{
if (base.Pawn.Map != null)
{
TM_MoteMaker.ThrowScreamMote(base.Pawn.Position.ToVector3(), base.Pawn.Map, .8f, 255, 255, 255);
}
base.Pawn.Kill(null, null);
}
}
Expand Down
1 change: 1 addition & 0 deletions Source/TMagic/TMagic/TorannMagic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@
<Compile Include="Weapon\SeerRing_Lightning.cs" />
<Compile Include="Weapon\SeerRing_Ice.cs" />
<Compile Include="Weapon\SeerRing_Fire.cs" />
<Compile Include="DefModExtension_NecroStarvation.cs" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down