From 2bbaaafd676c838fd75fc51347d7336d2393d2d2 Mon Sep 17 00:00:00 2001 From: Remuchi <72476615+Remuchi@users.noreply.github.com> Date: Wed, 28 May 2025 19:38:18 +0700 Subject: [PATCH] [Fix] Fixed laser's regulator lamp's visualizer (#530) * Reapply "[Fix] Regulator Lamp Visuals" (#523) This reverts commit 53370221581505b7297f51be17f9d132e55aae98. * Reapply "[Fix] Regular Lamp Layers" (#522)" This reverts commit 2ebf5e18 * fix: fixed lamp layers * style: styled overheat systems * fix: fixed advanced regulator lamp layers --- .../Ranged/Systems/GunSystem.AmmoCounter.cs | 78 +++--- .../Ranged/Systems/GunSystem.Battery.cs | 2 +- .../_White/Guns/GunOverheatSystem.cs | 47 ++-- .../_White/Guns/SharedGunOverheatSystem.cs | 252 +++++++++--------- .../Objects/Weapons/Guns/regulator_lamp.yml | 30 +-- 5 files changed, 207 insertions(+), 202 deletions(-) diff --git a/Content.Client/Weapons/Ranged/Systems/GunSystem.AmmoCounter.cs b/Content.Client/Weapons/Ranged/Systems/GunSystem.AmmoCounter.cs index d5d19e3aa8..b59c4d4820 100644 --- a/Content.Client/Weapons/Ranged/Systems/GunSystem.AmmoCounter.cs +++ b/Content.Client/Weapons/Ranged/Systems/GunSystem.AmmoCounter.cs @@ -102,7 +102,7 @@ public sealed partial class GunSystem MinHeight = 15; HorizontalExpand = true; VerticalAlignment = VAlignment.Center; - AddChild(_bulletRender = new BulletRender + AddChild(_bulletRender = new() { HorizontalAlignment = HAlignment.Right, VerticalAlignment = VAlignment.Bottom @@ -135,12 +135,12 @@ public sealed partial class GunSystem Orientation = BoxContainer.LayoutOrientation.Horizontal, Children = { - (_bullets = new BatteryBulletRenderer + (_bullets = new() { - Margin = new Thickness(0, 0, 5, 0), + Margin = new(0, 0, 5, 0), HorizontalExpand = true }), - (_ammoCount = new Label + (_ammoCount = new() { StyleClasses = { StyleNano.StyleClassItemStatus }, HorizontalAlignment = HAlignment.Right, @@ -183,15 +183,15 @@ public sealed partial class GunSystem new Control { HorizontalExpand = true, - Margin = new Thickness(0, 0, 5, 0), + Margin = new(0, 0, 5, 0), Children = { - (_bulletRender = new BulletRender + (_bulletRender = new() { HorizontalAlignment = HAlignment.Right, VerticalAlignment = VAlignment.Bottom }), - (_noMagazineLabel = new Label + (_noMagazineLabel = new() { Text = "No Magazine!", StyleClasses = {StyleNano.StyleClassItemStatus} @@ -202,15 +202,15 @@ public sealed partial class GunSystem { Orientation = BoxContainer.LayoutOrientation.Vertical, VerticalAlignment = VAlignment.Bottom, - Margin = new Thickness(0, 0, 0, 2), + Margin = new(0, 0, 0, 2), Children = { - (_ammoCount = new Label + (_ammoCount = new() { StyleClasses = {StyleNano.StyleClassItemStatus}, HorizontalAlignment = HAlignment.Right, }), - (_chamberedBullet = new TextureRect + (_chamberedBullet = new() { Texture = StaticIoC.ResC.GetTexture("/Textures/Interface/ItemStatus/Bullets/chambered.png"), HorizontalAlignment = HAlignment.Left, @@ -261,13 +261,13 @@ public sealed partial class GunSystem MinHeight = 15; HorizontalExpand = true; VerticalAlignment = Control.VAlignment.Center; - AddChild((_bulletsList = new BoxContainer + AddChild(_bulletsList = new() { Orientation = BoxContainer.LayoutOrientation.Horizontal, HorizontalExpand = true, VerticalAlignment = VAlignment.Center, SeparationOverride = 0 - })); + }); } public void Update(int currentIndex, bool?[] bullets) @@ -321,7 +321,7 @@ public sealed partial class GunSystem box.AddChild(new TextureRect { Texture = texture, - TextureScale = new Vector2(scale, scale), + TextureScale = new(scale, scale), ModulateSelfOverride = Color.LimeGreen, }); } @@ -369,23 +369,22 @@ public sealed partial class GunSystem private readonly BatteryAmmoProviderComponent _ammoProvider; private readonly GunOverheatComponent? _regulator; private readonly GunOverheatSystem _regSys; - private readonly IEntityManager _entMan; - private int _ammoCount = 0; + private int _ammoCount; private bool _heatLimitEnabled = true; - private float _heatLimit = 0; - private float _heat = 0; // caching temperature and ammo counts so that the labels don't end up having their measures invalidated every frame + private float _heatLimit; + private float _heat; // caching temperature and ammo counts so that the labels don't end up having their measures invalidated every frame // not sure if this makes any difference performance-wise, but it just seems like a good idea - public EnergyGunBatteryStatusControl(BatteryAmmoProviderComponent comp) + public EnergyGunBatteryStatusControl(EntityUid uid, BatteryAmmoProviderComponent comp) { - _entMan = IoCManager.Resolve(); - _regSys = _entMan.System(); - _gun = comp.Owner; + var entMan = IoCManager.Resolve(); + _regSys = entMan.System(); + _gun = uid; _ammoProvider = comp; _ammoCount = comp.Shots; MinHeight = 15; HorizontalExpand = true; - VerticalAlignment = Control.VAlignment.Center; + VerticalAlignment = VAlignment.Center; AddChild(new BoxContainer // outer box { Orientation = BoxContainer.LayoutOrientation.Vertical, @@ -396,14 +395,14 @@ public sealed partial class GunSystem Orientation = BoxContainer.LayoutOrientation.Horizontal, Children = { - (_lampLabel = new Label + (_lampLabel = new() { StyleClasses = { StyleNano.StyleClassItemStatus }, HorizontalAlignment = HAlignment.Left, VerticalAlignment = VAlignment.Bottom, - Text = $" ●" + Text = " \u25cf" }), - (_heatLabel = new Label + (_heatLabel = new() { StyleClasses = { StyleNano.StyleClassItemStatus }, HorizontalAlignment = HAlignment.Right, @@ -418,12 +417,12 @@ public sealed partial class GunSystem Orientation = BoxContainer.LayoutOrientation.Horizontal, Children = { - (_ammoBar = new BarControl + (_ammoBar = new() { Rows = 4, MaxWidth = 75 }), - (_ammoLabel = new Label + (_ammoLabel = new() { StyleClasses = { StyleNano.StyleClassItemStatus }, HorizontalExpand = true, @@ -438,7 +437,7 @@ public sealed partial class GunSystem // if temp regulator component is missing on the gun, hide the temperature gauge and lamp display // since they won't matter anyways - if (!_entMan.TryGetComponent(_gun, out _regulator)) + if (!entMan.TryGetComponent(_gun, out _regulator)) { _heatLabel.Visible = false; _lampLabel.Visible = false; @@ -450,22 +449,21 @@ public sealed partial class GunSystem // still using kelvin because having temperature go from 0 to +inf is much nicer than from -273.15 to +inf private void UpdateTemp(float K) { - float celcius = K - 273.15f; + var celcius = K - 273.15f; // we assume _regulator is not null since we'll check for it before calling this method - float maxTemp = _regulator!.MaxDisplayTemperatureCelcius; - string currentTemp = celcius > maxTemp ? $"{maxTemp:0}+°C" : $"{celcius:0} °C"; - if (_regulator.SafetyEnabled) - _heatLabel.Text = $"{currentTemp}/{_regulator.TemperatureLimit - 273.15f:0} °C "; // MathF.Min to conserve a single digit for space in an otherwise overly cramped piece of UI. - else - _heatLabel.Text = currentTemp; + var maxTemp = _regulator!.MaxDisplayTemperatureCelcius; + var currentTemp = celcius > maxTemp ? $"{maxTemp:0}+°C" : $"{celcius:0} °C"; + _heatLabel.Text = _regulator.SafetyEnabled + ? $"{currentTemp}/{_regulator.TemperatureLimit - 273.15f:0} °C " + : currentTemp; float hue = 0; // full red const float hueoffset = 0.07f; // raises the 0K color from dark blue to a brighter tone if (K < _regulator.TemperatureLimit) - hue = 0.66f - ((K) / (_regulator.TemperatureLimit) * 0.55f * (1f - hueoffset) + hueoffset); + hue = 0.66f - (K / _regulator.TemperatureLimit * 0.55f * (1f - hueoffset) + hueoffset); - var tempColor = Color.FromHsv(new Robust.Shared.Maths.Vector4(hue, 1, 1, 1)); + var tempColor = Color.FromHsv(new(hue, 1, 1, 1)); _heatLabel.FontColorOverride = tempColor; _lampLabel.FontColorOverride = tempColor; } @@ -486,10 +484,8 @@ public sealed partial class GunSystem if (_regulator is null) return; - if (_regSys.GetLamp(_gun, out var lampComp, _regulator)) - { - _lampLabel.Text = lampComp is null || !lampComp.Intact ? " ◌" : " ●"; - } + if (_regSys.GetLamp((_gun,_regulator), out var lamp)) + _lampLabel.Text = !lamp.Value.Comp.Intact ? " ◌" : " ●"; if (_heat != _regulator.CurrentTemperature || _heatLimit != _regulator.TemperatureLimit || _heatLimitEnabled != _regulator.SafetyEnabled) { diff --git a/Content.Client/Weapons/Ranged/Systems/GunSystem.Battery.cs b/Content.Client/Weapons/Ranged/Systems/GunSystem.Battery.cs index eff6a15d86..eb1663fdd8 100644 --- a/Content.Client/Weapons/Ranged/Systems/GunSystem.Battery.cs +++ b/Content.Client/Weapons/Ranged/Systems/GunSystem.Battery.cs @@ -27,6 +27,6 @@ public sealed partial class GunSystem private void OnControl(EntityUid uid, BatteryAmmoProviderComponent component, AmmoCounterControlEvent args) { - args.Control = new EnergyGunBatteryStatusControl(component); // WWDP EDIT + args.Control = new EnergyGunBatteryStatusControl(uid, component); // WWDP EDIT } } diff --git a/Content.Server/_White/Guns/GunOverheatSystem.cs b/Content.Server/_White/Guns/GunOverheatSystem.cs index d03e079d93..f5c7e5d4fa 100644 --- a/Content.Server/_White/Guns/GunOverheatSystem.cs +++ b/Content.Server/_White/Guns/GunOverheatSystem.cs @@ -25,37 +25,36 @@ public sealed class GunOverheatSystem : SharedGunOverheatSystem private void OnLampInit(EntityUid uid, RegulatorLampComponent comp, ComponentInit args) { - if (comp.SafeTemperature > comp.UnsafeTemperature) { - Log.Warning($"Entity {ToPrettyString(uid)} has SafeTemperature bigger than UnsafeTemperature. (s={comp.SafeTemperature}, u={comp.UnsafeTemperature}) Resolving by swapping them around."); + Log.Warning( + $"Entity {ToPrettyString(uid)} has SafeTemperature bigger than UnsafeTemperature. (s={comp.SafeTemperature}, u={comp.UnsafeTemperature}) Resolving by swapping them around."); (comp.SafeTemperature, comp.UnsafeTemperature) = (comp.UnsafeTemperature, comp.SafeTemperature); Dirty(uid, comp); } - if (comp.SafeTemperature == comp.UnsafeTemperature) - { - Log.Error($"Entity {ToPrettyString(uid)} has equal SafeTemperature and UnsafeTemperature. (s={comp.SafeTemperature}, u={comp.UnsafeTemperature}) Resolving by increasing UnsafeTemperature by 0.01f."); - comp.UnsafeTemperature += 0.01f; - Dirty(uid, comp); - } - } - - protected override void OnGunShot(EntityUid uid, GunOverheatComponent comp, ref GunShotEvent args) - { - CheckForBurnout(uid, comp, args.User); - _temp.ForceChangeTemperature(uid, comp.CurrentTemperature + comp.HeatCost); - } - - private void CheckForBurnout(EntityUid uid, GunOverheatComponent comp, EntityUid shooter) - { - if (!GetLamp(uid, out var lampComp, comp) || lampComp is null) + if (comp.SafeTemperature != comp.UnsafeTemperature) return; - float breakChance = GetLampBreakChance(comp.CurrentTemperature, lampComp, comp.LampBreakChanceMultiplier); - if (_rng.Prob(breakChance)) - { - BurnoutLamp(lampComp, shooter); - } + Log.Error( + $"Entity {ToPrettyString(uid)} has equal SafeTemperature and UnsafeTemperature. (s={comp.SafeTemperature}, u={comp.UnsafeTemperature}) Resolving by increasing UnsafeTemperature by 0.01f."); + comp.UnsafeTemperature += 0.01f; + Dirty(uid, comp); + } + + protected override void OnGunShot(Entity gun, ref GunShotEvent args) + { + CheckForBurnout(gun, args.User); + _temp.ForceChangeTemperature(gun, gun.Comp.CurrentTemperature + gun.Comp.HeatCost); + } + + private void CheckForBurnout(Entity gun, EntityUid shooter) + { + if (!GetLamp(gun, out var lamp)) + return; + + var breakChance = GetLampBreakChance(gun.Comp.CurrentTemperature, lamp, gun.Comp.LampBreakChanceMultiplier); + if (Rng.Prob(breakChance)) + BurnoutLamp(lamp.Value, shooter); } } diff --git a/Content.Shared/_White/Guns/SharedGunOverheatSystem.cs b/Content.Shared/_White/Guns/SharedGunOverheatSystem.cs index e89b36689d..2968702617 100644 --- a/Content.Shared/_White/Guns/SharedGunOverheatSystem.cs +++ b/Content.Shared/_White/Guns/SharedGunOverheatSystem.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using Content.Shared.Containers.ItemSlots; using Content.Shared.Destructible; using Content.Shared.Examine; @@ -17,177 +18,186 @@ namespace Content.Shared._White.Guns; /// public abstract class SharedGunOverheatSystem : EntitySystem { - [Dependency] protected readonly ItemSlotsSystem _slots = default!; - [Dependency] protected readonly IRobustRandom _rng = default!; - [Dependency] protected readonly SharedAudioSystem _audio = default!; - [Dependency] protected readonly SharedAppearanceSystem _appearance = default!; - [Dependency] protected readonly IGameTiming _timing = default!; + [Dependency] protected readonly ItemSlotsSystem Slots = default!; + [Dependency] protected readonly IRobustRandom Rng = default!; + [Dependency] protected readonly SharedAudioSystem Audio = default!; + [Dependency] protected readonly SharedAppearanceSystem Appearance = default!; + [Dependency] protected readonly IGameTiming Timing = default!; public override void Initialize() { SubscribeLocalEvent(OnAttemptShoot); SubscribeLocalEvent(OnGunShot); - SubscribeLocalEvent(OnBreak); - SubscribeLocalEvent(OnLampExamined); SubscribeLocalEvent(OnGunExamined); SubscribeLocalEvent>(OnAltVerbs); + + SubscribeLocalEvent(OnBreak); + SubscribeLocalEvent(OnLampExamined); } - private void OnLampExamined(EntityUid uid, RegulatorLampComponent comp, ExaminedEvent args) - { - args.PushMarkup(Loc.GetString("gun-regulator-lamp-examine-intact", ("intact", comp.Intact))); - - if (!args.IsInDetailsRange) - return; - - args.PushMarkup(Loc.GetString("gun-regulator-lamp-examine-temperature-range", ("safetemp", MathF.Round(comp.SafeTemperature - 273.15f)), ("unsafetemp", MathF.Round(comp.UnsafeTemperature - 273.15f)))); - } - - private void OnGunExamined(EntityUid uid, GunOverheatComponent comp, ExaminedEvent args) - { - if (!args.IsInDetailsRange) - return; - - args.PushMarkup(Loc.GetString($"gun-regulator-examine-safety{(comp.CanChangeSafety ? "-toggleable" : "")}", ("enabled", comp.SafetyEnabled), ("limit", MathF.Round(comp.TemperatureLimit - 273.15f)))); - if (comp.RequiresLamp) - { - int lampStatus = 0; // missing - if (GetLamp(uid, out var lamp, comp) && lamp is not null) - lampStatus = lamp.Intact ? 2 : 1; // present : broken - args.PushMarkup(Loc.GetString($"gun-regulator-examine-lamp", ("lampstatus", lampStatus))); - } - } - - private void OnBreak(EntityUid uid, RegulatorLampComponent comp, BreakageEventArgs args) - { - /*_appearance.SetData(uid, RegulatorLampVisuals.Glass, RegulatorLampState.Broken);*/ - comp.Intact = false; - Dirty(uid, comp); - } - - private void OnAttemptShoot(EntityUid uid, GunOverheatComponent comp, ref AttemptShootEvent args) + private void OnAttemptShoot(Entity gun, ref AttemptShootEvent args) { if (args.Cancelled) return; - if (comp.CurrentTemperature >= comp.TemperatureLimit && comp.SafetyEnabled) + if (gun.Comp.CurrentTemperature >= gun.Comp.TemperatureLimit && gun.Comp.SafetyEnabled) { args.Cancelled = true; args.Message = Loc.GetString("gun-regulator-temperature-limit-exceeded-popup"); return; } - if (!comp.RequiresLamp) + if (!gun.Comp.RequiresLamp) return; - if (GetLamp(uid, out var lampComp, comp) && lampComp is not null) + if (!GetLamp(gun, out var lamp)) { - if (lampComp.Intact) - return; - args.Cancelled = true; - args.Message = Loc.GetString($"gun-regulator-lamp-broken-popup"); + args.Message = Loc.GetString("gun-regulator-lamp-missing-popup"); return; } - args.Cancelled = true; - args.Message = Loc.GetString($"gun-regulator-lamp-missing-popup"); - return; + if (!lamp.Value.Comp.Intact) + { + args.Cancelled = true; + args.Message = Loc.GetString("gun-regulator-lamp-broken-popup"); + } } - protected virtual void OnGunShot(EntityUid uid, GunOverheatComponent comp, ref GunShotEvent args) + protected virtual void OnGunShot(Entity gun, ref GunShotEvent args) { - if (_timing.IsFirstTimePredicted) - comp.CurrentTemperature += comp.HeatCost; + if (Timing.IsFirstTimePredicted) + gun.Comp.CurrentTemperature += gun.Comp.HeatCost; + } + + private void OnGunExamined(Entity gun, ref ExaminedEvent args) + { + if (!args.IsInDetailsRange) + return; + + args.PushMarkup( + Loc.GetString( + $"gun-regulator-examine-safety{(gun.Comp.CanChangeSafety ? "-toggleable" : "")}", + ("enabled", gun.Comp.SafetyEnabled), ("limit", MathF.Round(gun.Comp.TemperatureLimit - 273.15f)))); + if (!gun.Comp.RequiresLamp) + return; + + var lampStatus = 0; // missing + if (GetLamp(gun, out var lamp)) + lampStatus = lamp.Value.Comp.Intact ? 2 : 1; // present : broken + args.PushMarkup(Loc.GetString("gun-regulator-examine-lamp", ("lampstatus", lampStatus))); + } + + private void OnAltVerbs(Entity gun, ref GetVerbsEvent args) + { + if (!args.CanInteract || !args.CanComplexInteract || !args.CanAccess || !gun.Comp.CanChangeSafety) + return; + var player = args.User; + + AddVerb(-1, "fireselector-100up-verb", ref args, () => AdjustSafety(gun.Comp, 100, player)); + AddVerb(-2, "fireselector-10up-verb", ref args, () => AdjustSafety(gun.Comp, 10, player)); + AddVerb(-3, "fireselector-toggle-verb", ref args, () => ToggleSafety(gun.Comp, player)); + AddVerb(-4, "fireselector-10down-verb", ref args, () => AdjustSafety(gun.Comp, -10, player)); + AddVerb(-5, "fireselector-100down-verb", ref args, () => AdjustSafety(gun.Comp, -100, player)); + return; + + void AddVerb(int priority, string text, ref GetVerbsEvent args, Action act) => + args.Verbs.Add( + new() + { + Category = VerbCategory.Safety, + Priority = priority, + CloseMenu = false, + DoContactInteraction = true, + Text = Loc.GetString(text), + Act = act + }); + + void AdjustSafety(GunOverheatComponent heat, float T, EntityUid user) + { + if (!Timing.IsFirstTimePredicted) + return; + Audio.PlayPredicted(T >= 0 ? heat.clickUpSound : heat.clickDownSound, gun, user); + AdjustTemperatureLimit(heat, T); + } + + void ToggleSafety(GunOverheatComponent heat, EntityUid user) + { + if (!Timing.IsFirstTimePredicted) + return; + Audio.PlayPredicted(heat.clickSound, gun, user); + heat.SafetyEnabled = !heat.SafetyEnabled; + } + } + + private void OnBreak(Entity lamp, ref BreakageEventArgs args) + { + Appearance.SetData(lamp, RegulatorLampGlass.Intact, false); + lamp.Comp.Intact = false; + Dirty(lamp); + } + + private void OnLampExamined(Entity lamp, ref ExaminedEvent args) + { + if (!args.IsInDetailsRange) + return; + + args.PushMarkup(Loc.GetString("gun-regulator-lamp-examine-intact", ("intact", lamp.Comp.Intact))); + args.PushMarkup( + Loc.GetString( + "gun-regulator-lamp-examine-temperature-range", + ("safetemp", MathF.Round(lamp.Comp.SafeTemperature - 273.15f)), + ("unsafetemp", MathF.Round(lamp.Comp.UnsafeTemperature - 273.15f)))); } public void AdjustTemperatureLimit(GunOverheatComponent comp, float tempChange) { - comp.TemperatureLimit = MathHelper.Clamp(comp.TemperatureLimit + tempChange, -250f + 273.15f, comp.MaxSafetyTemperature); // from -250C to MaxSafetyTemperature - } - - private void OnAltVerbs(EntityUid uid, GunOverheatComponent comp, GetVerbsEvent args) - { - if (!args.CanInteract || !args.CanComplexInteract || !args.CanAccess || !comp.CanChangeSafety) - return; - - AddVerb(-1, "fireselector-100up-verb", () => _adjustSafety(comp, 100)); - AddVerb(-2, "fireselector-10up-verb", () => _adjustSafety(comp, 10)); - AddVerb(-3, "fireselector-toggle-verb", () => _toggleSafety(comp)); - AddVerb(-4, "fireselector-10down-verb", () => _adjustSafety(comp, -10)); - AddVerb(-5, "fireselector-100down-verb", () => _adjustSafety(comp, -100)); - - void AddVerb(int priority, string text, Action act) - { - args.Verbs.Add(new AlternativeVerb - { - Category = VerbCategory.Safety, - Priority = priority, - CloseMenu = false, - DoContactInteraction = true, - Text = Loc.GetString(text), - Act = act, - }); - } - - void _adjustSafety(GunOverheatComponent comp, float T) - { - if (!_timing.IsFirstTimePredicted) - return; - _audio.PlayPredicted(T >= 0 ? comp.clickUpSound : comp.clickDownSound, uid, args.User); - AdjustTemperatureLimit(comp, T); - } - - void _toggleSafety(GunOverheatComponent comp) - { - if (!_timing.IsFirstTimePredicted) - return; - _audio.PlayPredicted(comp.clickSound, uid, args.User); - comp.SafetyEnabled = !comp.SafetyEnabled; - } + comp.TemperatureLimit = MathHelper.Clamp( + comp.TemperatureLimit + tempChange, -250f + 273.15f, + comp.MaxSafetyTemperature); // from -250C to MaxSafetyTemperature } /// /// Returns false if called on something without GunTemperatureRegulatorComponent. /// Otherwise returns true. /// - public bool GetLamp(EntityUid gunUid, out RegulatorLampComponent? lampComp, GunOverheatComponent? comp = null) + public bool GetLamp(Entity gun, [NotNullWhen(true)] out Entity? lamp) { - lampComp = null; - if (!Resolve(gunUid, ref comp)) + lamp = null; + if (!TryComp(gun, out var slotComp) || + !Slots.TryGetSlot(gun, gun.Comp.LampSlot, out var slot, slotComp) || + !TryComp(slot.Item, out RegulatorLampComponent? comp)) return false; - if (TryComp(gunUid, out var slotComp) && _slots.TryGetSlot(gunUid, comp.LampSlot, out var slot, slotComp)) - TryComp(slot.Item, out lampComp); + lamp = (slot.Item.Value, comp); return true; } - protected void BurnoutLamp(RegulatorLampComponent comp, EntityUid? shooter = null) + protected void BurnoutLamp(Entity lamp, EntityUid? shooter = null) { - var lampUid = comp.Owner; - _audio.PlayEntity(comp.BreakSound, Filter.Pvs(lampUid), lampUid, true); - /*_appearance.SetData(lampUid, RegulatorLampVisuals.Filament, RegulatorLampState.Broken);*/ - comp.Intact = false; - Dirty(lampUid, comp); + Audio.PlayEntity(lamp.Comp.BreakSound, Filter.Pvs(lamp), lamp, true); + Appearance.SetData(lamp, RegulatorLampFilament.Intact, false); + lamp.Comp.Intact = false; + Dirty(lamp); } - public float GetLampBreakChance(float temp, RegulatorLampComponent comp, float multiplier = 1) => MathHelper.Clamp01((temp - comp.SafeTemperature) / (comp.UnsafeTemperature - comp.SafeTemperature) * multiplier); -} - - -// I do not know why, but it refuses to work on the server. TODO: return it -/* -[Serializable, NetSerializable] -public enum RegulatorLampVisuals -{ - Glass, - Filament + public float GetLampBreakChance(float temp, RegulatorLampComponent comp, float multiplier = 1) + { + return MathHelper.Clamp01( + (temp - comp.SafeTemperature) / (comp.UnsafeTemperature - comp.SafeTemperature) * multiplier); + } } [Serializable, NetSerializable] -public enum RegulatorLampState +public enum RegulatorLampGlass : byte { - Intact, - Broken + Layer, + Intact +} + +[Serializable, NetSerializable] +public enum RegulatorLampFilament : byte +{ + Layer, + Intact } -*/ diff --git a/Resources/Prototypes/_White/Entities/Objects/Weapons/Guns/regulator_lamp.yml b/Resources/Prototypes/_White/Entities/Objects/Weapons/Guns/regulator_lamp.yml index 767f92e676..f5a86d36cc 100644 --- a/Resources/Prototypes/_White/Entities/Objects/Weapons/Guns/regulator_lamp.yml +++ b/Resources/Prototypes/_White/Entities/Objects/Weapons/Guns/regulator_lamp.yml @@ -10,9 +10,9 @@ layers: - state: base - state: filament - map: [ "Filament" ] + map: [ "enum.RegulatorLampFilament.Layer" ] - state: glass - map: [ "Glass" ] + map: [ "enum.RegulatorLampGlass.Layer" ] - type: RegulatorLamp safeTemp: 240 unsafeTemp: 650 @@ -61,17 +61,17 @@ max: 1 - !type:DoActsBehavior acts: [ "Destruction" ] - # - type: Appearance - # - type: GenericVisualizer - # visuals: - # enum.RegulatorLampVisuals.Glass: - # Glass: - # Intact: { state: glass } - # Broken: { state: glassbroken } - # enum.RegulatorLampVisuals.Filament: - # Filament: - # Intact: { state: filament } - # Broken: { state: filamentburned } + - type: Appearance + - type: GenericVisualizer + visuals: + enum.RegulatorLampGlass.Intact: + enum.RegulatorLampGlass.Layer: + True: { state: glass } + False: { state: glassbroken } + enum.RegulatorLampFilament.Intact: + enum.RegulatorLampFilament.Layer: + True: { state: filament } + False: { state: filamentburned } - type: entity parent: BaseRegulatorLamp @@ -90,9 +90,9 @@ layers: - state: adv - state: filament - map: [ "Filament" ] + map: [ "enum.RegulatorLampFilament.Layer" ] - state: glass - map: [ "Glass" ] + map: [ "enum.RegulatorLampGlass.Layer" ] - type: RegulatorLamp safeTemp: 480 unsafeTemp: 840