diff --git a/Content.Server/Administration/Commands/SetOutfitCommand.cs b/Content.Server/Administration/Commands/SetOutfitCommand.cs index 2f979f4340b..12312286518 100644 --- a/Content.Server/Administration/Commands/SetOutfitCommand.cs +++ b/Content.Server/Administration/Commands/SetOutfitCommand.cs @@ -13,6 +13,7 @@ using Robust.Shared.Player; using Robust.Shared.Prototypes; using Content.Server.Silicon.IPC; +using Content.Shared.Radio.Components; namespace Content.Server.Administration.Commands { @@ -127,7 +128,12 @@ public static bool SetOutfit(EntityUid target, string gear, IEntityManager entit handsSystem.TryPickup(target, inhandEntity, checkActionBlocker: false, handsComp: handsComponent); } } - InternalEncryptionKeySpawner.TryInsertEncryptionKey(target, startingGear, entityManager, profile); + + if (entityManager.HasComponent(target)) + { + var encryption = new InternalEncryptionKeySpawner(); + encryption.TryInsertEncryptionKey(target, startingGear, entityManager); + } return true; } } diff --git a/Content.Server/Power/Components/SiliconEmitSoundOnDrainedComponent.cs b/Content.Server/Power/Components/SiliconEmitSoundOnDrainedComponent.cs index 4e5121d6076..5740d7822d0 100644 --- a/Content.Server/Power/Components/SiliconEmitSoundOnDrainedComponent.cs +++ b/Content.Server/Power/Components/SiliconEmitSoundOnDrainedComponent.cs @@ -1,6 +1,4 @@ -using System.ComponentModel.DataAnnotations; using Robust.Shared.Audio; -using Content.Server.Sound.Components; namespace Content.Server.Silicon; diff --git a/Content.Server/Power/Systems/BatteryDrinkerSystem.cs b/Content.Server/Power/Systems/BatteryDrinkerSystem.cs index 9a06d4181c9..e42783c4d8d 100644 --- a/Content.Server/Power/Systems/BatteryDrinkerSystem.cs +++ b/Content.Server/Power/Systems/BatteryDrinkerSystem.cs @@ -1,4 +1,3 @@ -using System.Diagnostics.CodeAnalysis; using System.Linq; using Content.Server.Power.Components; using Content.Shared.Containers.ItemSlots; @@ -12,8 +11,6 @@ using Content.Server.Popups; using Content.Server.PowerCell; using Content.Shared.Popups; -using Content.Shared.Silicon.Components; -using FastAccessors; using Robust.Shared.Audio.Systems; using Robust.Shared.Containers; @@ -21,13 +18,11 @@ namespace Content.Server.Power; public sealed class BatteryDrinkerSystem : EntitySystem { - [Dependency] private readonly ItemSlotsSystem _slots = default!; [Dependency] private readonly SharedDoAfterSystem _doAfter = default!; [Dependency] private readonly SharedAudioSystem _audio = default!; [Dependency] private readonly BatterySystem _battery = default!; [Dependency] private readonly SiliconChargeSystem _silicon = default!; [Dependency] private readonly PopupSystem _popup = default!; - [Dependency] private readonly PowerCellSystem _powerCell = default!; [Dependency] private readonly SharedContainerSystem _container = default!; public override void Initialize() @@ -41,12 +36,10 @@ public override void Initialize() private void AddAltVerb(EntityUid uid, BatteryComponent batteryComponent, GetVerbsEvent args) { - if (!args.CanAccess || !args.CanInteract) - return; - - if (!TryComp(args.User, out var drinkerComp) || - !TestDrinkableBattery(uid, drinkerComp) || - !_silicon.TryGetSiliconBattery(args.User, out var drinkerBattery)) + if (!args.CanAccess || !args.CanInteract + || !TryComp(args.User, out var drinkerComp) + || !TestDrinkableBattery(uid, drinkerComp) + || !_silicon.TryGetSiliconBattery(args.User, out var _)) return; AlternativeVerb verb = new() @@ -80,6 +73,7 @@ private void DrinkBattery(EntityUid target, EntityUid user, BatteryDrinkerCompon { BreakOnDamage = true, BreakOnTargetMove = true, + BreakOnUserMove = true, Broadcast = false, DistanceThreshold = 1.35f, RequireCanInteract = true, @@ -91,39 +85,28 @@ private void DrinkBattery(EntityUid target, EntityUid user, BatteryDrinkerCompon private void OnDoAfter(EntityUid uid, BatteryDrinkerComponent drinkerComp, DoAfterEvent args) { - if (args.Cancelled || args.Target == null) + if (args.Cancelled || args.Target == null + || !TryComp(args.Target.Value, out var sourceBattery) + || !_silicon.TryGetSiliconBattery(uid, out var drinkerBatteryComponent) + || !TryComp(uid, out PowerCellSlotComponent? batterySlot) + || !TryComp(args.Target.Value, out var sourceComp) + || !_container.TryGetContainer(uid, batterySlot.CellSlotId, out var container) + || container.ContainedEntities is null) return; var source = args.Target.Value; - var drinker = uid; - var sourceBattery = Comp(source); - - _silicon.TryGetSiliconBattery(drinker, out var drinkerBatteryComponent); - - if (!TryComp(uid, out PowerCellSlotComponent? batterySlot)) - return; - - var container = _container.GetContainer(uid, batterySlot.CellSlotId); var drinkerBattery = container.ContainedEntities.First(); - - TryComp(source, out var sourceComp); - - DebugTools.AssertNotNull(drinkerBattery); - - if (drinkerBattery == null) - return; - var amountToDrink = drinkerComp.DrinkMultiplier * 1000; amountToDrink = MathF.Min(amountToDrink, sourceBattery.CurrentCharge); amountToDrink = MathF.Min(amountToDrink, drinkerBatteryComponent!.MaxCharge - drinkerBatteryComponent.CurrentCharge); - if (sourceComp != null && sourceComp.MaxAmount > 0) + if (sourceComp.MaxAmount > 0) amountToDrink = MathF.Min(amountToDrink, (float) sourceComp.MaxAmount); if (amountToDrink <= 0) { - _popup.PopupEntity(Loc.GetString("battery-drinker-empty", ("target", source)), drinker, drinker); + _popup.PopupEntity(Loc.GetString("battery-drinker-empty", ("target", source)), uid, uid); return; } @@ -135,10 +118,11 @@ private void OnDoAfter(EntityUid uid, BatteryDrinkerComponent drinkerComp, DoAft _battery.SetCharge(source, 0); } - if (sourceComp != null && sourceComp.DrinkSound != null){ - _popup.PopupEntity(Loc.GetString("ipc-recharge-tip"), drinker, drinker, PopupType.SmallCaution); - _audio.PlayPvs(sourceComp.DrinkSound, source); - Spawn("EffectSparks", Transform(source).Coordinates); - } + if (sourceComp.DrinkSound is null) + return; + + _popup.PopupEntity(Loc.GetString("ipc-recharge-tip"), uid, uid, PopupType.SmallCaution); + _audio.PlayPvs(sourceComp.DrinkSound, source); + Spawn("EffectSparks", Transform(source).Coordinates); } } diff --git a/Content.Server/Power/Systems/BatteryElectrocuteChargeSystem.cs b/Content.Server/Power/Systems/BatteryElectrocuteChargeSystem.cs index 9993c151b1e..707d7c679e8 100644 --- a/Content.Server/Power/Systems/BatteryElectrocuteChargeSystem.cs +++ b/Content.Server/Power/Systems/BatteryElectrocuteChargeSystem.cs @@ -4,7 +4,6 @@ using Content.Server.Power.EntitySystems; using Content.Shared.Electrocution; using Robust.Shared.Random; -using Robust.Shared.Timing; namespace Content.Server.Power.Systems; @@ -26,10 +25,10 @@ private void OnElectrocuted(EntityUid uid, BatteryComponent battery, Electrocute if (args.ShockDamage == null || args.ShockDamage <= 0) return; - var damagePerWatt = ElectrocutionSystem.ElectrifiedDamagePerWatt * 2; - - var damage = args.ShockDamage.Value * args.SiemensCoefficient; - var charge = Math.Min(damage / damagePerWatt, battery.MaxCharge * 0.25f) * _random.NextFloat(0.75f, 1.25f); + var charge = Math.Min(args.ShockDamage.Value * args.SiemensCoefficient + / ElectrocutionSystem.ElectrifiedDamagePerWatt * 2, + battery.MaxCharge * 0.25f) + * _random.NextFloat(0.75f, 1.25f); _battery.SetCharge(uid, battery.CurrentCharge + charge); diff --git a/Content.Server/Power/Systems/SiliconEmitSoundOnDrainedSystem.cs b/Content.Server/Power/Systems/SiliconEmitSoundOnDrainedSystem.cs index 28a46cc7f70..f95a940aaeb 100644 --- a/Content.Server/Power/Systems/SiliconEmitSoundOnDrainedSystem.cs +++ b/Content.Server/Power/Systems/SiliconEmitSoundOnDrainedSystem.cs @@ -2,7 +2,6 @@ using Content.Shared.Sound.Components; using Content.Server.Sound; using Content.Shared.Mobs; -using Content.Shared.Silicon.Systems; namespace Content.Server.Silicon; @@ -35,7 +34,9 @@ private void OnAlive(EntityUid uid, SiliconEmitSoundOnDrainedComponent component public void OnStateChange(EntityUid uid, SiliconEmitSoundOnDrainedComponent component, MobStateChangedEvent args) { - if (args.NewMobState == MobState.Dead) - RemComp(uid); + if (args.NewMobState != MobState.Dead) + return; + + RemComp(uid); } } diff --git a/Content.Server/Silicon/BatteryLocking/BatterySlotRequiresLockSystem.cs b/Content.Server/Silicon/BatteryLocking/BatterySlotRequiresLockSystem.cs index 98e1cb5584c..12e86691281 100644 --- a/Content.Server/Silicon/BatteryLocking/BatterySlotRequiresLockSystem.cs +++ b/Content.Server/Silicon/BatteryLocking/BatterySlotRequiresLockSystem.cs @@ -2,7 +2,7 @@ using Content.Shared.Lock; using Content.Shared.Popups; using Content.Shared.Silicon.Components; -using Content.Shared.IdentityManagement; +using Content.Shared.IdentityManagement; namespace Content.Server.Silicon.BatteryLocking; @@ -10,19 +10,18 @@ public sealed class BatterySlotRequiresLockSystem : EntitySystem { [Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!; - [Dependency] private readonly SharedPopupSystem _popupSystem = default!; + [Dependency] private readonly SharedPopupSystem _popupSystem = default!; - /// public override void Initialize() { base.Initialize(); SubscribeLocalEvent(LockToggled); - SubscribeLocalEvent(LockToggleAttempted); - + SubscribeLocalEvent(LockToggleAttempted); } + private void LockToggled(EntityUid uid, BatterySlotRequiresLockComponent component, LockToggledEvent args) { - if (!TryComp(uid, out var lockComp) + if (!TryComp(uid, out var lockComp) || !TryComp(uid, out var itemslots) || !_itemSlotsSystem.TryGetSlot(uid, component.ItemSlot, out var slot, itemslots)) return; @@ -33,9 +32,9 @@ private void LockToggled(EntityUid uid, BatterySlotRequiresLockComponent compone private void LockToggleAttempted(EntityUid uid, BatterySlotRequiresLockComponent component, LockToggleAttemptEvent args) { if (args.User == uid - || !TryComp(uid, out var siliconComp)) + || !HasComp(uid)) return; - + _popupSystem.PopupEntity(Loc.GetString("batteryslotrequireslock-component-alert-owner", ("user", Identity.Entity(args.User, EntityManager))), uid, uid, PopupType.Large); } diff --git a/Content.Server/Silicon/BlindHealing/BlindHealingComponent.cs b/Content.Server/Silicon/BlindHealing/BlindHealingComponent.cs index 4c3c478c4b8..fe218491708 100644 --- a/Content.Server/Silicon/BlindHealing/BlindHealingComponent.cs +++ b/Content.Server/Silicon/BlindHealing/BlindHealingComponent.cs @@ -1,28 +1,23 @@ -using Content.Shared.Damage; -using Content.Shared.Tools; -using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; +namespace Content.Server.Silicon.BlindHealing; -namespace Content.Server.Silicon.BlindHealing +[RegisterComponent] +public sealed partial class BlindHealingComponent : Component { - [RegisterComponent] - public sealed partial class BlindHealingComponent : Component - { - [DataField] - public int DoAfterDelay = 3; + [DataField] + public int DoAfterDelay = 3; - /// - /// A multiplier that will be applied to the above if an entity is repairing themselves. - /// - [DataField] - public float SelfHealPenalty = 3f; + /// + /// A multiplier that will be applied to the above if an entity is repairing themselves. + /// + [DataField] + public float SelfHealPenalty = 3f; - /// - /// Whether or not an entity is allowed to repair itself. - /// - [DataField] - public bool AllowSelfHeal = true; + /// + /// Whether or not an entity is allowed to repair itself. + /// + [DataField] + public bool AllowSelfHeal = true; - [DataField(required: true)] - public List DamageContainers; - } + [DataField(required: true)] + public List DamageContainers; } diff --git a/Content.Server/Silicon/BlindHealing/BlindHealingSystem.cs b/Content.Server/Silicon/BlindHealing/BlindHealingSystem.cs index 6cf60e6ef3f..b9d26b59f7c 100644 --- a/Content.Server/Silicon/BlindHealing/BlindHealingSystem.cs +++ b/Content.Server/Silicon/BlindHealing/BlindHealingSystem.cs @@ -12,110 +12,87 @@ using Content.Shared.Popups; using Content.Shared.Stacks; -namespace Content.Server.Silicon.BlindHealing +namespace Content.Server.Silicon.BlindHealing; + +public sealed class BlindHealingSystem : SharedBlindHealingSystem { - public sealed class BlindHealingSystem : SharedBlindHealingSystem + [Dependency] private readonly SharedPopupSystem _popup = default!; + [Dependency] private readonly IAdminLogManager _adminLogger = default!; + [Dependency] private readonly BlindableSystem _blindableSystem = default!; + [Dependency] private readonly StackSystem _stackSystem = default!; + [Dependency] private readonly SharedDoAfterSystem _doAfter = default!; + + public override void Initialize() { - [Dependency] private readonly SharedPopupSystem _popup = default!; - [Dependency] private readonly IAdminLogManager _adminLogger= default!; - [Dependency] private readonly BlindableSystem _blindableSystem = default!; - [Dependency] private readonly StackSystem _stackSystem = default!; - [Dependency] private readonly DamageableSystem _damageableSystem = default!; - [Dependency] private readonly SharedDoAfterSystem _doAfter = default!; - - public override void Initialize() - { - SubscribeLocalEvent(OnUse); - SubscribeLocalEvent(OnInteract); - SubscribeLocalEvent(OnHealingFinished); - } - - private void OnHealingFinished(EntityUid uid, BlindHealingComponent component, HealingDoAfterEvent args) - { - Log.Info("event started!"); - - if (args.Cancelled || args.Target == null) - return; - - EntityUid target = (EntityUid) args.Target; - - if(!EntityManager.TryGetComponent(target, out BlindableComponent? blindcomp) - || blindcomp is { EyeDamage: 0 }) - return; - - if(EntityManager.TryGetComponent(uid, out StackComponent? stackComponent)) - { - double price = 1; - if (EntityManager.TryGetComponent(uid, out StackPriceComponent? stackPrice)) - price = stackPrice.Price; - _stackSystem.SetCount(uid, (int) (_stackSystem.GetCount(uid, stackComponent) - price), stackComponent); + SubscribeLocalEvent(OnUse); + SubscribeLocalEvent(OnInteract); + SubscribeLocalEvent(OnHealingFinished); + } - } + private void OnHealingFinished(EntityUid uid, BlindHealingComponent component, HealingDoAfterEvent args) + { + if (args.Cancelled || args.Target == null + || !TryComp(args.Target, out var blindComp) + || blindComp is { EyeDamage: 0 }) + return; - _blindableSystem.AdjustEyeDamage((target, blindcomp), -blindcomp!.EyeDamage); + if (TryComp(uid, out var stackComponent) + && TryComp(uid, out var stackPrice)) + _stackSystem.SetCount(uid, (int) (_stackSystem.GetCount(uid, stackComponent) - stackPrice.Price), stackComponent); - _adminLogger.Add(LogType.Healed, $"{ToPrettyString(args.User):user} repaired {ToPrettyString(uid):target}'s vision"); + _blindableSystem.AdjustEyeDamage((args.Target.Value, blindComp), -blindComp.EyeDamage); - var str = Loc.GetString("comp-repairable-repair", - ("target", uid), - ("tool", args.Used!)); - _popup.PopupEntity(str, uid, args.User); + _adminLogger.Add(LogType.Healed, $"{ToPrettyString(args.User):user} repaired {ToPrettyString(uid):target}'s vision"); - } + var str = Loc.GetString("comp-repairable-repair", + ("target", uid), + ("tool", args.Used!)); + _popup.PopupEntity(str, uid, args.User); - private bool TryHealBlindness(EntityUid uid, EntityUid user, EntityUid target, float delay) - { - var doAfterEventArgs = - new DoAfterArgs(EntityManager, user, delay, new HealingDoAfterEvent(), uid, target: target, used: uid) - { - NeedHand = true, - BreakOnUserMove = true, - BreakOnWeightlessMove = false, - }; + } - _doAfter.TryStartDoAfter(doAfterEventArgs); - return true; - } + private bool TryHealBlindness(EntityUid uid, EntityUid user, EntityUid target, float delay) + { + var doAfterEventArgs = + new DoAfterArgs(EntityManager, user, delay, new HealingDoAfterEvent(), uid, target: target, used: uid) + { + NeedHand = true, + BreakOnUserMove = true, + BreakOnWeightlessMove = false, + }; - private void OnInteract(EntityUid uid, BlindHealingComponent component, ref AfterInteractEvent args) - { + _doAfter.TryStartDoAfter(doAfterEventArgs); + return true; + } - if (args.Handled - || !TryComp(args.User, out DamageableComponent? damageable) - || damageable.DamageContainerID != null - && !component.DamageContainers.Contains(damageable.DamageContainerID) - || !TryComp(args.User, out BlindableComponent? blindcomp) - || blindcomp is { EyeDamage: 0 }) - return; + private void OnInteract(EntityUid uid, BlindHealingComponent component, ref AfterInteractEvent args) + { - float delay = component.DoAfterDelay; + if (args.Handled + || !TryComp(args.User, out var damageable) + || damageable.DamageContainerID != null && !component.DamageContainers.Contains(damageable.DamageContainerID) + || !TryComp(args.User, out var blindcomp) + || blindcomp.EyeDamage == 0 + || args.User == args.Target && !component.AllowSelfHeal) + return; + + TryHealBlindness(uid, args.User, args.User, + args.User == args.Target + ? component.DoAfterDelay * component.SelfHealPenalty + : component.DoAfterDelay); + } - if (args.User == args.Target) - { - if (!component.AllowSelfHeal) - return; - delay *= component.SelfHealPenalty; - } - - TryHealBlindness(uid, args.User, args.User, delay); - } - - private void OnUse(EntityUid uid, BlindHealingComponent component, ref UseInHandEvent args) - { - if (args.Handled - || !TryComp(args.User, out DamageableComponent? damageable) - || damageable.DamageContainerID != null - && !component.DamageContainers.Contains(damageable.DamageContainerID) - || !TryComp(args.User, out BlindableComponent? blindcomp) - || blindcomp is { EyeDamage: 0 } - || !component.AllowSelfHeal) - return; - - float delay = component.DoAfterDelay; - delay *= component.SelfHealPenalty; - - TryHealBlindness(uid, args.User, args.User, delay); - - } + private void OnUse(EntityUid uid, BlindHealingComponent component, ref UseInHandEvent args) + { + if (args.Handled + || !TryComp(args.User, out var damageable) + || damageable.DamageContainerID != null && !component.DamageContainers.Contains(damageable.DamageContainerID) + || !TryComp(args.User, out var blindcomp) + || blindcomp.EyeDamage == 0 + || !component.AllowSelfHeal) + return; + + TryHealBlindness(uid, args.User, args.User, + component.DoAfterDelay * component.SelfHealPenalty); } } diff --git a/Content.Server/Silicon/Charge/Components/SiliconDownOnDeadComponent.cs b/Content.Server/Silicon/Charge/Components/SiliconDownOnDeadComponent.cs index 3080144cd4a..4b3aad33ab6 100644 --- a/Content.Server/Silicon/Charge/Components/SiliconDownOnDeadComponent.cs +++ b/Content.Server/Silicon/Charge/Components/SiliconDownOnDeadComponent.cs @@ -1,5 +1,3 @@ -using System.Threading; - namespace Content.Server.Silicon.Death; /// @@ -15,5 +13,5 @@ public sealed partial class SiliconDownOnDeadComponent : Component /// Is this Silicon currently dead? /// [ViewVariables(VVAccess.ReadOnly)] - public bool Dead { get; set; } = false; + public bool Dead; } diff --git a/Content.Server/Silicon/Charge/Systems/SiliconChargeDeathSystem.cs b/Content.Server/Silicon/Charge/Systems/SiliconChargeDeathSystem.cs index d6fa07a1a14..d4d1db5ed96 100644 --- a/Content.Server/Silicon/Charge/Systems/SiliconChargeDeathSystem.cs +++ b/Content.Server/Silicon/Charge/Systems/SiliconChargeDeathSystem.cs @@ -2,14 +2,9 @@ using Content.Shared.Silicon.Systems; using Content.Server.Bed.Sleep; using Content.Shared.Bed.Sleep; -using Content.Server.Sound.Components; using Content.Server.Silicon.Charge; -using System.Threading; using Content.Server.Humanoid; using Content.Shared.Humanoid; -using Content.Shared.Humanoid.Markings; -using Robust.Shared.Utility; -using Timer = Robust.Shared.Timing.Timer; namespace Content.Server.Silicon.Death; @@ -40,7 +35,7 @@ private void OnSiliconChargeStateUpdate(EntityUid uid, SiliconDownOnDeadComponen if (args.ChargePercent == 0 && !siliconDeadComp.Dead) SiliconDead(uid, siliconDeadComp, batteryComp, uid); else if (args.ChargePercent != 0 && siliconDeadComp.Dead) - SiliconUnDead(uid, siliconDeadComp, batteryComp, uid); + SiliconUnDead(uid, siliconDeadComp, batteryComp, uid); } private void SiliconDead(EntityUid uid, SiliconDownOnDeadComponent siliconDeadComp, BatteryComponent? batteryComp, EntityUid batteryUid) @@ -54,7 +49,7 @@ private void SiliconDead(EntityUid uid, SiliconDownOnDeadComponent siliconDeadCo EntityManager.EnsureComponent(uid); EntityManager.EnsureComponent(uid); - if (TryComp(uid, out HumanoidAppearanceComponent? humanoidAppearanceComponent)) + if (TryComp(uid, out var humanoidAppearanceComponent)) { var layers = HumanoidVisualLayersExtension.Sublayers(HumanoidVisualLayers.HeadSide); _humanoidAppearanceSystem.SetLayersVisibility(uid, layers, false, true, humanoidAppearanceComponent); diff --git a/Content.Server/Silicon/Charge/Systems/SiliconChargeSystem.cs b/Content.Server/Silicon/Charge/Systems/SiliconChargeSystem.cs index de50c828bd7..d8b034a69f5 100644 --- a/Content.Server/Silicon/Charge/Systems/SiliconChargeSystem.cs +++ b/Content.Server/Silicon/Charge/Systems/SiliconChargeSystem.cs @@ -10,20 +10,16 @@ using Content.Shared.Silicon.Systems; using Content.Shared.Movement.Systems; using Content.Server.Body.Components; -using Content.Server.Power.EntitySystems; using Robust.Shared.Containers; using Content.Shared.Mind.Components; using System.Diagnostics.CodeAnalysis; using Content.Server.PowerCell; using Robust.Shared.Timing; using Robust.Shared.Configuration; -using Robust.Shared.Audio.Systems; using Robust.Shared.Utility; using Content.Shared.CCVar; using Content.Shared.PowerCell.Components; -using Content.Shared.Mind; using Content.Shared.Alert; -using Content.Server.Silicon.Death; namespace Content.Server.Silicon.Charge; @@ -34,7 +30,6 @@ public sealed class SiliconChargeSystem : EntitySystem [Dependency] private readonly FlammableSystem _flammable = default!; [Dependency] private readonly PopupSystem _popup = default!; [Dependency] private readonly MovementSpeedModifierSystem _moveMod = default!; - [Dependency] private readonly SharedContainerSystem _container = default!; [Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly IConfigurationManager _config = default!; [Dependency] private readonly PowerCellSystem _powerCell = default!; @@ -49,27 +44,23 @@ public override void Initialize() public bool TryGetSiliconBattery(EntityUid silicon, [NotNullWhen(true)] out BatteryComponent? batteryComp) { batteryComp = null; - if (!TryComp(silicon, out SiliconComponent? siliconComp)) + if (!HasComp(silicon)) return false; - // try get a battery directly on the inserted entity if (TryComp(silicon, out batteryComp) || _powerCell.TryGetBatteryFromSlot(silicon, out batteryComp)) return true; - //DebugTools.Assert("SiliconComponent does not contain Battery"); return false; } private void OnSiliconStartup(EntityUid uid, SiliconComponent component, ComponentStartup args) { - if (!TryComp(uid, out PowerCellSlotComponent? batterySlot)) + if (!HasComp(uid)) return; - var container = _container.GetContainer(uid, batterySlot.CellSlotId); - if (component.EntityType.GetType() != typeof(SiliconType)) DebugTools.Assert("SiliconComponent.EntityType is not a SiliconType enum."); } @@ -82,7 +73,8 @@ public override void Update(float frameTime) var query = EntityQueryEnumerator(); while (query.MoveNext(out var silicon, out var siliconComp)) { - if (!siliconComp.BatteryPowered) + if (_mobState.IsDead(silicon) + || !siliconComp.BatteryPowered) continue; // Check if the Silicon is an NPC, and if so, follow the delay as specified in the CVAR. @@ -107,20 +99,11 @@ public override void Update(float frameTime) continue; } - // If the silicon is dead, skip it. - if (_mobState.IsDead(silicon)) + // If the silicon ghosted or is SSD while still being powered, skip it. + if (TryComp(silicon, out var mindContComp) + && !mindContComp.HasMind) continue; - // If the silicon ghosted or is SSD while still being powered, skip it. - DeltaV - if (EntityManager.TryGetComponent(silicon, out var mindContComp) - && EntityManager.TryGetComponent(silicon, out var siliconDeathComp)) - { - if ((mindContComp.HasMind == false || CompOrNull(mindContComp.Mind)?.Session == null) && !siliconDeathComp.Dead) - { - continue; - } - } - var drainRate = siliconComp.DrainPerSecond; // All multipliers will be subtracted by 1, and then added together, and then multiplied by the drain rate. This is then added to the base drain rate. @@ -131,7 +114,7 @@ public override void Update(float frameTime) // Maybe use something similar to refreshmovespeedmodifiers, where it's stored in the component. // Maybe it doesn't matter, and stuff should just use static drain? if (!siliconComp.EntityType.Equals(SiliconType.Npc)) // Don't bother checking heat if it's an NPC. It's a waste of time, and it'd be delayed due to the update time. - drainRateFinalAddi += SiliconHeatEffects(silicon, frameTime) - 1; // This will need to be changed at some point if we allow external batteries, since the heat of the Silicon might not be applicable. + drainRateFinalAddi += SiliconHeatEffects(silicon, siliconComp, frameTime) - 1; // This will need to be changed at some point if we allow external batteries, since the heat of the Silicon might not be applicable. // Ensures that the drain rate is at least 10% of normal, // and would allow at least 4 minutes of life with a max charge, to prevent cheese. @@ -166,14 +149,12 @@ public void UpdateChargeState(EntityUid uid, short chargePercent, SiliconCompone } } - private float SiliconHeatEffects(EntityUid silicon, float frameTime) + private float SiliconHeatEffects(EntityUid silicon, SiliconComponent siliconComp, float frameTime) { - if (!EntityManager.TryGetComponent(silicon, out var temperComp) - || !EntityManager.TryGetComponent(silicon, out var thermalComp)) + if (!TryComp(silicon, out var temperComp) + || !TryComp(silicon, out var thermalComp)) return 0; - var siliconComp = EntityManager.GetComponent(silicon); - // If the Silicon is hot, drain the battery faster, if it's cold, drain it slower, capped. var upperThresh = thermalComp.NormalBodyTemperature + thermalComp.ThermalRegulationTemperatureThreshold; var upperThreshHalf = thermalComp.NormalBodyTemperature + thermalComp.ThermalRegulationTemperatureThreshold * 0.5f; @@ -198,12 +179,11 @@ private float SiliconHeatEffects(EntityUid silicon, float frameTime) return hotTempMulti; _popup.PopupEntity(Loc.GetString("silicon-overheating"), silicon, silicon, PopupType.MediumCaution); - if (_random.Prob(Math.Clamp(temperComp.CurrentTemperature / (upperThresh * 5), 0.001f, 0.9f))) - { - //MaximumFireStacks and MinimumFireStacks doesn't exists on EE - _flammable.AdjustFireStacks(silicon, Math.Clamp(siliconComp.FireStackMultiplier, -10, 10), flamComp); - _flammable.Ignite(silicon, silicon, flamComp); - } + if (!_random.Prob(Math.Clamp(temperComp.CurrentTemperature / (upperThresh * 5), 0.001f, 0.9f))) + return hotTempMulti; + + _flammable.AdjustFireStacks(silicon, Math.Clamp(siliconComp.FireStackMultiplier, -10, 10), flamComp); + _flammable.Ignite(silicon, silicon, flamComp); return hotTempMulti; } diff --git a/Content.Server/Silicon/DeadStartupButtonSystem/DeadStartupButtonSystem.cs b/Content.Server/Silicon/DeadStartupButtonSystem/DeadStartupButtonSystem.cs index a25f2a22545..1c43a3cff91 100644 --- a/Content.Server/Silicon/DeadStartupButtonSystem/DeadStartupButtonSystem.cs +++ b/Content.Server/Silicon/DeadStartupButtonSystem/DeadStartupButtonSystem.cs @@ -1,4 +1,3 @@ -using Content.Server.Chat.Systems; using Content.Server.Lightning; using Content.Server.Popups; using Content.Server.PowerCell; @@ -25,7 +24,6 @@ public sealed class DeadStartupButtonSystem : SharedDeadStartupButtonSystem [Dependency] private readonly LightningSystem _lightning = default!; [Dependency] private readonly SiliconChargeSystem _siliconChargeSystem = default!; [Dependency] private readonly PowerCellSystem _powerCell = default!; - [Dependency] private readonly ChatSystem _chatSystem = default!; /// public override void Initialize() @@ -39,14 +37,13 @@ public override void Initialize() private void OnDoAfter(EntityUid uid, DeadStartupButtonComponent comp, OnDoAfterButtonPressedEvent args) { if (args.Handled || args.Cancelled - || !TryComp(uid, out MobStateComponent? mobStateComponent) + || !TryComp(uid, out var mobStateComponent) || !_mobState.IsDead(uid, mobStateComponent) - || !TryComp(uid, out MobThresholdsComponent? mobThresholdsComponent) - || !TryComp(uid, out DamageableComponent? damageable)) + || !TryComp(uid, out var mobThresholdsComponent) + || !TryComp(uid, out var damageable) + || !_mobThreshold.TryGetThresholdForState(uid, MobState.Critical, out var criticalThreshold, mobThresholdsComponent)) return; - var criticalThreshold = _mobThreshold.GetThresholdForState(uid, MobState.Critical, mobThresholdsComponent); - if (damageable.TotalDamage < criticalThreshold) _mobState.ChangeMobState(uid, MobState.Alive, mobStateComponent); else @@ -59,9 +56,9 @@ private void OnDoAfter(EntityUid uid, DeadStartupButtonComponent comp, OnDoAfter private void OnElectrocuted(EntityUid uid, DeadStartupButtonComponent comp, ElectrocutedEvent args) { - if (!TryComp(uid, out MobStateComponent? mobStateComponent) + if (!TryComp(uid, out var mobStateComponent) || !_mobState.IsDead(uid, mobStateComponent) - || !_siliconChargeSystem.TryGetSiliconBattery(uid, out var bateria) + || !_siliconChargeSystem.TryGetSiliconBattery(uid, out var bateria) || bateria.CurrentCharge <= 0) return; @@ -72,13 +69,10 @@ private void OnElectrocuted(EntityUid uid, DeadStartupButtonComponent comp, Elec private void OnMobStateChanged(EntityUid uid, DeadStartupButtonComponent comp, MobStateChangedEvent args) { + if (args.NewMobState != MobState.Alive) + return; - if (args.NewMobState == MobState.Alive) - { - _popup.PopupEntity(Loc.GetString("dead-startup-system-reboot-success", ("target", MetaData(uid).EntityName)), uid); - _audio.PlayPvs(comp.Sound, uid); - } - + _popup.PopupEntity(Loc.GetString("dead-startup-system-reboot-success", ("target", MetaData(uid).EntityName)), uid); + _audio.PlayPvs(comp.Sound, uid); } - } diff --git a/Content.Server/Silicon/EmitBuzzWhileDamaged/EmitBuzzWhileDamagedSystem.cs b/Content.Server/Silicon/EmitBuzzWhileDamaged/EmitBuzzWhileDamagedSystem.cs index 05e5f5af89b..161a912d061 100644 --- a/Content.Server/Silicon/EmitBuzzWhileDamaged/EmitBuzzWhileDamagedSystem.cs +++ b/Content.Server/Silicon/EmitBuzzWhileDamaged/EmitBuzzWhileDamagedSystem.cs @@ -1,13 +1,13 @@ using Content.Server.Popups; using Content.Shared.Silicon.EmitBuzzWhileDamaged; using Content.Shared.Audio; -using Content.Shared.Body.Components; using Content.Shared.Damage; using Content.Shared.Mobs; using Content.Shared.Mobs.Systems; using Robust.Shared.Audio.Systems; using Robust.Shared.Random; using Robust.Shared.Timing; +using Content.Shared.Mobs.Components; namespace Content.Server.Silicon.EmitBuzzOnCrit; @@ -27,34 +27,29 @@ public override void Update(float frameTime) { base.Update(frameTime); - var query = EntityQueryEnumerator(); + var query = EntityQueryEnumerator(); - while (query.MoveNext(out var uid, out var emitBuzzOnCritComponent, out var body)) + while (query.MoveNext(out var uid, out var emitBuzzOnCritComponent, out var mobStateComponent, out var thresholdsComponent, out var damageableComponent)) { - - if (_mobState.IsDead(uid) - || !_mobThreshold.TryGetThresholdForState(uid, MobState.Critical, out var threshold) - || !TryComp(uid, out DamageableComponent? damageableComponent) - || damageableComponent.TotalDamage < (threshold/2)) + if (_mobState.IsDead(uid, mobStateComponent) + || !_mobThreshold.TryGetThresholdForState(uid, MobState.Critical, out var threshold, thresholdsComponent) + || damageableComponent.TotalDamage < threshold / 2) continue; - + // Check update time emitBuzzOnCritComponent.AccumulatedFrametime += frameTime; - if (emitBuzzOnCritComponent.AccumulatedFrametime < emitBuzzOnCritComponent.CycleDelay) continue; emitBuzzOnCritComponent.AccumulatedFrametime -= emitBuzzOnCritComponent.CycleDelay; + if (_gameTiming.CurTime <= emitBuzzOnCritComponent.LastBuzzPopupTime + emitBuzzOnCritComponent.BuzzPopupCooldown) + continue; - // start buzzing - if (_gameTiming.CurTime >= emitBuzzOnCritComponent.LastBuzzPopupTime + emitBuzzOnCritComponent.BuzzPopupCooldown) - { - emitBuzzOnCritComponent.LastBuzzPopupTime = _gameTiming.CurTime; - _popupSystem.PopupEntity(Loc.GetString("silicon-behavior-buzz"), uid); - Spawn("EffectSparks", Transform(uid).Coordinates); - _audio.PlayPvs(emitBuzzOnCritComponent.Sound, uid, AudioHelpers.WithVariation(0.05f, _robustRandom)); - } + // Start buzzing + emitBuzzOnCritComponent.LastBuzzPopupTime = _gameTiming.CurTime; + _popupSystem.PopupEntity(Loc.GetString("silicon-behavior-buzz"), uid); + Spawn("EffectSparks", Transform(uid).Coordinates); + _audio.PlayPvs(emitBuzzOnCritComponent.Sound, uid, AudioHelpers.WithVariation(0.05f, _robustRandom)); } } - } diff --git a/Content.Server/Silicon/EncryptionHolderRequiresLock/EncryptionHolderRequiresLockSystem.cs b/Content.Server/Silicon/EncryptionHolderRequiresLock/EncryptionHolderRequiresLockSystem.cs index 5eb4f25c49b..6efb51096c3 100644 --- a/Content.Server/Silicon/EncryptionHolderRequiresLock/EncryptionHolderRequiresLockSystem.cs +++ b/Content.Server/Silicon/EncryptionHolderRequiresLock/EncryptionHolderRequiresLockSystem.cs @@ -1,4 +1,3 @@ -using Content.Shared.Containers.ItemSlots; using Content.Shared.Lock; using Content.Shared.Radio.Components; using Content.Shared.Radio.EntitySystems; @@ -8,7 +7,6 @@ namespace Content.Server.Silicon.EncryptionHolderRequiresLock; public sealed class EncryptionHolderRequiresLockSystem : EntitySystem { - [Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!; [Dependency] private readonly EncryptionKeySystem _encryptionKeySystem = default!; /// @@ -16,11 +14,11 @@ public override void Initialize() { base.Initialize(); SubscribeLocalEvent(LockToggled); - } + private void LockToggled(EntityUid uid, EncryptionHolderRequiresLockComponent component, LockToggledEvent args) { - if (!TryComp(uid, out var lockComp) + if (!TryComp(uid, out var lockComp) || !TryComp(uid, out var keyHolder)) return; diff --git a/Content.Server/Silicon/IPC/InternalEncryptionKeySpawner.cs b/Content.Server/Silicon/IPC/InternalEncryptionKeySpawner.cs index eb01409e854..7f5d216c92f 100644 --- a/Content.Server/Silicon/IPC/InternalEncryptionKeySpawner.cs +++ b/Content.Server/Silicon/IPC/InternalEncryptionKeySpawner.cs @@ -1,39 +1,31 @@ -using Content.Shared.Preferences; using Content.Shared.Roles; using Content.Shared.Radio.Components; using Content.Shared.Containers; using Robust.Shared.Containers; +using Content.Server.Cargo.Components; - // Pretty much copied from StationSpawningSystem.SpawnStartingGear namespace Content.Server.Silicon.IPC; -public static class InternalEncryptionKeySpawner +public sealed partial class InternalEncryptionKeySpawner : EntitySystem { - public static void TryInsertEncryptionKey(EntityUid target, StartingGearPrototype startingGear, IEntityManager entityManager, HumanoidCharacterProfile? profile) + [Dependency] private readonly SharedContainerSystem _container = default!; + public void TryInsertEncryptionKey(EntityUid target, StartingGearPrototype startingGear, IEntityManager entityManager) { - if (entityManager.TryGetComponent(target, out var keyHolderComp)) - { - var earEquipString = startingGear.GetGear("ears", profile); - var containerMan = entityManager.System(); + if (!TryComp(target, out var keyHolderComp) + || !startingGear.Equipment.TryGetValue("ears", out var earEquipString) + || string.IsNullOrEmpty(earEquipString)) + return; - if (!string.IsNullOrEmpty(earEquipString)) - { - var earEntity = entityManager.SpawnEntity(earEquipString, entityManager.GetComponent(target).Coordinates); + var earEntity = entityManager.SpawnEntity(earEquipString, entityManager.GetComponent(target).Coordinates); + if (!entityManager.HasComponent(earEntity) + || !entityManager.TryGetComponent(earEntity, out var fillComp) + || !fillComp.Containers.TryGetValue(EncryptionKeyHolderComponent.KeyContainerName, out var defaultKeys)) + return; - if (entityManager.TryGetComponent(earEntity, out _) && // I had initially wanted this to spawn the headset, and simply move all the keys over, but the headset didn't seem to have any keys in it when spawned... - entityManager.TryGetComponent(earEntity, out var fillComp) && - fillComp.Containers.TryGetValue(EncryptionKeyHolderComponent.KeyContainerName, out var defaultKeys)) - { - containerMan.CleanContainer(keyHolderComp.KeyContainer); + _container.CleanContainer(keyHolderComp.KeyContainer); - foreach (var key in defaultKeys) - { - var keyEntity = entityManager.SpawnEntity(key, entityManager.GetComponent(target).Coordinates); - containerMan.Insert(keyEntity, keyHolderComp.KeyContainer, force: true); - } - } + foreach (var key in defaultKeys) + entityManager.SpawnInContainerOrDrop(key, target, keyHolderComp.KeyContainer.ID, out _); - entityManager.QueueDeleteEntity(earEntity); - } - } + entityManager.QueueDeleteEntity(earEntity); } } diff --git a/Content.Server/Silicon/Systems/SiliconMiscSystem.cs b/Content.Server/Silicon/Systems/SiliconMiscSystem.cs deleted file mode 100644 index 85d76c77bc8..00000000000 --- a/Content.Server/Silicon/Systems/SiliconMiscSystem.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Content.Shared.Silicon.Components; -using Content.Shared.Bed.Sleep; - -namespace Content.Server.Silicon.Misc; - -// This entire thing is fucking stupid and I hate it. -public sealed class SiliconMiscSystem : EntitySystem -{ - public override void Initialize() - { - base.Initialize(); - - SubscribeLocalEvent(OnTryingToSleep); - } - - private void OnTryingToSleep(EntityUid uid, SiliconComponent component, ref TryingToSleepEvent args) - { - args.Cancelled = true; - } -} diff --git a/Content.Server/Silicon/WeldingHealable/WeldingHealableComponent.cs b/Content.Server/Silicon/WeldingHealable/WeldingHealableComponent.cs index 115e9308707..9f4b6c3483f 100644 --- a/Content.Server/Silicon/WeldingHealable/WeldingHealableComponent.cs +++ b/Content.Server/Silicon/WeldingHealable/WeldingHealableComponent.cs @@ -1,9 +1,5 @@ -using Content.Shared.Damage; -using Content.Shared.Tools; -using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; +namespace Content.Server.Silicon.WeldingHealable; + +[RegisterComponent] +public sealed partial class WeldingHealableComponent : Component { } -namespace Content.Server.Silicon.WeldingHealable -{ - [RegisterComponent] - public sealed partial class WeldingHealableComponent : Component { } -} diff --git a/Content.Server/Silicon/WeldingHealable/WeldingHealableSystem.cs b/Content.Server/Silicon/WeldingHealable/WeldingHealableSystem.cs index 09a2ee99fcd..e0783db0c8b 100644 --- a/Content.Server/Silicon/WeldingHealable/WeldingHealableSystem.cs +++ b/Content.Server/Silicon/WeldingHealable/WeldingHealableSystem.cs @@ -1,121 +1,102 @@ -using System.Diagnostics; using Content.Server.Silicon.WeldingHealing; -using Content.Server.Administration.Logs; -using Content.Server.Stack; using Content.Server.Tools.Components; using Content.Shared.Silicon.WeldingHealing; -using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Components.SolutionManager; using Content.Shared.Chemistry.EntitySystems; using Content.Shared.Damage; -using Content.Shared.Database; -using Content.Shared.Eye.Blinding.Components; -using Content.Shared.Eye.Blinding.Systems; -using Content.Shared.FixedPoint; using Content.Shared.Interaction; using Content.Shared.Popups; -using Content.Shared.Tools; -using Content.Shared.Stacks; using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem; -namespace Content.Server.Silicon.WeldingHealable -{ - public sealed class WeldingHealableSystem : SharedWeldingHealableSystem - { - [Dependency] private readonly SharedToolSystem _toolSystem = default!; - [Dependency] private readonly DamageableSystem _damageableSystem = default!; - [Dependency] private readonly SharedPopupSystem _popup = default!; - [Dependency] private readonly IAdminLogManager _adminLogger= default!; - [Dependency] private readonly SharedSolutionContainerSystem _solutionContainer= default!; - - public override void Initialize() - { - SubscribeLocalEvent(Repair); - SubscribeLocalEvent(OnRepairFinished); - } - - private void OnRepairFinished(EntityUid uid, WeldingHealableComponent healableComponentcomponent, SiliconRepairFinishedEvent args) - { - if (args.Cancelled || args.Used == null - || !EntityManager.TryGetComponent(args.Target, out DamageableComponent? damageable) - || !EntityManager.TryGetComponent(args.Used, out WeldingHealingComponent? component) - || damageable.DamageContainerID != null - && !component.DamageContainers.Contains(damageable.DamageContainerID)) - return; - - var damageChanged = _damageableSystem.TryChangeDamage(uid, component.Damage, true, false, origin: args.User); - - - if (!HasDamage(damageable, component)) - return; - - if (TryComp(args.Used, out WelderComponent? welder) && - TryComp(args.Used, out SolutionContainerManagerComponent? solutionContainer)) - { - if (!_solutionContainer.ResolveSolution(((EntityUid) args.Used, solutionContainer), welder.FuelSolutionName, ref welder.FuelSolution, out var solution)) - return; - _solutionContainer.RemoveReagent(welder.FuelSolution.Value, welder.FuelReagent, component.FuelCost); - } - - var str = Loc.GetString("comp-repairable-repair", - ("target", uid), - ("tool", args.Used!)); - _popup.PopupEntity(str, uid, args.User); - - - if (args.Used.HasValue) - { - args.Handled = _toolSystem.UseTool(args.Used.Value, args.User, uid, args.Delay, component.QualityNeeded, new SiliconRepairFinishedEvent - { - Delay = args.Delay - }); - } - } - - +namespace Content.Server.Silicon.WeldingHealable; - private async void Repair(EntityUid uid, WeldingHealableComponent healableComponent, InteractUsingEvent args) - { - if (args.Handled - || !EntityManager.TryGetComponent(args.Used, out WeldingHealingComponent? component) - || !EntityManager.TryGetComponent(args.Target, out DamageableComponent? damageable) - || damageable.DamageContainerID != null - && !component.DamageContainers.Contains(damageable.DamageContainerID) - || !HasDamage(damageable, component) - || !_toolSystem.HasQuality(args.Used, component.QualityNeeded)) - return; +public sealed class WeldingHealableSystem : SharedWeldingHealableSystem +{ + [Dependency] private readonly SharedToolSystem _toolSystem = default!; + [Dependency] private readonly DamageableSystem _damageableSystem = default!; + [Dependency] private readonly SharedPopupSystem _popup = default!; + [Dependency] private readonly SharedSolutionContainerSystem _solutionContainer = default!; - float delay = component.DoAfterDelay; + public override void Initialize() + { + SubscribeLocalEvent(Repair); + SubscribeLocalEvent(OnRepairFinished); + } - // Add a penalty to how long it takes if the user is repairing itself - if (args.User == args.Target) + private void OnRepairFinished(EntityUid uid, WeldingHealableComponent healableComponent, SiliconRepairFinishedEvent args) + { + if (args.Cancelled || args.Used == null + || !TryComp(args.Target, out var damageable) + || !TryComp(args.Used, out var component) + || damageable.DamageContainerID is null + || !component.DamageContainers.Contains(damageable.DamageContainerID) + || !HasDamage(damageable, component) + || !TryComp(args.Used, out var welder) + || !TryComp(args.Used, out var solutionContainer) + || !_solutionContainer.ResolveSolution(((EntityUid) args.Used, solutionContainer), welder.FuelSolutionName, ref welder.FuelSolution)) + return; + + _damageableSystem.TryChangeDamage(uid, component.Damage, true, false, origin: args.User); + + _solutionContainer.RemoveReagent(welder.FuelSolution.Value, welder.FuelReagent, component.FuelCost); + + var str = Loc.GetString("comp-repairable-repair", + ("target", uid), + ("tool", args.Used!)); + _popup.PopupEntity(str, uid, args.User); + + if (!args.Used.HasValue) + return; + + args.Handled = _toolSystem.UseTool + (args.Used.Value, + args.User, + uid, + args.Delay, + component.QualityNeeded, + new SiliconRepairFinishedEvent { - if (!component.AllowSelfHeal) - return; - - delay *= component.SelfHealPenalty; - } + Delay = args.Delay + }); + } - // Run the repairing doafter - args.Handled = _toolSystem.UseTool(args.Used, args.User, args.Target, delay, component.QualityNeeded, new SiliconRepairFinishedEvent + private async void Repair(EntityUid uid, WeldingHealableComponent healableComponent, InteractUsingEvent args) + { + if (args.Handled + || !EntityManager.TryGetComponent(args.Used, out WeldingHealingComponent? component) + || !EntityManager.TryGetComponent(args.Target, out DamageableComponent? damageable) + || damageable.DamageContainerID is null + || !component.DamageContainers.Contains(damageable.DamageContainerID) + || !HasDamage(damageable, component) + || !_toolSystem.HasQuality(args.Used, component.QualityNeeded) + || args.User == args.Target && !component.AllowSelfHeal) + return; + + float delay = args.User == args.Target + ? component.DoAfterDelay * component.SelfHealPenalty + : component.DoAfterDelay; + + args.Handled = _toolSystem.UseTool + (args.Used, + args.User, + args.Target, + delay, + component.QualityNeeded, + new SiliconRepairFinishedEvent { Delay = delay, }); + } - } - private bool HasDamage(DamageableComponent component, WeldingHealingComponent healable) - { - var damageableDict = component.Damage.DamageDict; - var healingDict = healable.Damage.DamageDict; - foreach (var type in healingDict) - { - if (damageableDict[type.Key].Value > 0) - { - return true; - } - } - + private bool HasDamage(DamageableComponent component, WeldingHealingComponent healable) + { + if (healable.Damage.DamageDict is null) return false; - } + + foreach (var type in healable.Damage.DamageDict) + if (component.Damage.DamageDict[type.Key].Value > 0) + return true; + return false; } } + diff --git a/Content.Server/Silicon/WeldingHealing/WeldingHealingComponent.cs b/Content.Server/Silicon/WeldingHealing/WeldingHealingComponent.cs index c381d547180..a7aa1707938 100644 --- a/Content.Server/Silicon/WeldingHealing/WeldingHealingComponent.cs +++ b/Content.Server/Silicon/WeldingHealing/WeldingHealingComponent.cs @@ -2,47 +2,46 @@ using Content.Shared.Tools; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; -namespace Content.Server.Silicon.WeldingHealing +namespace Content.Server.Silicon.WeldingHealing; + +[RegisterComponent] +public sealed partial class WeldingHealingComponent : Component { - [RegisterComponent] - public sealed partial class WeldingHealingComponent : Component - { - /// - /// All the damage to change information is stored in this . - /// - /// - /// If this data-field is specified, it will change damage by this amount instead of setting all damage to 0. - /// in order to heal/repair the damage values have to be negative. - /// - - [DataField(required: true)] - public DamageSpecifier Damage; - - [DataField(customTypeSerializer:typeof(PrototypeIdSerializer))] - public string QualityNeeded = "Welding"; - - /// - /// The fuel amount needed to repair physical related damage - /// - [DataField] - public int FuelCost = 5; - - [DataField] - public int DoAfterDelay = 3; - - /// - /// A multiplier that will be applied to the above if an entity is repairing themselves. - /// - [DataField] - public float SelfHealPenalty = 3f; - - /// - /// Whether or not an entity is allowed to repair itself. - /// - [DataField] - public bool AllowSelfHeal = true; - - [DataField(required: true)] - public List DamageContainers; - } + /// + /// All the damage to change information is stored in this . + /// + /// + /// If this data-field is specified, it will change damage by this amount instead of setting all damage to 0. + /// in order to heal/repair the damage values have to be negative. + /// + + [DataField(required: true)] + public DamageSpecifier Damage; + + [DataField(customTypeSerializer:typeof(PrototypeIdSerializer))] + public string QualityNeeded = "Welding"; + + /// + /// The fuel amount needed to repair physical related damage + /// + [DataField] + public int FuelCost = 5; + + [DataField] + public int DoAfterDelay = 3; + + /// + /// A multiplier that will be applied to the above if an entity is repairing themselves. + /// + [DataField] + public float SelfHealPenalty = 3f; + + /// + /// Whether or not an entity is allowed to repair itself. + /// + [DataField] + public bool AllowSelfHeal = true; + + [DataField(required: true)] + public List DamageContainers; } diff --git a/Content.Server/Station/Systems/StationSpawningSystem.cs b/Content.Server/Station/Systems/StationSpawningSystem.cs index 61fc1e0a51b..92f16de5c73 100644 --- a/Content.Server/Station/Systems/StationSpawningSystem.cs +++ b/Content.Server/Station/Systems/StationSpawningSystem.cs @@ -47,7 +47,7 @@ public sealed class StationSpawningSystem : SharedStationSpawningSystem [Dependency] private readonly SharedAccessSystem _accessSystem = default!; [Dependency] private readonly IdentitySystem _identity = default!; [Dependency] private readonly MetaDataSystem _metaSystem = default!; - + [Dependency] private readonly InternalEncryptionKeySpawner _internalEncryption = default!; [Dependency] private readonly ArrivalsSystem _arrivalsSystem = default!; [Dependency] private readonly ContainerSpawnPointSystem _containerSpawnPointSystem = default!; @@ -176,7 +176,7 @@ public EntityUid SpawnPlayerMob( EquipStartingGear(entity.Value, startingGear); if (profile != null) EquipIdCard(entity.Value, profile.Name, prototype, station); - InternalEncryptionKeySpawner.TryInsertEncryptionKey(entity.Value, startingGear, EntityManager, profile); // Parkstation - IPC + _internalEncryption.TryInsertEncryptionKey(entity.Value, startingGear, EntityManager); } if (profile != null) diff --git a/Content.Shared/Lock/LockComponent.cs b/Content.Shared/Lock/LockComponent.cs index 9606540a74a..875451b5a14 100644 --- a/Content.Shared/Lock/LockComponent.cs +++ b/Content.Shared/Lock/LockComponent.cs @@ -14,88 +14,82 @@ namespace Content.Shared.Lock; public sealed partial class LockComponent : Component { /// - /// Whether or not the lock is locked. + /// Whether or not the lock is locked. /// - [DataField("locked"), ViewVariables(VVAccess.ReadWrite)] - [AutoNetworkedField] - public bool Locked = true; + [DataField, AutoNetworkedField] + public bool Locked = true; /// - /// Whether or not the lock is toggled by simply clicking. + /// Whether or not the lock is toggled by simply clicking. /// - [DataField("lockOnClick"), ViewVariables(VVAccess.ReadWrite)] - [AutoNetworkedField] + [DataField, AutoNetworkedField] public bool LockOnClick; /// - /// Whether or not the lock is unlocked by simply clicking. + /// Whether or not the lock is unlocked by simply clicking. /// - [DataField("unlockOnClick"), ViewVariables(VVAccess.ReadWrite)] - [AutoNetworkedField] + [DataField, AutoNetworkedField] public bool UnlockOnClick = true; /// - /// The sound played when unlocked. + /// The sound played when unlocked. /// - [DataField("unlockingSound"), ViewVariables(VVAccess.ReadWrite)] + [DataField] public SoundSpecifier UnlockSound = new SoundPathSpecifier("/Audio/Machines/door_lock_off.ogg") { Params = AudioParams.Default.WithVolume(-5f), }; /// - /// The sound played when locked. + /// The sound played when locked. /// - [DataField("lockingSound"), ViewVariables(VVAccess.ReadWrite)] + [DataField] public SoundSpecifier LockSound = new SoundPathSpecifier("/Audio/Machines/door_lock_on.ogg") { Params = AudioParams.Default.WithVolume(-5f) }; /// - /// Whether or not an emag disables it. + /// Whether or not an emag disables it. /// - [DataField("breakOnEmag")] - [AutoNetworkedField] + [DataField, AutoNetworkedField] public bool BreakOnEmag = true; /// - /// Amount of do-after time needed to lock the entity. + /// Amount of do-after time needed to lock the entity. /// /// - /// If set to zero, no do-after will be used. + /// If set to zero, no do-after will be used. /// - [DataField] - [AutoNetworkedField] + [DataField, AutoNetworkedField] public TimeSpan LockTime; /// - /// Amount of do-after time needed to unlock the entity. + /// Amount of do-after time needed to unlock the entity. /// /// - /// If set to zero, no do-after will be used. + /// If set to zero, no do-after will be used. /// - [DataField] - [AutoNetworkedField] + [DataField, AutoNetworkedField] public TimeSpan UnlockTime; } /// -/// Event raised on the lock when a toggle is attempted. -/// Can be cancelled to prevent it. +/// Event raised on the lock when a toggle is attempted. +/// Can be cancelled to prevent it. /// [ByRefEvent] public record struct LockToggleAttemptEvent(EntityUid User, bool Silent = false, bool Cancelled = false); /// -/// Event raised on a lock after it has been toggled. +/// Event raised on a lock after it has been toggled. /// [ByRefEvent] public readonly record struct LockToggledEvent(bool Locked); /// -/// Used to lock a lockable entity that has a lock time configured. +/// Used to lock a lockable entity that has a lock time configured. /// /// /// @@ -109,7 +103,7 @@ public override DoAfterEvent Clone() } /// -/// Used to unlock a lockable entity that has an unlock time configured. +/// Used to unlock a lockable entity that has an unlock time configured. /// /// /// diff --git a/Content.Shared/Lock/LockSystem.cs b/Content.Shared/Lock/LockSystem.cs index b74f17b1525..bd533663876 100644 --- a/Content.Shared/Lock/LockSystem.cs +++ b/Content.Shared/Lock/LockSystem.cs @@ -54,7 +54,6 @@ private void OnStartup(EntityUid uid, LockComponent lockComp, ComponentStartup a private void OnActivated(EntityUid uid, LockComponent lockComp, ActivateInWorldEvent args) { - if (args.Handled) return; diff --git a/Content.Shared/Radio/Components/EncryptionKeyHolderComponent.cs b/Content.Shared/Radio/Components/EncryptionKeyHolderComponent.cs index 6c50acb9660..d84a1618602 100644 --- a/Content.Shared/Radio/Components/EncryptionKeyHolderComponent.cs +++ b/Content.Shared/Radio/Components/EncryptionKeyHolderComponent.cs @@ -15,27 +15,22 @@ public sealed partial class EncryptionKeyHolderComponent : Component /// /// Whether or not encryption keys can be removed from the headset. /// - [ViewVariables(VVAccess.ReadWrite)] - [DataField("keysUnlocked")] + [DataField] public bool KeysUnlocked = true; /// /// The tool required to extract the encryption keys from the headset. /// - [ViewVariables(VVAccess.ReadWrite)] - [DataField("keysExtractionMethod", customTypeSerializer: typeof(PrototypeIdSerializer))] + [DataField(customTypeSerializer: typeof(PrototypeIdSerializer))] public string KeysExtractionMethod = "Screwing"; - [ViewVariables(VVAccess.ReadWrite)] - [DataField("keySlots")] + [DataField] public int KeySlots = 2; - [ViewVariables(VVAccess.ReadWrite)] - [DataField("keyExtractionSound")] + [DataField] public SoundSpecifier KeyExtractionSound = new SoundPathSpecifier("/Audio/Items/pistol_magout.ogg"); - [ViewVariables(VVAccess.ReadWrite)] - [DataField("keyInsertionSound")] + [DataField] public SoundSpecifier KeyInsertionSound = new SoundPathSpecifier("/Audio/Items/pistol_magin.ogg"); [ViewVariables] @@ -45,8 +40,7 @@ public sealed partial class EncryptionKeyHolderComponent : Component /// /// Whether or not the headset can be examined to see the encryption keys while the keys aren't accessible. /// - [ViewVariables(VVAccess.ReadWrite)] - [DataField("examineWhileLocked")] + [DataField] public bool ExamineWhileLocked = true; /// diff --git a/Content.Shared/Radio/EntitySystems/EncryptionKeySystem.cs b/Content.Shared/Radio/EntitySystems/EncryptionKeySystem.cs index 712debbafa0..a15b6f76e90 100644 --- a/Content.Shared/Radio/EntitySystems/EncryptionKeySystem.cs +++ b/Content.Shared/Radio/EntitySystems/EncryptionKeySystem.cs @@ -6,10 +6,8 @@ using Content.Shared.Interaction; using Content.Shared.Popups; using Content.Shared.Radio.Components; -using Content.Shared.Tools; using Content.Shared.Tools.Components; using Content.Shared.Wires; -using Robust.Shared.Audio; using Robust.Shared.Audio.Systems; using Robust.Shared.Containers; using Robust.Shared.Network; @@ -175,13 +173,9 @@ private void OnStartup(EntityUid uid, EncryptionKeyHolderComponent component, Co private void OnHolderExamined(EntityUid uid, EncryptionKeyHolderComponent component, ExaminedEvent args) { - if (!args.IsInDetailsRange) - return; - - if (!component.ExamineWhileLocked && !component.KeysUnlocked) - return; - - if (!component.ExamineWhileLocked && TryComp(uid, out var panel) && !panel.Open) + if (!args.IsInDetailsRange + || !component.ExamineWhileLocked && !component.KeysUnlocked + || !component.ExamineWhileLocked && TryComp(uid, out var panel) && !panel.Open) return; if (component.KeyContainer.ContainedEntities.Count == 0) diff --git a/Content.Shared/Silicon/BatteryDrinkerEvent.cs b/Content.Shared/Silicon/BatteryDrinkerEvent.cs index 4d9a610055d..99af03df3a1 100644 --- a/Content.Shared/Silicon/BatteryDrinkerEvent.cs +++ b/Content.Shared/Silicon/BatteryDrinkerEvent.cs @@ -6,7 +6,5 @@ namespace Content.Shared.Silicon; [Serializable, NetSerializable] public sealed partial class BatteryDrinkerDoAfterEvent : SimpleDoAfterEvent { - public BatteryDrinkerDoAfterEvent() - { - } + public BatteryDrinkerDoAfterEvent() { } } diff --git a/Content.Shared/Silicon/BlindHealing/SharedBlindHealingSystem.cs b/Content.Shared/Silicon/BlindHealing/SharedBlindHealingSystem.cs index be4be9e5d38..bfc5092b644 100644 --- a/Content.Shared/Silicon/BlindHealing/SharedBlindHealingSystem.cs +++ b/Content.Shared/Silicon/BlindHealing/SharedBlindHealingSystem.cs @@ -6,8 +6,6 @@ namespace Content.Shared.Silicon.BlindHealing; public abstract partial class SharedBlindHealingSystem : EntitySystem { [Serializable, NetSerializable] - protected sealed partial class HealingDoAfterEvent : SimpleDoAfterEvent - { - } + protected sealed partial class HealingDoAfterEvent : SimpleDoAfterEvent { } } diff --git a/Content.Shared/Silicon/Components/SiliconComponent.cs b/Content.Shared/Silicon/Components/SiliconComponent.cs index c80d9397d93..bcee4d161a5 100644 --- a/Content.Shared/Silicon/Components/SiliconComponent.cs +++ b/Content.Shared/Silicon/Components/SiliconComponent.cs @@ -1,7 +1,6 @@ using Robust.Shared.GameStates; using Content.Shared.Silicon.Systems; using Robust.Shared.Serialization.TypeSerializers.Implementations; -using Robust.Shared.Containers; using Robust.Shared.Prototypes; using Content.Shared.Alert; @@ -36,7 +35,7 @@ public sealed partial class SiliconComponent : Component /// /// Is the Silicon currently dead? /// - public bool Dead = false; + public bool Dead; // BatterySystem took issue with how this was used, so I'm coming back to it at a later date, when more foundational Silicon stuff is implemented. // /// @@ -52,7 +51,7 @@ public sealed partial class SiliconComponent : Component /// Any new types of Silicons should be added to the enum. /// Setting this to Npc will delay charge state updates by LastDrainTime and skip battery heat calculations /// - [DataField("entityType", customTypeSerializer: typeof(EnumSerializer))] + [DataField(customTypeSerializer: typeof(EnumSerializer))] public Enum EntityType = SiliconType.Npc; /// @@ -61,13 +60,13 @@ public sealed partial class SiliconComponent : Component /// /// If true, should go along with a battery component. One will not be added automatically. /// - [DataField("batteryPowered"), ViewVariables(VVAccess.ReadWrite)] - public bool BatteryPowered = false; + [DataField] + public bool BatteryPowered; /// /// How much power is drained by this Silicon every second by default. /// - [DataField("drainPerSecond"), ViewVariables(VVAccess.ReadWrite)] + [DataField] public float DrainPerSecond = 50f; @@ -79,15 +78,15 @@ public sealed partial class SiliconComponent : Component /// Setting a value to null will disable that state. /// Setting Critical to 0 will cause the Silicon to never enter the dead state. /// - [DataField("chargeThresholdMid"), ViewVariables(VVAccess.ReadWrite)] + [DataField] public float? ChargeThresholdMid = 0.5f; /// - [DataField("chargeThresholdLow"), ViewVariables(VVAccess.ReadWrite)] + [DataField] public float? ChargeThresholdLow = 0.25f; /// - [DataField("chargeThresholdCritical"), ViewVariables(VVAccess.ReadWrite)] + [DataField] public float? ChargeThresholdCritical = 0.1f; [DataField] @@ -100,9 +99,16 @@ public sealed partial class SiliconComponent : Component /// /// The amount the Silicon will be slowed at each charge state. /// - [DataField("speedModifierThresholds", required: true)] - public Dictionary SpeedModifierThresholds = default!; + [DataField(required: true)] + public Dictionary SpeedModifierThresholds = default!; - [DataField("fireStackMultiplier"), ViewVariables(VVAccess.ReadWrite)] + [DataField] public float FireStackMultiplier = 1f; + + /// + /// Whether or not a Silicon will cancel all sleep events. + /// Maybe you want an android that can sleep as well as drink APCs? I'm not going to judge. + /// + [DataField] + public bool DoSiliconsDreamOfElectricSheep; } diff --git a/Content.Shared/Silicon/DeadStartupButton/DeadStartupButtonComponent.cs b/Content.Shared/Silicon/DeadStartupButton/DeadStartupButtonComponent.cs index 3390a76439b..9c2e5baf573 100644 --- a/Content.Shared/Silicon/DeadStartupButton/DeadStartupButtonComponent.cs +++ b/Content.Shared/Silicon/DeadStartupButton/DeadStartupButtonComponent.cs @@ -3,26 +3,26 @@ namespace Content.Shared.Silicon.DeadStartupButton; /// -/// This is used for... +/// This is used for Silicon entities such as IPCs, Cyborgs, Androids, anything "living" with a button people can touch. /// [RegisterComponent] public sealed partial class DeadStartupButtonComponent : Component { - [DataField("verbText")] + [DataField] public string VerbText = "dead-startup-button-verb"; - [DataField("sound")] + [DataField] public SoundSpecifier Sound = new SoundPathSpecifier("/Audio/Effects/Arcade/newgame.ogg"); - [DataField("buttonSound")] + [DataField] public SoundSpecifier ButtonSound = new SoundPathSpecifier("/Audio/Machines/button.ogg"); - [DataField("doAfterInterval"), ViewVariables(VVAccess.ReadWrite)] + [DataField] public float DoAfterInterval = 1f; - [DataField("buzzSound")] + [DataField] public SoundSpecifier BuzzSound = new SoundCollectionSpecifier("buzzes"); - [DataField("verbPriority"), ViewVariables(VVAccess.ReadWrite)] + [DataField] public int VerbPriority = 1; } diff --git a/Content.Shared/Silicon/DeadStartupButton/SharedDeadStartupButtonSystem.cs b/Content.Shared/Silicon/DeadStartupButton/SharedDeadStartupButtonSystem.cs index 2faa6dfde00..605ca48e6cb 100644 --- a/Content.Shared/Silicon/DeadStartupButton/SharedDeadStartupButtonSystem.cs +++ b/Content.Shared/Silicon/DeadStartupButton/SharedDeadStartupButtonSystem.cs @@ -1,5 +1,4 @@ using Content.Shared.DoAfter; -using Content.Shared.Mobs.Components; using Content.Shared.Mobs.Systems; using Content.Shared.Verbs; using Robust.Shared.Audio.Systems; @@ -10,19 +9,16 @@ namespace Content.Shared.Silicon.DeadStartupButton; /// -/// This creates a Button that can be activated after an entity, usually a silicon or an IPC, died. -/// This will activate a doAfter and then revive the entity, playing a custom afterward sound. +/// This creates a Button that can be activated after an entity, usually a silicon or an IPC, died. +/// This will activate a doAfter and then revive the entity, playing a custom afterward sound. /// -public partial class SharedDeadStartupButtonSystem : EntitySystem +public abstract partial class SharedDeadStartupButtonSystem : EntitySystem { [Dependency] private readonly MobStateSystem _mobState = default!; [Dependency] private readonly SharedAudioSystem _audio = default!; [Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!; [Dependency] private readonly INetManager _net = default!; - - - /// public override void Initialize() { @@ -31,10 +27,8 @@ public override void Initialize() private void AddTurnOnVerb(EntityUid uid, DeadStartupButtonComponent component, GetVerbsEvent args) { - if (!args.CanAccess || !args.CanInteract || args.Hands == null) - return; - - if (!TryComp(uid, out MobStateComponent? mobStateComponent) || !_mobState.IsDead(uid, mobStateComponent)) + if (!_mobState.IsDead(uid) + || !args.CanAccess || !args.CanInteract || args.Hands == null) return; args.Verbs.Add(new AlternativeVerb() @@ -50,6 +44,7 @@ private void TryStartup(EntityUid user, EntityUid target, DeadStartupButtonCompo { if (!_net.IsServer) return; + _audio.PlayPvs(comp.ButtonSound, target); var args = new DoAfterArgs(EntityManager, user, comp.DoAfterInterval, new OnDoAfterButtonPressedEvent(), target, target:target) { @@ -60,9 +55,5 @@ private void TryStartup(EntityUid user, EntityUid target, DeadStartupButtonCompo } [Serializable, NetSerializable] - public sealed partial class OnDoAfterButtonPressedEvent : SimpleDoAfterEvent - { - } - - + public sealed partial class OnDoAfterButtonPressedEvent : SimpleDoAfterEvent { } } diff --git a/Content.Shared/Silicon/EmitBuzzWhileDamaged/EmitBuzzWhileDamagedComponent.cs b/Content.Shared/Silicon/EmitBuzzWhileDamaged/EmitBuzzWhileDamagedComponent.cs index a8362610e25..986292551d0 100644 --- a/Content.Shared/Silicon/EmitBuzzWhileDamaged/EmitBuzzWhileDamagedComponent.cs +++ b/Content.Shared/Silicon/EmitBuzzWhileDamaged/EmitBuzzWhileDamagedComponent.cs @@ -1,26 +1,26 @@ -using System.ComponentModel.DataAnnotations; using Robust.Shared.Audio; namespace Content.Shared.Silicon.EmitBuzzWhileDamaged; /// -/// This is used for controlling the cadence of the buzzing emitted by EmitBuzzOnCritSystem. -/// This component is used by mechanical species that can get to critical health. +/// This is used for controlling the cadence of the buzzing emitted by EmitBuzzOnCritSystem. +/// This component is used by mechanical species that can get to critical health. /// [RegisterComponent] public sealed partial class EmitBuzzWhileDamagedComponent : Component { - [DataField("buzzPopupCooldown")] - public TimeSpan BuzzPopupCooldown { get; private set; } = TimeSpan.FromSeconds(8); + [DataField] + public TimeSpan BuzzPopupCooldown = TimeSpan.FromSeconds(8); [ViewVariables] public TimeSpan LastBuzzPopupTime; - [DataField("cycleDelay")] + [DataField] public float CycleDelay = 2.0f; + [ViewVariables] public float AccumulatedFrametime; - [DataField("sound")] + [DataField] public SoundSpecifier Sound = new SoundCollectionSpecifier("buzzes"); } diff --git a/Content.Shared/Silicon/Systems/SharedSiliconSystem.cs b/Content.Shared/Silicon/Systems/SharedSiliconSystem.cs index aab9b6e7522..8fe87e162bc 100644 --- a/Content.Shared/Silicon/Systems/SharedSiliconSystem.cs +++ b/Content.Shared/Silicon/Systems/SharedSiliconSystem.cs @@ -1,17 +1,17 @@ using Content.Shared.Silicon.Components; using Content.Shared.Alert; -using Robust.Shared.Serialization; -using Content.Shared.Movement.Systems; +using Content.Shared.Bed.Sleep; using Content.Shared.Containers.ItemSlots; +using Content.Shared.Movement.Systems; using Content.Shared.PowerCell.Components; +using Robust.Shared.Serialization; namespace Content.Shared.Silicon.Systems; - public sealed class SharedSiliconChargeSystem : EntitySystem { [Dependency] private readonly AlertsSystem _alertsSystem = default!; - [Dependency] protected readonly ItemSlotsSystem ItemSlots = default!; + [Dependency] private readonly ItemSlotsSystem _itemSlots = default!; public override void Initialize() { @@ -22,47 +22,50 @@ public override void Initialize() SubscribeLocalEvent(OnRefreshMovespeed); SubscribeLocalEvent(OnItemSlotInsertAttempt); SubscribeLocalEvent(OnItemSlotEjectAttempt); + SubscribeLocalEvent(OnTryingToSleep); } - private void OnItemSlotInsertAttempt(EntityUid uid, SiliconComponent component, ref ItemSlotInsertAttemptEvent args) + /// + /// Silicon entities can now also be Living player entities. We may want to prevent them from sleeping if they can't sleep. + /// + private void OnTryingToSleep(EntityUid uid, SiliconComponent component, ref TryingToSleepEvent args) { - if (args.Cancelled) - return; - - if (!TryComp(uid, out var cellSlotComp)) - return; + args.Cancelled = !component.DoSiliconsDreamOfElectricSheep; + } - if (!ItemSlots.TryGetSlot(uid, cellSlotComp.CellSlotId, out var cellSlot) || cellSlot != args.Slot) + private void OnItemSlotInsertAttempt(EntityUid uid, SiliconComponent component, ref ItemSlotInsertAttemptEvent args) + { + if (args.Cancelled + || !TryComp(uid, out var cellSlotComp) + || !_itemSlots.TryGetSlot(uid, cellSlotComp.CellSlotId, out var cellSlot) + || cellSlot != args.Slot || args.User != uid) return; - if (args.User == uid) - args.Cancelled = true; + args.Cancelled = true; } private void OnItemSlotEjectAttempt(EntityUid uid, SiliconComponent component, ref ItemSlotEjectAttemptEvent args) { - if (args.Cancelled) - return; - - if (!TryComp(uid, out var cellSlotComp)) - return; - - if (!ItemSlots.TryGetSlot(uid, cellSlotComp.CellSlotId, out var cellSlot) || cellSlot != args.Slot) + if (args.Cancelled + || !TryComp(uid, out var cellSlotComp) + || !_itemSlots.TryGetSlot(uid, cellSlotComp.CellSlotId, out var cellSlot) + || cellSlot != args.Slot || args.User != uid) return; - if (args.User == uid) - args.Cancelled = true; + args.Cancelled = true; } private void OnSiliconInit(EntityUid uid, SiliconComponent component, ComponentInit args) { - if (component.BatteryPowered) - _alertsSystem.ShowAlert(uid, AlertType.BorgBattery, component.ChargeState); + if (!component.BatteryPowered) + return; + + _alertsSystem.ShowAlert(uid, AlertType.BorgBattery, component.ChargeState); } private void OnSiliconChargeStateUpdate(EntityUid uid, SiliconComponent component, SiliconChargeStateUpdateEvent ev) { - _alertsSystem.ShowAlert(uid, AlertType.BorgBattery, (short) ev.ChargePercent); + _alertsSystem.ShowAlert(uid, AlertType.BorgBattery, ev.ChargePercent); } private void OnRefreshMovespeed(EntityUid uid, SiliconComponent component, RefreshMovementSpeedModifiersEvent args) @@ -70,17 +73,12 @@ private void OnRefreshMovespeed(EntityUid uid, SiliconComponent component, Refre if (!component.BatteryPowered) return; - var speedModThresholds = component.SpeedModifierThresholds; - - var closest = 0f; - - foreach (var state in speedModThresholds) - { - if (component.ChargeState >= state.Key && (float) state.Key > closest) - closest = (float) state.Key; - } + var closest = 0; + foreach (var state in component.SpeedModifierThresholds) + if (component.ChargeState >= state.Key && state.Key > closest) + closest = state.Key; - var speedMod = speedModThresholds[(short) closest]; + var speedMod = component.SpeedModifierThresholds[closest]; args.ModifySpeed(speedMod, speedMod); } diff --git a/Content.Shared/Station/SharedStationSpawningSystem.cs b/Content.Shared/Station/SharedStationSpawningSystem.cs index 56a8a846b07..9e933181034 100644 --- a/Content.Shared/Station/SharedStationSpawningSystem.cs +++ b/Content.Shared/Station/SharedStationSpawningSystem.cs @@ -49,7 +49,6 @@ public void EquipStartingGear(EntityUid entity, StartingGearPrototype? startingG var equipmentEntity = EntityManager.SpawnEntity(equipmentStr, EntityManager.GetComponent(entity).Coordinates); InventorySystem.TryEquip(entity, equipmentEntity, slot.Name, true, force:true); } - } if (TryComp(entity, out HandsComponent? handsComponent))