static void Postfix(ref Thing __instance, bool respawningAfterLoad) { if (!usingExtensions || !__instance.def.HasModExtension <Flecker>()) { return; } Flecker modX = __instance.def.GetModExtension <Flecker>(); ThingWithComps fleckerHolder = new ThingWithComps() { def = __instance.def, Position = __instance.Position, mapIndexOrState = __instance.mapIndexOrState }; CompProperties_Smoker props = new CompProperties_Smoker() { particleOffset = modX.particleOffset, particleOffsetEast = modX.particleOffsetEast, particleOffsetNorth = modX.particleOffsetNorth, particleOffsetSouth = modX.particleOffsetSouth, particleOffsetWest = modX.particleOffsetWest, particleSize = modX.particleSize, fleckDef = modX.fleckDef, indoorAlt = modX.indoorAlt, idleAlt = modX.idleAlt, billsOnly = modX.billsOnly, alwaysSmoke = modX.alwaysSmoke, driver = modX.driver, compClass = typeof(CompFlecker) }; //Null checks if (props.fleckDef == null) { props.fleckDef = RimWorld.FleckDefOf.Smoke; } if (props.particleSize == 0) { props.particleSize = 1f; } CompFlecker comp = new CompFlecker() { parent = fleckerHolder, props = props, trueParent = __instance }; registry.Add(__instance, comp); comp.PostSpawnSetup(false); }
public override void MapComponentTick() { float currentSpeed = UnityEngine.Mathf.Clamp(map.windManager.WindSpeed, LowWind, HighWind); UpdateWindDirection(); //The tick trigger rate varies depending on wind speed to avoid particle gaps if (++ticker > 35f / (currentSpeed + 0.5f)) { if (Find.CurrentMap != map) { return; } //Catch length for optimization int numberOfFleckers = compCache.Count; //Recycled rands float angleOffset = fastRandom.Next(-5, 5); float rotationRate = fastRandom.Next(-30, 30); if (++tickerRoofCheck > 9) //Every 350 ticks { compCache.ForEach(x => x.CheckIfRoofed()); tickerRoofCheck = 0; } for (int i = 0; i < numberOfFleckers; ++i) { CompFlecker comp = compCache[i]; CompProperties_Smoker props = comp.Props; if ( //Fuelable but has no fuel or flickable but turned off (!props.alwaysSmoke && (comp.fuelComp != null && !comp.fuelComp.HasFuel || comp.flickComp != null && !comp.flickComp.SwitchIsOn)) || //Bills only but not in use and no idle-smoke (props.billsOnly && !comp.InUse && props.idleAlt == null) || //Not spawnable motes (!comp.cachedParticleOffset.ShouldSpawnMotesAt(map)) ) { continue; } //Get the base fleckDef and angle FleckDef fleckDef = props.fleckDef; float angle = windDirection + angleOffset; //Indoor if (comp.isRoofed) { currentSpeed = IndoorSpeed; angle = IndoorAngle + angleOffset; //Indoor smoke if (props.indoorAlt != null) { fleckDef = props.indoorAlt; } } //Idle smoke if (props.idleAlt != null && props.billsOnly && !comp.InUse) { fleckDef = props.idleAlt; } //Speed instance float speed = currentSpeed; //Check for special drivers float size = Rand.Range(comp.cachedParticleSizeMin, comp.cachedParticleSizeMax); if (props.driver == CompProperties_Smoker.Driver.Fire && comp.trueParent is Fire) { float fireSizeModifier = System.Math.Max(0.5f, ((Fire)comp.trueParent).fireSize / 1.25f); size *= fireSizeModifier; speed *= fireSizeModifier; } //Push results to comp comp.ThrowFleck(angle, rotationRate, speed, fleckDef, size); } ticker = 0; } }