private void OnUseInHand(EntityUid uid, SpawnItemsOnUseComponent component, UseInHandEvent args) { if (args.Handled) { return; } var coords = Transform(args.User).Coordinates; var spawnEntities = EntitySpawnCollection.GetSpawns(component.Items, _random); EntityUid?entityToPlaceInHands = null; foreach (var proto in spawnEntities) { entityToPlaceInHands = Spawn(proto, coords); } if (component.Sound != null) { SoundSystem.Play(component.Sound.GetSound(), Filter.Pvs(uid), uid); } component.Uses--; if (component.Uses == 0) { args.Handled = true; EntityManager.DeleteEntity(uid); } if (entityToPlaceInHands != null) { _handsSystem.PickupOrDrop(args.User, entityToPlaceInHands.Value); } }
private void OnUseInHand(EntityUid uid, SpawnItemsOnUseComponent component, UseInHandEvent args) { if (args.Handled) { return; } var owner = EntityManager.GetEntity(uid); var alreadySpawnedGroups = new List <string>(); IEntity?entityToPlaceInHands = null; foreach (var storageItem in component.Items) { if (!string.IsNullOrEmpty(storageItem.GroupId) && alreadySpawnedGroups.Contains(storageItem.GroupId)) { continue; } if (storageItem.SpawnProbability != 1f && !_random.Prob(storageItem.SpawnProbability)) { continue; } for (var i = 0; i < storageItem.Amount; i++) { entityToPlaceInHands = EntityManager.SpawnEntity(storageItem.PrototypeId, args.User.Transform.Coordinates); } if (!string.IsNullOrEmpty(storageItem.GroupId)) { alreadySpawnedGroups.Add(storageItem.GroupId); } } if (component.Sound != null) { SoundSystem.Play(Filter.Pvs(owner), component.Sound.GetSound()); } component.Uses--; if (component.Uses == 0) { args.Handled = true; owner.Delete(); } if (entityToPlaceInHands != null && args.User.TryGetComponent <SharedHandsComponent>(out var hands)) { hands.TryPutInAnyHand(entityToPlaceInHands); } }
private void OnUseInHand(EntityUid uid, SpawnItemsOnUseComponent component, UseInHandEvent args) { if (args.Handled) { return; } var alreadySpawnedGroups = new List <string>(); EntityUid?entityToPlaceInHands = null; foreach (var storageItem in component.Items) { if (!string.IsNullOrEmpty(storageItem.GroupId) && alreadySpawnedGroups.Contains(storageItem.GroupId)) { continue; } if (storageItem.SpawnProbability != 1f && !_random.Prob(storageItem.SpawnProbability)) { continue; } for (var i = 0; i < storageItem.Amount; i++) { entityToPlaceInHands = EntityManager.SpawnEntity(storageItem.PrototypeId, EntityManager.GetComponent <TransformComponent>(args.User).Coordinates); } if (!string.IsNullOrEmpty(storageItem.GroupId)) { alreadySpawnedGroups.Add(storageItem.GroupId); } } if (component.Sound != null) { SoundSystem.Play(Filter.Pvs(uid), component.Sound.GetSound(), uid); } component.Uses--; if (component.Uses == 0) { args.Handled = true; EntityManager.DeleteEntity(uid); } if (entityToPlaceInHands != null) { _handsSystem.PickupOrDrop(args.User, entityToPlaceInHands.Value); } }