Beispiel #1
0
        private void OnGhostBoo(EntityUid uid, PoweredLightComponent light, GhostBooEvent args)
        {
            if (light.IgnoreGhostsBoo)
            {
                return;
            }

            // check cooldown first to prevent abuse
            var time = _gameTiming.CurTime;

            if (light.LastGhostBlink != null)
            {
                if (time <= light.LastGhostBlink + light.GhostBlinkingCooldown)
                {
                    return;
                }
            }

            light.LastGhostBlink = time;

            ToggleBlinkingLight(light, true);
            light.Owner.SpawnTimer(light.GhostBlinkingTime, () =>
            {
                ToggleBlinkingLight(light, false);
            });

            args.Handled = true;
        }
Beispiel #2
0
        private void OnInteractUsing(EntityUid uid, PoweredLightComponent component, InteractUsingEvent args)
        {
            if (args.Handled)
            {
                return;
            }

            args.Handled = InsertBulb(uid, args.Used, component);
        }
Beispiel #3
0
 /// <summary>
 ///     Destroy the light bulb if the light took any damage.
 /// </summary>
 public void HandleLightDamaged(EntityUid uid, PoweredLightComponent component, DamageChangedEvent args)
 {
     // Was it being repaired, or did it take damage?
     if (args.DamageIncreased)
     {
         // Eventually, this logic should all be done by this (or some other) system, not a component.
         TryDestroyBulb(uid, component);
     }
 }
Beispiel #4
0
 private void OnSignalReceived(EntityUid uid, PoweredLightComponent component, SignalReceivedEvent args)
 {
     switch (args.Port)
     {
     case "state":
         component.ToggleLight();
         break;
     }
 }
Beispiel #5
0
 private void OnMapInit(EntityUid uid, PoweredLightComponent light, MapInitEvent args)
 {
     if (light.HasLampOnSpawn != null)
     {
         var entity = EntityManager.SpawnEntity(light.HasLampOnSpawn, EntityManager.GetComponent <TransformComponent>(light.Owner).Coordinates);
         light.LightBulbContainer.Insert(entity);
     }
     // need this to update visualizers
     UpdateLight(uid, light);
 }
Beispiel #6
0
        /// <summary>
        /// Turns the light on or of when receiving a <see cref="DeviceNetworkConstants.CmdSetState"/> command.
        /// The light is turned on or of according to the <see cref="DeviceNetworkConstants.StateEnabled"/> value
        /// </summary>
        private void OnPacketReceived(EntityUid uid, PoweredLightComponent component, DeviceNetworkPacketEvent args)
        {
            if (!args.Data.TryGetValue(DeviceNetworkConstants.Command, out string?command) || command != DeviceNetworkConstants.CmdSetState)
            {
                return;
            }
            if (!args.Data.TryGetValue(DeviceNetworkConstants.StateEnabled, out bool enabled))
            {
                return;
            }

            SetState(uid, enabled, component);
        }
Beispiel #7
0
        private void OnInteractHand(EntityUid uid, PoweredLightComponent light, InteractHandEvent args)
        {
            if (args.Handled)
            {
                return;
            }

            // check if light has bulb to eject
            var bulbUid = GetBulb(uid, light);

            if (bulbUid == null)
            {
                return;
            }

            // check if it's possible to apply burn damage to user
            var userUid = args.User;

            if (EntityManager.TryGetComponent(userUid, out HeatResistanceComponent? heatResist) &&
                EntityManager.TryGetComponent(bulbUid.Value, out LightBulbComponent? lightBulb))
            {
                // get users heat resistance
                var res = heatResist.GetHeatResistance();

                // check heat resistance against user
                var burnedHand = light.CurrentLit && res < lightBulb.BurningTemperature;
                if (burnedHand)
                {
                    // apply damage to users hands and show message with sound
                    var burnMsg = Loc.GetString("powered-light-component-burn-hand");
                    _popupSystem.PopupEntity(burnMsg, uid, Filter.Entities(userUid));

                    var damage = _damageableSystem.TryChangeDamage(userUid, light.Damage);

                    if (damage != null)
                    {
                        _logSystem.Add(LogType.Damaged,
                                       $"{ToPrettyString(args.User):user} burned their hand on {ToPrettyString(args.Target):target} and received {damage.Total:damage} damage");
                    }

                    SoundSystem.Play(Filter.Pvs(uid), light.BurnHandSound.GetSound(), uid);

                    args.Handled = true;
                    return;
                }
            }

            // all checks passed
            // just try to eject bulb
            args.Handled = EjectBulb(uid, userUid, light) != null;
        }
Beispiel #8
0
 private void OnSignalReceived(EntityUid uid, PoweredLightComponent component, SignalReceivedEvent args)
 {
     if (args.Port == component.OffPort)
     {
         SetState(uid, false, component);
     }
     else if (args.Port == component.OnPort)
     {
         SetState(uid, true, component);
     }
     else if (args.Port == component.TogglePort)
     {
         ToggleLight(uid, component);
     }
 }
Beispiel #9
0
        public void ToggleBlinkingLight(PoweredLightComponent light, bool isNowBlinking)
        {
            if (light.IsBlinking == isNowBlinking)
            {
                return;
            }

            light.IsBlinking = isNowBlinking;

            if (!EntityManager.TryGetComponent(light.Owner, out AppearanceComponent? appearance))
            {
                return;
            }
            appearance.SetData(PoweredLightVisuals.Blinking, isNowBlinking);
        }
Beispiel #10
0
        private void OnMapInit(EntityUid uid, PoweredLightComponent light, MapInitEvent args)
        {
            if (light.HasLampOnSpawn)
            {
                var prototype = light.BulbType switch
                {
                    LightBulbType.Bulb => "LightBulb",
                    LightBulbType.Tube => "LightTube",
                    _ => throw new ArgumentOutOfRangeException()
                };

                var entity = EntityManager.SpawnEntity(prototype, EntityManager.GetComponent <TransformComponent>(light.Owner).Coordinates);
                light.LightBulbContainer.Insert(entity);
            }

            // need this to update visualizers
            UpdateLight(uid, light);
        }
Beispiel #11
0
        private void OnInteractHand(EntityUid uid, PoweredLightComponent light, InteractHandEvent args)
        {
            if (args.Handled)
            {
                return;
            }

            if (light.CancelToken != null)
            {
                return;
            }

            // check if light has bulb to eject
            var bulbUid = GetBulb(uid, light);

            if (bulbUid == null)
            {
                return;
            }

            // check if it's possible to apply burn damage to user
            var userUid = args.User;

            if (EntityManager.TryGetComponent(userUid, out HeatResistanceComponent? heatResist) &&
                EntityManager.TryGetComponent(bulbUid.Value, out LightBulbComponent? lightBulb))
            {
                // get users heat resistance
                var res = heatResist.GetHeatResistance();

                // check heat resistance against user
                var burnedHand = light.CurrentLit && res < lightBulb.BurningTemperature;
                if (burnedHand)
                {
                    // apply damage to users hands and show message with sound
                    var burnMsg = Loc.GetString("powered-light-component-burn-hand");
                    _popupSystem.PopupEntity(burnMsg, uid, Filter.Entities(userUid));

                    var damage = _damageableSystem.TryChangeDamage(userUid, light.Damage);

                    if (damage != null)
                    {
                        _adminLogger.Add(LogType.Damaged,
                                         $"{ToPrettyString(args.User):user} burned their hand on {ToPrettyString(args.Target):target} and received {damage.Total:damage} damage");
                    }

                    SoundSystem.Play(light.BurnHandSound.GetSound(), Filter.Pvs(uid), uid);

                    args.Handled = true;
                    return;
                }
            }


            //removing a broken/burned bulb, so allow instant removal
            if (TryComp <LightBulbComponent>(bulbUid.Value, out var bulb) && bulb.State != LightBulbState.Normal)
            {
                args.Handled = EjectBulb(uid, userUid, light) != null;
                return;
            }

            // removing a working bulb, so require a delay
            light.CancelToken = new CancellationTokenSource();
            _doAfterSystem.DoAfter(new DoAfterEventArgs((EntityUid)userUid, light.EjectBulbDelay, light.CancelToken.Token, uid)
            {
                BreakOnUserMove     = true,
                BreakOnDamage       = true,
                BreakOnStun         = true,
                TargetFinishedEvent = new EjectBulbCompleteEvent()
                {
                    Component = light,
                    User      = userUid,
                    Target    = uid,
                },
                TargetCancelledEvent = new EjectBulbCancelledEvent()
                {
                    Component = light,
                }
            });

            args.Handled = true;
        }
Beispiel #12
0
 private void OnInit(EntityUid uid, PoweredLightComponent light, ComponentInit args)
 {
     light.LightBulbContainer = _containerSystem.EnsureContainer <ContainerSlot>(uid, LightBulbContainer);
     _signalSystem.EnsureReceiverPorts(uid, light.OnPort, light.OffPort, light.TogglePort);
 }
Beispiel #13
0
 private static void OnEjectBulbCancelled(EntityUid uid, PoweredLightComponent component, EjectBulbCancelledEvent args)
 {
     args.Component.CancelToken = null;
 }
Beispiel #14
0
 private void OnEjectBulbComplete(EntityUid uid, PoweredLightComponent component, EjectBulbCompleteEvent args)
 {
     args.Component.CancelToken = null;
     EjectBulb(args.Target, args.User, args.Component);
 }
Beispiel #15
0
 private void OnPowerChanged(EntityUid uid, PoweredLightComponent component, PowerChangedEvent args)
 {
     UpdateLight(uid, component);
 }
Beispiel #16
0
 private void OnInit(EntityUid uid, PoweredLightComponent light, ComponentInit args)
 {
     light.LightBulbContainer = light.Owner.EnsureContainer <ContainerSlot>("light_bulb");
 }