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); } }
public bool TryLayEgg(EntityUid uid, EggLayerComponent?component) { if (!Resolve(uid, ref component)) { return(false); } // Allow infinitely laying eggs if they can't get hungry if (TryComp <HungerComponent>(uid, out var hunger)) { if (hunger.CurrentHunger < component.HungerUsage) { _popup.PopupEntity(Loc.GetString("action-popup-lay-egg-too-hungry"), uid, Filter.Entities(uid)); return(false); } hunger.CurrentHunger -= component.HungerUsage; } foreach (var ent in EntitySpawnCollection.GetSpawns(component.EggSpawn, _random)) { Spawn(ent, Transform(uid).Coordinates); } // Sound + popups SoundSystem.Play(component.EggLaySound.GetSound(), Filter.Pvs(uid), uid, component.EggLaySound.Params); _popup.PopupEntity(Loc.GetString("action-popup-lay-egg-user"), uid, Filter.Entities(uid)); _popup.PopupEntity(Loc.GetString("action-popup-lay-egg-others", ("entity", uid)), uid, Filter.PvsExcept(uid)); return(true); }
private void Spike(EntityUid uid, EntityUid userUid, EntityUid victimUid, KitchenSpikeComponent?component = null, SharedButcherableComponent?butcherable = null) { if (!Resolve(uid, ref component) || !Resolve(victimUid, ref butcherable)) { return; } // TODO VERY SUS component.PrototypesToSpawn = EntitySpawnCollection.GetSpawns(butcherable.SpawnedEntities, _random); // This feels not okay, but entity is getting deleted on "Spike", for now... component.MeatSource1p = Loc.GetString("comp-kitchen-spike-remove-meat", ("victim", victimUid)); component.MeatSource0 = Loc.GetString("comp-kitchen-spike-remove-meat-last", ("victim", victimUid)); component.Victim = Name(victimUid); UpdateAppearance(uid, null, component); _popupSystem.PopupEntity(Loc.GetString("comp-kitchen-spike-kill", ("user", userUid), ("victim", victimUid)), uid, Filter.Pvs(userUid)); // THE WHAT? // TODO: Need to be able to leave them on the spike to do DoT, see ss13. EntityManager.QueueDeleteEntity(victimUid); SoundSystem.Play(component.SpikeSound.GetSound(), Filter.Pvs(uid), uid); }
private void OnStorageFillMapInit(EntityUid uid, StorageFillComponent component, MapInitEvent args) { if (component.Contents.Count == 0) { return; } if (!EntityManager.EntitySysManager.TryGetEntitySystem <EntityStorageSystem>(out var entityStorage)) { return; } TryComp <ServerStorageComponent>(uid, out var serverStorageComp); TryComp <EntityStorageComponent>(uid, out var entityStorageComp); if (entityStorageComp == null && serverStorageComp == null) { Logger.Error($"StorageFillComponent couldn't find any StorageComponent ({uid})"); return; } var coordinates = Transform(uid).Coordinates; var spawnItems = EntitySpawnCollection.GetSpawns(component.Contents, _random); foreach (var item in spawnItems) { var ent = EntityManager.SpawnEntity(item, coordinates); // handle depending on storage component, again this should be unified after ECS if (entityStorageComp != null && entityStorage.Insert(ent, uid)) { continue; } if (serverStorageComp != null && Insert(uid, ent, serverStorageComp)) { continue; } Logger.ErrorS("storage", $"Tried to StorageFill {item} inside {ToPrettyString(uid)} but can't."); EntityManager.DeleteEntity(ent); } }
/// <summary> /// Loops through a supplied list of entity prototypes and spawns them /// </summary> /// <remarks> /// If an offset of 0, 0 is supplied then the entities will all spawn on the same tile. /// Any other offset will spawn entities starting from the source Map Coordinates and will increment the supplied /// offset /// </remarks> /// <param name="entityEntries"> The list of Entities to spawn in</param> /// <param name="mapCoords"> Map Coordinates where the entities will spawn</param> /// <param name="lifetime"> Check to see if the entities should self delete</param> /// <param name="offsetVector2"> A Vector2 offset that the entities will spawn in</param> private void SpawnSpellHelper(List <EntitySpawnEntry> entityEntries, MapCoordinates mapCoords, float?lifetime, Vector2 offsetVector2) { var getProtos = EntitySpawnCollection.GetSpawns(entityEntries, _random); var offsetCoords = mapCoords; foreach (var proto in getProtos) { // TODO: Share this code with instant because they're both doing similar things for positioning. var entity = Spawn(proto, offsetCoords); offsetCoords = offsetCoords.Offset(offsetVector2); if (lifetime != null) { var comp = EnsureComp <TimedDespawnComponent>(entity); comp.Lifetime = lifetime.Value; } } }
private void OnMindAdded(EntityUid uid, DroneComponent drone, MindAddedMessage args) { UpdateDroneAppearance(uid, DroneStatus.On); _popupSystem.PopupEntity(Loc.GetString("drone-activated"), uid, Filter.Pvs(uid), PopupType.Large); if (drone.AlreadyAwoken == false) { var spawnCoord = Transform(uid).Coordinates; if (drone.Tools.Count == 0) { return; } if (TryComp <HandsComponent>(uid, out var hands) && hands.Count >= drone.Tools.Count) { var items = EntitySpawnCollection.GetSpawns(drone.Tools, _robustRandom); foreach (var entry in items) { var item = Spawn(entry, spawnCoord); AddComp <UnremoveableComponent>(item); if (!_handsSystem.TryPickupAnyHand(uid, item, checkActionBlocker: false)) { QueueDel(item); Logger.Error($"Drone ({ToPrettyString(uid)}) failed to pick up innate item ({ToPrettyString(item)})"); continue; } drone.ToolUids.Add(item); } } if (TryComp <ActionsComponent>(uid, out var actions) && TryComp <UnpoweredFlashlightComponent>(uid, out var flashlight)) { _actionsSystem.AddAction(uid, flashlight.ToggleAction, null, actions); } drone.AlreadyAwoken = true; } }
/// <inheritdoc cref="EntitySpawnCollection.GetSpawns"/> public List <string> GetSpawns(IRobustRandom?random = null) { return(EntitySpawnCollection.GetSpawns(Entries, random)); }