Пример #1
0
        public override void MapComponentTick()
        {
            base.MapComponentTick();

            int tick     = Find.TickManager.TicksGame;
            var orphaned = new List <CompBreakdownable>();

            foreach (KeyValuePair <CompBreakdownable, float> _dur in _durabilities)
            {
                float             durability = _dur.Value;
                CompBreakdownable comp       = _dur.Key;
                if (comp?.parent?.Spawned ?? false)
                {
                    if (durability < .5 && (tick + comp.GetHashCode()) % _moteIntervalRequiresRepair == 0)
                    {
                        MoteMaker.ThrowSmoke(comp.parent.DrawPos, map, (1f - durability) * 1 / 2f);
                    }

                    if (durability < .25 && (tick + comp.GetHashCode()) % _moteIntervalRequiresCriticalRepair == 0)
                    {
                        MoteMaker.ThrowMicroSparks(comp.parent.DrawPos, map);
                    }
                }

                // can't simply use !Spawned, since that would allow resetting durability by moving furniture.
                if (comp?.parent?.DestroyedOrNull() ?? true)
                {
                    // mark for removal
                    orphaned.Add(comp);
                }
            }

            // remove
            foreach (CompBreakdownable comp in orphaned)
            {
                _durabilities.Remove(comp);
            }
        }