using Content.Shared._EE.Silicon.Components; using Content.Shared.Alert; using Content.Shared.Bed.Sleep; using Robust.Shared.Serialization; using Content.Shared.Movement.Systems; using Content.Shared.Containers.ItemSlots; using Content.Shared.PowerCell.Components; namespace Content.Shared._EE.Silicon.Systems; public abstract class SharedSiliconChargeSystem : EntitySystem // DeltaV - Make class abstract to split into Client/Server { // [Dependency] private readonly AlertsSystem _alertsSystem = default!; // DeltaV - Moved alert handling to Client [Dependency] private readonly ItemSlotsSystem _itemSlots = default!; public override void Initialize() { base.Initialize(); // Begin DeltaV - Moved alert handling to Client // SubscribeLocalEvent(OnSiliconInit); // SubscribeLocalEvent(OnSiliconChargeStateUpdate); // End DeltaV - Moved alert handling to Client SubscribeLocalEvent(OnRefreshMovespeed); SubscribeLocalEvent(OnItemSlotInsertAttempt); SubscribeLocalEvent(OnItemSlotEjectAttempt); SubscribeLocalEvent(OnTryingToSleep); } 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; args.Cancelled = true; } private void OnItemSlotEjectAttempt(EntityUid uid, SiliconComponent component, ref ItemSlotEjectAttemptEvent args) { if (args.Cancelled || !TryComp(uid, out var cellSlotComp) || !_itemSlots.TryGetSlot(uid, cellSlotComp.CellSlotId, out var cellSlot) || cellSlot != args.Slot || args.User != uid) return; args.Cancelled = true; } // Begin DeltaV - Moved alert handling to Client // private void OnSiliconInit(EntityUid uid, SiliconComponent component, ComponentInit args) // { // if (!component.BatteryPowered) // return; // _alertsSystem.ShowAlert(uid, component.BatteryAlert, component.ChargeState); // } // private void OnSiliconChargeStateUpdate(EntityUid uid, SiliconComponent component, SiliconChargeStateUpdateEvent ev) // { // _alertsSystem.ShowAlert(uid, component.BatteryAlert, ev.ChargePercent); // } // End DeltaV - Moved alert handling to Client private void OnRefreshMovespeed(EntityUid uid, SiliconComponent component, RefreshMovementSpeedModifiersEvent args) { if (!component.BatteryPowered) return; var closest = 0; foreach (var state in component.SpeedModifierThresholds) if (component.ChargeState >= state.Key && state.Key > closest) closest = state.Key; var speedMod = component.SpeedModifierThresholds[closest]; args.ModifySpeed(speedMod, speedMod); } /// /// 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) { args.Cancelled = !component.DoSiliconsDreamOfElectricSheep; } } public enum SiliconType { Player, GhostRole, Npc, } /// /// Event raised when a Silicon's charge state needs to be updated. /// [Serializable, NetSerializable] public sealed class SiliconChargeStateUpdateEvent : EntityEventArgs { public short ChargePercent { get; } public SiliconChargeStateUpdateEvent(short chargePercent) { ChargePercent = chargePercent; } }