public override void FinalizeInit() { base.FinalizeInit(); if (this.ToxicDamagesChunks != null) { foreach (var b in this.ToxicDamagesChunks) { foreach (var t in this.map.thingGrid.ThingsListAt(b.Key)) { if (PurpleIvyUtils.IsChunkOrMineable(t)) { this.ToxicDamagesChunksDeep[t] = b.Value; } } } } if (this.ToxicDamagesChunksDeep != null) { foreach (var b in this.ToxicDamagesChunksDeep) { this.ToxicDamages[b.Key] = b.Value; } } if (this.ToxicDamagesThings != null) { foreach (var b in this.ToxicDamagesThings) { this.ToxicDamages[b.Key] = b.Value; } } if (this.ToxicDamagesThings != null) { foreach (var b in this.ToxicDamages) { Log.Message("Notifying " + b.Key); ThingsToxicDamageSectionLayerUtility.Notify_ThingHitPointsChanged(this, b.Key, b.Key.MaxHitPoints); } } foreach (Thing t in this.map.listerThings.AllThings) { Pawn pawn = null; if (t is Pawn) { pawn = (Pawn)t; } else if (t is Corpse) { Corpse corpse = (Corpse)t; pawn = corpse.InnerPawn; } else { continue; } AlienInfectionHediff hediff = (AlienInfectionHediff)pawn.health.hediffSet.hediffs .Where(x => x is AlienInfectionHediff).FirstOrDefault(); if (hediff != null) { var comp = pawn.TryGetComp <AlienInfection>(); if (comp == null) { if (hediff.instigator != null) { var dummyCorpse = PurpleIvyDefOf.InfectedCorpseDummy; comp = new AlienInfection(); comp.Initialize(dummyCorpse.GetCompProperties <CompProperties_AlienInfection>()); comp.parent = pawn; comp.Props.typesOfCreatures = new List <string>() { hediff.instigator.defName }; var range = PurpleIvyData.maxNumberOfCreatures[hediff.instigator.race.defName]; comp.maxNumberOfCreatures = hediff.maxNumberOfCreatures; comp.currentCountOfCreatures = hediff.currentCountOfCreatures; comp.startOfIncubation = hediff.startOfIncubation; comp.tickStartHediff = hediff.tickStartHediff; comp.stopSpawning = hediff.stopSpawning; comp.Props.maxNumberOfCreatures = range; comp.Props.incubationPeriod = new IntRange(10000, 40000); comp.Props.IncubationData = new IncubationData(); comp.Props.IncubationData.tickStartHediff = new IntRange(2000, 4000); comp.Props.IncubationData.deathChance = 90; comp.Props.IncubationData.hediff = HediffDefOf.Pregnant.defName; if (pawn.Dead) { var corpse = pawn.Corpse; corpse.AllComps.Add(comp); } else { pawn.AllComps.Add(comp); } } } else if (pawn.Dead && comp != null) { var corpse = pawn.Corpse; corpse.AllComps.Add(comp); } } } }
public void DoDamageToBuildings() { List <Thing> list = new List <Thing>(); foreach (var pos2 in GenAdj.CellsAdjacent8Way(this)) { try { if (GenGrid.InBounds(pos2, this.Map)) { list = this.Map.thingGrid.ThingsListAt(pos2); } } catch { continue; } for (int i = 0; i < list.Count; i++) { if (list[i].Faction != PurpleIvyData.AlienFaction) { if (list[i] is Pawn || list[i] is Gas || list[i] is Mote || list[i] is Filth) { continue; } var comp = this.Map.GetComponent <MapComponent_MapEvents>(); if (comp != null) { int oldDamage = 0; if (!comp.ToxicDamages.ContainsKey(list[i])) { if (PurpleIvyUtils.IsChunkOrMineable(list[i])) { comp.ToxicDamagesChunksDeep[list[i]] = list[i].MaxHitPoints - 1; } else { //Log.Message("Loading: " + list[i], true); comp.ToxicDamagesThings[list[i]] = list[i].MaxHitPoints - 1; } oldDamage = list[i].MaxHitPoints; comp.ToxicDamages[list[i]] = list[i].MaxHitPoints - 1; } else { oldDamage = comp.ToxicDamages[list[i]]; comp.ToxicDamages[list[i]] -= 1; } //Log.Message("Damaging " + list[i], true); ThingsToxicDamageSectionLayerUtility.Notify_ThingHitPointsChanged(comp, list[i], oldDamage); if (list[i] is Building b && comp.ToxicDamages[b] / 2 < b.MaxHitPoints) { if (b.GetComp <CompBreakdownable>() != null) { b.GetComp <CompBreakdownable>().DoBreakdown(); } if (b.GetComp <CompPowerPlantWind>() != null) { b.GetComp <CompPowerPlantWind>().PowerOutput /= 2f; } if (b.GetComp <CompPowerTrader>() != null) { b.GetComp <CompPowerTrader>().PowerOn = false; } } } } } } }