private void OnPumpInit(EntityUid uid, PumpBarrelComponent component, ComponentInit args) { component.AmmoContainer = uid.EnsureContainer <Container>($"{component.GetType()}-ammo-container", out var existing); if (existing) { foreach (var entity in component.AmmoContainer.ContainedEntities) { component.SpawnedAmmo.Push(entity); component.UnspawnedCount--; } } component.ChamberContainer = uid.EnsureContainer <ContainerSlot>($"{component.GetType()}-chamber-container", out existing); if (existing) { component.UnspawnedCount--; } if (TryComp(uid, out AppearanceComponent? appearanceComponent)) { appearanceComponent.SetData(MagazineBarrelVisuals.MagLoaded, true); } component.Dirty(EntityManager); UpdatePumpAppearance(component); }
private void CyclePump(PumpBarrelComponent component, bool manual = false) { if (component.ChamberContainer.ContainedEntity is { Valid: true } chamberedEntity) { component.ChamberContainer.Remove(chamberedEntity); var ammoComponent = EntityManager.GetComponent <AmmoComponent>(chamberedEntity); if (!ammoComponent.Caseless) { EjectCasing(chamberedEntity); } } if (component.SpawnedAmmo.TryPop(out var next)) { component.AmmoContainer.Remove(next); component.ChamberContainer.Insert(next); } if (component.UnspawnedCount > 0) { component.UnspawnedCount--; var ammoEntity = EntityManager.SpawnEntity(component.FillPrototype, Transform(component.Owner).Coordinates); component.ChamberContainer.Insert(ammoEntity); } if (manual) { SoundSystem.Play(Filter.Pvs(component.Owner), component.SoundCycle.GetSound(), component.Owner, AudioParams.Default.WithVolume(-2)); } component.Dirty(EntityManager); UpdatePumpAppearance(component); }
public bool TryInsertBullet(PumpBarrelComponent component, InteractUsingEvent args) { if (!TryComp(args.Used, out AmmoComponent? ammoComponent)) { return(false); } if (ammoComponent.Caliber != component.Caliber) { _popup.PopupEntity(Loc.GetString("pump-barrel-component-try-insert-bullet-wrong-caliber"), component.Owner, Filter.Entities(args.User)); return(false); } if (component.AmmoContainer.ContainedEntities.Count < component.Capacity - 1) { component.AmmoContainer.Insert(args.Used); component.SpawnedAmmo.Push(args.Used); component.Dirty(EntityManager); UpdatePumpAppearance(component); SoundSystem.Play(Filter.Pvs(component.Owner), component.SoundInsert.GetSound(), component.Owner, AudioParams.Default.WithVolume(-2)); return(true); } _popup.PopupEntity(Loc.GetString("pump-barrel-component-try-insert-bullet-no-room"), component.Owner, Filter.Entities(args.User)); return(false); }
public EntityUid?TakeProjectile(PumpBarrelComponent component, EntityCoordinates spawnAt) { if (!component.ManualCycle) { CyclePump(component); } else { component.Dirty(EntityManager); } if (component.ChamberContainer.ContainedEntity is not { Valid: true } chamberEntity) { return(null); } var ammoComponent = EntityManager.GetComponentOrNull <AmmoComponent>(chamberEntity); return(ammoComponent == null ? null : TakeBullet(ammoComponent, spawnAt)); }