Skip to content

Commit

Permalink
Health points
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxDorob committed Nov 29, 2024
1 parent ba5e06a commit 3989b82
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
1 change: 1 addition & 0 deletions Patches/Core/Skyfallers/SkyfallerBase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<value>
<li Class="CombatExtended.CompProperties_CIWSImpactHandler">
<compClass>CombatExtended.CompCIWSImpactHandler_Skyfaller</compClass>
<HP>22</HP>
</li>
</value>
</Operation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ namespace CombatExtended
{
public class CompCIWSImpactHandler : ThingComp
{
public CompProperties_CIWSImpactHandler Props => props as CompProperties_CIWSImpactHandler;
private float hp;

public float HP
{
get => hp;
set => hp = value;
}
public CompProperties_CIWSImpactHandler Props => props as CompProperties_CIWSImpactHandler;
public virtual void OnImpact(ProjectileCE projectile, DamageInfo dinfo)
{
if (!Props.impacted.NullOrUndefined())
Expand All @@ -24,8 +30,33 @@ public virtual void OnImpact(ProjectileCE projectile, DamageInfo dinfo)
{
Props.impactEffecter.Spawn(parent.DrawPos.ToIntVec3(), parent.Map);
}
ApplyDamage(dinfo);
}
public virtual void ApplyDamage(DamageInfo dinfo)
{
HP -= dinfo.Amount;
if (HP <= 0.00001f && !parent.Destroyed)
{
OnDestroying(dinfo);
}
}
protected virtual void OnDestroying(DamageInfo dinfo)
{
parent.Destroy(DestroyMode.Vanish);
}
public override void PostExposeData()
{
base.PostExposeData();
Scribe_Values.Look(ref hp, nameof(HP));
}
public override void PostSpawnSetup(bool respawningAfterLoad)
{
base.PostSpawnSetup(respawningAfterLoad);
if (!respawningAfterLoad)
{
HP = Props.HP;
}
}

}
public class CompProperties_CIWSImpactHandler : CompProperties
Expand All @@ -34,6 +65,7 @@ public CompProperties_CIWSImpactHandler()
{
compClass = typeof(CompCIWSImpactHandler);
}
public float HP = 0.0001f;
public SoundDef impacted;
public EffecterDef impactEffecter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ namespace CombatExtended
public class CompCIWSImpactHandler_Skyfaller : CompCIWSImpactHandler
{
public override void OnImpact(ProjectileCE projectile, DamageInfo dinfo)
{

base.OnImpact(projectile, dinfo);
if (!parent.Destroyed)
{
if (parent is IThingHolder pod)
{
var pawns = pod.ContainedThings().OfType<Pawn>().ToList();
if (pawns.Any())
{
pawns.RandomElement().TakeDamage(dinfo);
}
}
}
}
protected override void OnDestroying(DamageInfo dinfo)
{
if (parent is IThingHolder pod)
{
Expand All @@ -25,7 +41,7 @@ public override void OnImpact(ProjectileCE projectile, DamageInfo dinfo)
GenLeaving.DoLeavingsFor(thing, parent.Map, DestroyMode.KillFinalize, CellRect.CenteredOn(parent.Position, thing.def.size), listOfLeavingsOut: leavingList);
continue;
}
TryDropThing(thing, projectile.Map, projectile.Position);
TryDropThing(thing, parent.Map, parent.DrawPos.ToIntVec3());
if (thing is Pawn pawn)
{
pawn.TakeDamage(dinfo);
Expand All @@ -41,8 +57,7 @@ public override void OnImpact(ProjectileCE projectile, DamageInfo dinfo)

}
}
base.OnImpact(projectile, dinfo);

base.OnDestroying(dinfo);
}
private Thing TryDropThing(Thing thing, Map map, IntVec3 position)
{
Expand Down

0 comments on commit 3989b82

Please sign in to comment.