public override void PostPostRemove() { Log.Message("PostPostRemove"); this.counter = 0; this.StopInfection(); this.radius = -1; // -1 is set to allow filRadius remove alien biome in the place PurpleIvyData.BiomesDirty = true; PurpleIvyData.BiomesToClear = true; PurpleIvyUtils.UpdateBiomes(); base.PostPostRemove(); }
public override void GameComponentTick() { base.GameComponentTick(); bool temp; if (PurpleIvyData.BiomesDirty == true) { PurpleIvyUtils.UpdateBiomes(); } if (Find.TickManager.TicksGame % 3451 == 0) // same as for toxic weather { bool raidHappened = false; var tempComp = new WorldObjectComp_InfectedTile(); Log.Message("Total polluted biomes to check: " + PurpleIvyData.TotalPollutedBiomes.Count); foreach (var tile in PurpleIvyData.TotalPollutedBiomes) { var worldObjects = Find.WorldObjects.ObjectsAt(tile); foreach (var worldObject in worldObjects) { if (worldObject is Caravan caravan) { tempComp.infectedTile = caravan.Tile; float fogProgress = PurpleIvyUtils.getFogProgressWithOuterSources(0, tempComp, out temp); if (fogProgress > 0f) { foreach (Pawn p in caravan.pawns) { if (p.Faction != PurpleIvyData.AlienFaction && p.RaceProps.IsFlesh) { float num = fogProgress / 20; //TODO: balance it num *= p.GetStatValue(StatDefOf.ToxicSensitivity, true); if (num != 0f) { HealthUtility.AdjustSeverity(p, HediffDefOf.ToxicBuildup, num); } } } } if (raidHappened != true) { var infectedSites = getInfectedTilesNearby(worldObject.Tile); if (infectedSites != null && infectedSites.Count > 0) { if (fogProgress > 0.7f) { fogProgress = 0.7f; } int raidChance = (int)(fogProgress * 100); System.Random random = new System.Random(caravan.Tile); Log.Message("An attempt to ambush caravan, raid chance: " + raidChance.ToString() + " - fogProgress: " + fogProgress.ToString()); if (raidChance >= random.Next(1, 100)) { Log.Message("The caravan has been ambushed! RaidChance: " + raidChance.ToString() + " - fogProgress: " + fogProgress.ToString()); this.AlienAmbush(caravan, infectedSites.RandomElement()); raidHappened = true; } } } } else if (worldObject is MapParent mapParent) { tempComp.infectedTile = mapParent.Tile; float?fogProgress = null; if (raidHappened != true && mapParent.Map != null) { var infectedSites = getInfectedTilesNearby(mapParent.Tile); if (infectedSites != null && infectedSites.Count > 0) { fogProgress = PurpleIvyUtils.getFogProgressWithOuterSources(0, tempComp, out temp); int raidChance = (int)(fogProgress * 100) / 10; System.Random random = new System.Random(); int randomChance = random.Next(1, 100); Log.Message("An attempt to raid map, raid chance: " + raidChance.ToString() + " - randomChance: " + randomChance.ToString() + " - fogProgress: " + fogProgress.ToString()); if (raidChance >= randomChance) { Log.Message("Alien Raid! RaidChance: " + raidChance.ToString() + " - fogProgress: " + fogProgress.ToString() + " map: " + mapParent.Map.ToString()); this.AlienRaid(mapParent.Map, infectedSites.RandomElement()); raidHappened = true; } } } if (mapParent.Faction != Faction.OfPlayer && mapParent.Faction != PurpleIvyData.AlienFaction) { if (!fogProgress.HasValue) { fogProgress = PurpleIvyUtils.getFogProgressWithOuterSources(0, tempComp, out temp); } if (fogProgress > 0f) { int abandonChance = (int)(fogProgress * 100) / 10; System.Random random = new System.Random(Find.TickManager.TicksGame); Log.Message(mapParent.Faction.ToString()); Log.Message("An attempt to abandon NPC base, abandon chance: " + abandonChance.ToString() + " - fogProgress: " + fogProgress.ToString()); if (abandonChance >= random.Next(1, 100)) { Log.Message("NPC base abandoned! Chance: " + abandonChance.ToString() + " - fogProgress: " + fogProgress.ToString() + " base: " + mapParent.ToString()); Site site = (Site)WorldObjectMaker.MakeWorldObject(PurpleIvyDefOf.PI_AbandonedBase); site.Tile = mapParent.Tile; site.SetFaction(mapParent.Faction); mapParent.Destroy(); Find.LetterStack.ReceiveLetter("AbandonedBase".Translate(), "AbandonedBaseDesc".Translate(), LetterDefOf.NeutralEvent, site, mapParent.Faction, null, null, null); } else { int defeatChance = (int)(fogProgress * 100) / 10; random = new System.Random(Find.TickManager.TicksGame + mapParent.Tile); Log.Message(mapParent.Faction.ToString()); Log.Message("An attempt to defeat NPC base, defeat chance: " + abandonChance.ToString() + " - fogProgress: " + fogProgress.ToString()); if (defeatChance >= random.Next(1, 100)) { Log.Message("NPC base defeated! Chance: " + defeatChance.ToString() + " - fogProgress: " + fogProgress.ToString() + " base: " + mapParent.ToString()); Site site = (Site)WorldObjectMaker.MakeWorldObject(PurpleIvyDefOf.PI_DefeatedBase); site.Tile = mapParent.Tile; site.SetFaction(mapParent.Faction); mapParent.Destroy(); Find.LetterStack.ReceiveLetter("DefeatedBase".Translate(), "DefeatedBaseDesc".Translate(), LetterDefOf.NegativeEvent, site, mapParent.Faction, null, null, null); } } } } } } } } }