using Content.Shared.Hands.Components;
using Content.Shared.Internals;
using Content.Shared.Inventory;
+using Content.Shared.Roles;
using Content.Shared.Verbs;
using Robust.Shared.Containers;
using Robust.Shared.Utility;
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
- public const SlotFlags InventorySlots = SlotFlags.POCKET | SlotFlags.BELT;
+ private EntityQuery<InternalsComponent> _internalsQuery;
public override void Initialize()
{
base.Initialize();
+ _internalsQuery = GetEntityQuery<InternalsComponent>();
+
SubscribeLocalEvent<InternalsComponent, InhaleLocationEvent>(OnInhaleLocation);
SubscribeLocalEvent<InternalsComponent, ComponentStartup>(OnInternalsStartup);
SubscribeLocalEvent<InternalsComponent, ComponentShutdown>(OnInternalsShutdown);
SubscribeLocalEvent<InternalsComponent, GetVerbsEvent<InteractionVerb>>(OnGetInteractionVerbs);
SubscribeLocalEvent<InternalsComponent, InternalsDoAfterEvent>(OnDoAfter);
+
+ SubscribeLocalEvent<StartingGearEquippedEvent>(OnStartingGear);
+ }
+
+ private void OnStartingGear(ref StartingGearEquippedEvent ev)
+ {
+ if (!_internalsQuery.TryComp(ev.Entity, out var internals) || internals.BreathToolEntity == null)
+ return;
+
+ ToggleInternals(ev.Entity, ev.Entity, force: false, internals);
}
private void OnGetInteractionVerbs(
if (component.BreathToolEntity is null || !AreInternalsWorking(component))
return 2;
- // If pressure in the tank is below low pressure threshhold, flash warning on internals UI
+ // If pressure in the tank is below low pressure threshold, flash warning on internals UI
if (TryComp<GasTankComponent>(component.GasTankEntity, out var gasTank)
&& gasTank.IsLowPressure)
{
/// <inheritdoc/>
public override void Initialize()
{
+ base.Initialize();
Subs.CVar(_configurationManager, CCVars.ICRandomCharacters, e => _randomizeCharacters = e, true);
_spawnerCallbacks = new Dictionary<SpawnPriorityPreference, Action<PlayerSpawningEvent>>()
if (prototype?.StartingGear != null)
{
var startingGear = _prototypeManager.Index<StartingGearPrototype>(prototype.StartingGear);
- EquipStartingGear(entity.Value, startingGear);
+ EquipStartingGear(entity.Value, startingGear, raiseEvent: false);
}
// Run loadouts after so stuff like storage loadouts can get
}
// Handle any extra data here.
- EquipStartingGear(entity.Value, startingGear);
+ EquipStartingGear(entity.Value, startingGear, raiseEvent: false);
}
}
}
+ var gearEquippedEv = new StartingGearEquippedEvent(entity.Value);
+ RaiseLocalEvent(entity.Value, ref gearEquippedEv, true);
+
if (profile != null)
{
if (prototype != null)
[Dependency] private readonly SharedStorageSystem _storage = default!;
[Dependency] private readonly SharedTransformSystem _xformSystem = default!;
+ private EntityQuery<HandsComponent> _handsQuery;
+ private EntityQuery<InventoryComponent> _inventoryQuery;
+ private EntityQuery<StorageComponent> _storageQuery;
+ private EntityQuery<TransformComponent> _xformQuery;
+
+ public override void Initialize()
+ {
+ base.Initialize();
+ _handsQuery = GetEntityQuery<HandsComponent>();
+ _inventoryQuery = GetEntityQuery<InventoryComponent>();
+ _storageQuery = GetEntityQuery<StorageComponent>();
+ _xformQuery = GetEntityQuery<TransformComponent>();
+ }
+
/// <summary>
- /// Equips starting gear onto the given entity.
+ /// <see cref="EquipStartingGear(Robust.Shared.GameObjects.EntityUid,System.Nullable{Robust.Shared.Prototypes.ProtoId{Content.Shared.Roles.StartingGearPrototype}},bool)"/>
/// </summary>
- /// <param name="entity">Entity to load out.</param>
- /// <param name="startingGear">Starting gear to use.</param>
- public void EquipStartingGear(EntityUid entity, ProtoId<StartingGearPrototype>? startingGear)
+ public void EquipStartingGear(EntityUid entity, ProtoId<StartingGearPrototype>? startingGear, bool raiseEvent = true)
{
PrototypeManager.TryIndex(startingGear, out var gearProto);
EquipStartingGear(entity, gearProto);
/// </summary>
/// <param name="entity">Entity to load out.</param>
/// <param name="startingGear">Starting gear to use.</param>
- public void EquipStartingGear(EntityUid entity, StartingGearPrototype? startingGear)
+ /// <param name="raiseEvent">Should we raise the event for equipped. Set to false if you will call this manually</param>
+ public void EquipStartingGear(EntityUid entity, StartingGearPrototype? startingGear, bool raiseEvent = true)
{
if (startingGear == null)
return;
+ var xform = _xformQuery.GetComponent(entity);
+
if (InventorySystem.TryGetSlots(entity, out var slotDefinitions))
{
foreach (var slot in slotDefinitions)
var equipmentStr = startingGear.GetGear(slot.Name);
if (!string.IsNullOrEmpty(equipmentStr))
{
- var equipmentEntity = EntityManager.SpawnEntity(equipmentStr, EntityManager.GetComponent<TransformComponent>(entity).Coordinates);
+ var equipmentEntity = EntityManager.SpawnEntity(equipmentStr, xform.Coordinates);
InventorySystem.TryEquip(entity, equipmentEntity, slot.Name, silent: true, force:true);
}
}
}
- if (TryComp(entity, out HandsComponent? handsComponent))
+ if (_handsQuery.TryComp(entity, out var handsComponent))
{
var inhand = startingGear.Inhand;
- var coords = EntityManager.GetComponent<TransformComponent>(entity).Coordinates;
+ var coords = xform.Coordinates;
foreach (var prototype in inhand)
{
var inhandEntity = EntityManager.SpawnEntity(prototype, coords);
{
var coords = _xformSystem.GetMapCoordinates(entity);
var ents = new ValueList<EntityUid>();
- TryComp(entity, out InventoryComponent? inventoryComp);
+ _inventoryQuery.TryComp(entity, out var inventoryComp);
foreach (var (slot, entProtos) in startingGear.Storage)
{
if (inventoryComp != null &&
InventorySystem.TryGetSlotEntity(entity, slot, out var slotEnt, inventoryComponent: inventoryComp) &&
- TryComp(slotEnt, out StorageComponent? storage))
+ _storageQuery.TryComp(slotEnt, out var storage))
{
foreach (var ent in ents)
{
}
}
}
+
+ if (raiseEvent)
+ {
+ var ev = new StartingGearEquippedEvent(entity);
+ RaiseLocalEvent(entity, ref ev, true);
+ }
}
}