private void OnInit(EntityUid uid, SleepingComponent component, ComponentInit args)
        {
            var ev = new SleepStateChangedEvent(true);

            RaiseLocalEvent(uid, ev, false);
            _blindingSystem.AdjustBlindSources(uid, true);
        }
        private void OnShutdown(EntityUid uid, SleepingComponent component, ComponentShutdown args)
        {
            var ev = new SleepStateChangedEvent(false);

            RaiseLocalEvent(uid, ev, false);
            _blindingSystem.AdjustBlindSources(uid, false);
        }
示例#3
0
        /// <summary>
        /// when sleeping component is added or removed, we do some stuff with other components.
        /// </summary>
        private void OnSleepStateChanged(EntityUid uid, MobStateComponent component, SleepStateChangedEvent args)
        {
            _prototypeManager.TryIndex <InstantActionPrototype>("Wake", out var wakeAction);
            if (args.FellAsleep)
            {
                EnsureComp <StunnedComponent>(uid);
                EnsureComp <KnockedDownComponent>(uid);

                var emitSound = EnsureComp <SpamEmitSoundComponent>(uid);
                emitSound.Sound          = new SoundCollectionSpecifier("Snores");
                emitSound.PlayChance     = 0.33f;
                emitSound.RollInterval   = 5f;
                emitSound.PopUp          = "sleep-onomatopoeia";
                emitSound.PitchVariation = 0.2f;

                if (wakeAction != null)
                {
                    var wakeInstance = new InstantAction(wakeAction);
                    wakeInstance.Cooldown = (_gameTiming.CurTime, _gameTiming.CurTime + TimeSpan.FromSeconds(15));
                    _actionsSystem.AddAction(uid, wakeInstance, null);
                }
                return;
            }
            if (wakeAction != null)
            {
                _actionsSystem.RemoveAction(uid, wakeAction);
            }

            RemComp <StunnedComponent>(uid);
            RemComp <KnockedDownComponent>(uid);
            RemComp <SpamEmitSoundComponent>(uid);
        }