123 lines
4.1 KiB
C#
123 lines
4.1 KiB
C#
using Verse;
|
|
using Verse.Sound;
|
|
using System.Collections.Generic;
|
|
using RimWorld;
|
|
|
|
namespace ArachnaeSwarm;
|
|
|
|
public class CompHunterExplosion : ThingComp
|
|
{
|
|
private bool wickStarted;
|
|
|
|
private int wickTicks;
|
|
|
|
[Unsaved(false)]
|
|
private Sustainer wickSoundSustainer;
|
|
|
|
[Unsaved(false)]
|
|
private OverlayHandle? overlayBurningWick;
|
|
|
|
private CompProperties_HunterExplosion Props => (CompProperties_HunterExplosion)props;
|
|
|
|
public override void PostExposeData()
|
|
{
|
|
base.PostExposeData();
|
|
Scribe_Values.Look(ref wickStarted, "wickStarted", defaultValue: false);
|
|
Scribe_Values.Look(ref wickTicks, "wickTicks", 0);
|
|
}
|
|
|
|
public override void CompTickInterval(int delta)
|
|
{
|
|
if (!wickStarted && parent.IsHashIntervalTick(30, delta) && parent is Pawn { Spawned: not false, Downed: false } pawn && PawnUtility.EnemiesAreNearby(pawn, 9, passDoors: true, 1.5f))
|
|
{
|
|
StartWick();
|
|
}
|
|
}
|
|
|
|
public override void CompTick()
|
|
{
|
|
if (wickStarted)
|
|
{
|
|
wickSoundSustainer.Maintain();
|
|
wickTicks--;
|
|
if (wickTicks <= 0)
|
|
{
|
|
Detonate();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void StartWick()
|
|
{
|
|
if (!wickStarted)
|
|
{
|
|
wickStarted = true;
|
|
overlayBurningWick = parent.Map.overlayDrawer.Enable(parent, OverlayTypes.BurningWick);
|
|
wickSoundSustainer = SoundDefOf.HissSmall.TrySpawnSustainer(SoundInfo.InMap(parent, MaintenanceType.PerTick));
|
|
wickTicks = 120;
|
|
}
|
|
}
|
|
|
|
public override void Notify_Killed(Map prevMap, DamageInfo? dinfo = null)
|
|
{
|
|
if (dinfo.HasValue)
|
|
{
|
|
Detonate(prevMap);
|
|
}
|
|
}
|
|
|
|
private void Detonate(Map map = null)
|
|
{
|
|
IntVec3 position = parent.Position;
|
|
if (map == null)
|
|
{
|
|
map = parent.Map;
|
|
}
|
|
if (!parent.Destroyed)
|
|
{
|
|
parent.Destroy();
|
|
}
|
|
GenExplosion.DoExplosion(
|
|
center: position,
|
|
map: map,
|
|
radius: Props.explosionRadius,
|
|
damType: Props.explosionDamageType,
|
|
instigator: parent,
|
|
damAmount: Props.explosionDamageAmount,
|
|
armorPenetration: Props.armorPenetration,
|
|
explosionSound: Props.explosionSound,
|
|
weapon: Props.weapon,
|
|
projectile: Props.projectile,
|
|
intendedTarget: Props.intendedTarget,
|
|
postExplosionSpawnThingDef: Props.postExplosionSpawnThingDef,
|
|
postExplosionSpawnChance: Props.postExplosionSpawnChance,
|
|
postExplosionSpawnThingCount: Props.postExplosionSpawnThingCount,
|
|
postExplosionGasType: Props.postExplosionGasType,
|
|
postExplosionGasRadiusOverride: Props.postExplosionGasRadiusOverride,
|
|
postExplosionGasAmount: Props.postExplosionGasAmount,
|
|
applyDamageToExplosionCellsNeighbors: Props.applyDamageToExplosionCellsNeighbors,
|
|
preExplosionSpawnThingDef: Props.preExplosionSpawnThingDef,
|
|
preExplosionSpawnChance: Props.preExplosionSpawnChance,
|
|
preExplosionSpawnThingCount: Props.preExplosionSpawnThingCount,
|
|
chanceToStartFire: Props.chanceToStartFire,
|
|
damageFalloff: Props.damageFalloff,
|
|
direction: Props.direction,
|
|
ignoredThings: Props.ignoredThings,
|
|
affectedAngle: Props.affectedAngle,
|
|
doVisualEffects: Props.doVisualEffects,
|
|
propagationSpeed: Props.propagationSpeed,
|
|
excludeRadius: Props.excludeRadius,
|
|
doSoundEffects: Props.doSoundEffects,
|
|
postExplosionSpawnThingDefWater: Props.postExplosionSpawnThingDefWater,
|
|
screenShakeFactor: Props.screenShakeFactor,
|
|
flammabilityChanceCurve: Props.flammabilityChanceCurve,
|
|
overrideCells: Props.overrideCells,
|
|
postExplosionSpawnSingleThingDef: Props.postExplosionSpawnSingleThingDef,
|
|
preExplosionSpawnSingleThingDef: Props.preExplosionSpawnSingleThingDef
|
|
);
|
|
if (base.ParentHolder is Corpse corpse)
|
|
{
|
|
corpse.Destroy();
|
|
}
|
|
}
|
|
} |