using Content.Shared.Explosion.Components; using Content.Shared.Interaction; using Content.Shared.Whitelist; using Robust.Shared.Containers; namespace Content.Shared.Explosion.EntitySystems; public abstract class SharedScatteringGrenadeSystem : EntitySystem { [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!; [Dependency] private readonly SharedAppearanceSystem _appearance = default!; [Dependency] private readonly SharedContainerSystem _container = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnScatteringInit); SubscribeLocalEvent(OnScatteringStartup); SubscribeLocalEvent(OnScatteringInteractUsing); } private void OnScatteringInit(Entity entity, ref ComponentInit args) { entity.Comp.Container = _container.EnsureContainer(entity.Owner, "cluster-payload"); } /// /// Setting the unspawned count based on capacity, so we know how many new entities to spawn /// Update appearance based on initial fill amount /// private void OnScatteringStartup(Entity entity, ref ComponentStartup args) { if (entity.Comp.FillPrototype == null) return; entity.Comp.UnspawnedCount = Math.Max(0, entity.Comp.Capacity - entity.Comp.Container.ContainedEntities.Count); UpdateAppearance(entity); Dirty(entity, entity.Comp); } /// /// There are some scattergrenades you can fill up with more grenades (like clusterbangs) /// This covers how you insert more into it /// private void OnScatteringInteractUsing(Entity entity, ref InteractUsingEvent args) { if (entity.Comp.Whitelist == null) return; // Make sure there's room for another grenade to be added if (entity.Comp.Count >= entity.Comp.Capacity) return; if (args.Handled || !_whitelistSystem.IsValid(entity.Comp.Whitelist, args.Used)) return; _container.Insert(args.Used, entity.Comp.Container); UpdateAppearance(entity); args.Handled = true; } /// /// Update appearance based off of total count of contents /// private void UpdateAppearance(Entity entity) { if (!TryComp(entity, out var appearanceComponent)) return; _appearance.SetData(entity, ClusterGrenadeVisuals.GrenadesCounter, entity.Comp.Count, appearanceComponent); } }