Unhardcode some logic related to objects with battery slots. Minor fix to fire helmets. (#11734)
This commit is contained in:
@@ -92,7 +92,10 @@ internal sealed class ChargerSystem : EntitySystem
|
||||
if (!TryComp(args.EntityUid, out PowerCellSlotComponent? cellSlot))
|
||||
return;
|
||||
|
||||
if (!cellSlot.FitsInCharger || !cellSlot.CellSlot.HasItem)
|
||||
if (!_itemSlotsSystem.TryGetSlotById(args.EntityUid, cellSlot.CellSlotId, out ItemSlot? itemSlot))
|
||||
return;
|
||||
|
||||
if (!cellSlot.FitsInCharger || !itemSlot.HasItem)
|
||||
args.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ using Content.Shared.Rounding;
|
||||
using Robust.Shared.Containers;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Server.Kitchen.Components;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
|
||||
namespace Content.Server.PowerCell;
|
||||
|
||||
@@ -19,6 +20,8 @@ public sealed class PowerCellSystem : SharedPowerCellSystem
|
||||
[Dependency] private readonly ExplosionSystem _explosionSystem = default!;
|
||||
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
|
||||
[Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _sharedAppearanceSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -36,10 +39,13 @@ public sealed class PowerCellSystem : SharedPowerCellSystem
|
||||
|
||||
private void OnSlotMicrowaved(EntityUid uid, PowerCellSlotComponent component, BeingMicrowavedEvent args)
|
||||
{
|
||||
if (component.CellSlot.Item == null)
|
||||
if (_itemSlotsSystem.TryGetSlotById(uid, component.CellSlotId, out ItemSlot? slot))
|
||||
{
|
||||
if (slot.Item == null)
|
||||
return;
|
||||
|
||||
RaiseLocalEvent(component.CellSlot.Item.Value, args, false);
|
||||
RaiseLocalEvent(slot.Item.Value, args, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMicrowaved(EntityUid uid, BatteryComponent component, BeingMicrowavedEvent args)
|
||||
@@ -69,13 +75,14 @@ public sealed class PowerCellSystem : SharedPowerCellSystem
|
||||
|
||||
var frac = battery.CurrentCharge / battery.MaxCharge;
|
||||
var level = (byte) ContentHelpers.RoundToNearestLevels(frac, 1, PowerCellComponent.PowerCellVisualsLevels);
|
||||
appearance.SetData(PowerCellVisuals.ChargeLevel, level);
|
||||
_sharedAppearanceSystem.SetData(uid, PowerCellVisuals.ChargeLevel, level, appearance);
|
||||
|
||||
// If this power cell is inside a cell-slot, inform that entity that the power has changed (for updating visuals n such).
|
||||
if (_containerSystem.TryGetContainingContainer(uid, out var container)
|
||||
&& TryComp(container.Owner, out PowerCellSlotComponent? slot)
|
||||
&& slot.CellSlot.Item == uid)
|
||||
&& _itemSlotsSystem.TryGetSlotById(container.Owner, slot.CellSlotId, out ItemSlot? itemSlot))
|
||||
{
|
||||
if (itemSlot.Item == uid)
|
||||
RaiseLocalEvent(container.Owner, new PowerCellChangedEvent(false), false);
|
||||
}
|
||||
}
|
||||
@@ -101,7 +108,13 @@ public sealed class PowerCellSystem : SharedPowerCellSystem
|
||||
return false;
|
||||
}
|
||||
|
||||
return TryComp(component.CellSlot.Item, out battery);
|
||||
if (_itemSlotsSystem.TryGetSlotById(uid, component.CellSlotId, out ItemSlot? slot))
|
||||
{
|
||||
return TryComp(slot.Item, out battery);
|
||||
}
|
||||
|
||||
battery = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
private void OnSolutionChange(EntityUid uid, PowerCellComponent component, SolutionChangedEvent args)
|
||||
|
||||
@@ -125,6 +125,16 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
else
|
||||
Dirty(itemSlots);
|
||||
}
|
||||
|
||||
public bool TryGetSlotById(EntityUid uid, string slotId, [NotNullWhen(true)] out ItemSlot? itemSlot, ItemSlotsComponent? component = null)
|
||||
{
|
||||
itemSlot = null;
|
||||
|
||||
if (!Resolve(uid, ref component))
|
||||
return false;
|
||||
|
||||
return component.Slots.TryGetValue(slotId, out itemSlot);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Interactions
|
||||
|
||||
@@ -12,37 +12,8 @@ public sealed class PowerCellSlotComponent : Component
|
||||
/// Given that <see cref="PowerCellSystem"/> needs to verify that a given cell has the correct cell-size before
|
||||
/// inserting anyways, there is no need to specify a separate entity whitelist. In this slot's yaml definition.
|
||||
/// </remarks>
|
||||
[DataField("cellSlot")]
|
||||
public ItemSlot CellSlot = new();
|
||||
|
||||
/// <summary>
|
||||
/// Name of the item-slot used to store cells. Determines the eject/insert verb text. E.g., "Eject > Power cell".
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is simply used provide a default value for <see cref="CellSlot.Name"/>. If this string is empty or
|
||||
/// whitespace, the verb will instead use the full name of any cell (e.g., "eject > small super-capacity power
|
||||
/// cell").
|
||||
/// </remarks>
|
||||
[DataField("slotName")]
|
||||
public readonly string SlotName = "power-cell-slot-component-slot-name-default"; // gets Loc.GetString()-ed by ItemSlotsSystem
|
||||
|
||||
/// <summary>
|
||||
/// True if we don't want a cell inserted during map init. If a starting item is defined
|
||||
/// in the <see cref="CellSlot"/> yaml definition, that always takes precedence.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If false, the cell will start with a standard cell with a matching cell-size.
|
||||
/// </remarks>
|
||||
[DataField("startEmpty")]
|
||||
public bool StartEmpty = false;
|
||||
|
||||
/// <summary>
|
||||
/// Descriptive text to add to add when examining an entity with a cell slot. If empty or whitespace, will not add
|
||||
/// any text.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("descFormatString")]
|
||||
public string? DescFormatString { get; set; } = "power-cell-slot-component-description-default";
|
||||
[DataField("cellSlotId", required: true)]
|
||||
public string CellSlotId = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Can this entity be inserted directly into a charging station? If false, you need to manually remove the power
|
||||
@@ -50,6 +21,7 @@ public sealed class PowerCellSlotComponent : Component
|
||||
/// </summary>
|
||||
[DataField("fitsInCharger")]
|
||||
public bool FitsInCharger = true;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.PowerCell.Components;
|
||||
using Robust.Shared.Containers;
|
||||
|
||||
@@ -7,17 +5,9 @@ namespace Content.Shared.PowerCell;
|
||||
|
||||
public abstract class SharedPowerCellSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!;
|
||||
|
||||
public const string CellSlotContainer = "cell_slot";
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<PowerCellSlotComponent, ComponentInit>(OnCellSlotInit);
|
||||
SubscribeLocalEvent<PowerCellSlotComponent, ComponentRemove>(OnCellSlotRemove);
|
||||
|
||||
SubscribeLocalEvent<PowerCellSlotComponent, EntInsertedIntoContainerMessage>(OnCellInserted);
|
||||
SubscribeLocalEvent<PowerCellSlotComponent, EntRemovedFromContainerMessage>(OnCellRemoved);
|
||||
SubscribeLocalEvent<PowerCellSlotComponent, ContainerIsInsertingAttemptEvent>(OnCellInsertAttempt);
|
||||
@@ -28,7 +18,7 @@ public abstract class SharedPowerCellSystem : EntitySystem
|
||||
if (!component.Initialized)
|
||||
return;
|
||||
|
||||
if (args.Container.ID != component.CellSlot.ID)
|
||||
if (args.Container.ID != component.CellSlotId)
|
||||
return;
|
||||
|
||||
if (!HasComp<PowerCellComponent>(args.EntityUid))
|
||||
@@ -42,7 +32,7 @@ public abstract class SharedPowerCellSystem : EntitySystem
|
||||
if (!component.Initialized)
|
||||
return;
|
||||
|
||||
if (args.Container.ID != component.CellSlot.ID)
|
||||
if (args.Container.ID != component.CellSlotId)
|
||||
return;
|
||||
|
||||
RaiseLocalEvent(uid, new PowerCellChangedEvent(false), false);
|
||||
@@ -50,25 +40,9 @@ public abstract class SharedPowerCellSystem : EntitySystem
|
||||
|
||||
private void OnCellRemoved(EntityUid uid, PowerCellSlotComponent component, EntRemovedFromContainerMessage args)
|
||||
{
|
||||
if (args.Container.ID != component.CellSlot.ID)
|
||||
if (args.Container.ID != component.CellSlotId)
|
||||
return;
|
||||
|
||||
RaiseLocalEvent(uid, new PowerCellChangedEvent(true), false);
|
||||
}
|
||||
|
||||
private void OnCellSlotInit(EntityUid uid, PowerCellSlotComponent component, ComponentInit args)
|
||||
{
|
||||
_itemSlotsSystem.AddItemSlot(uid, CellSlotContainer, component.CellSlot);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(component.CellSlot.Name) &&
|
||||
!string.IsNullOrWhiteSpace(component.SlotName))
|
||||
{
|
||||
component.CellSlot.Name = component.SlotName;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCellSlotRemove(EntityUid uid, PowerCellSlotComponent component, ComponentRemove args)
|
||||
{
|
||||
_itemSlotsSystem.RemoveItemSlot(uid, component.CellSlot);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,2 @@
|
||||
# Default examine descriptions
|
||||
power-cell-slot-component-description-default = It uses {$size} power cells.
|
||||
power-cell-slot-component-description-size-small = small
|
||||
power-cell-slot-component-description-size-medium = medium-sized
|
||||
power-cell-slot-component-description-size-large = large
|
||||
|
||||
# Verbs
|
||||
power-cell-slot-component-slot-name-default = Power cell
|
||||
|
||||
@@ -58,12 +58,16 @@
|
||||
- type: FlashLightVisualizer
|
||||
- type: HandheldLight
|
||||
addPrefix: true
|
||||
- type: Battery
|
||||
maxCharge: 600 #lights drain 3/s but recharge of 2 makes this 1/s. Therefore 600 is 10 minutes of light.
|
||||
startingCharge: 600
|
||||
- type: BatterySelfRecharger
|
||||
autoRecharge: true
|
||||
autoRechargeRate: 2 #recharge of 2 makes total drain 1w / s so max charge is 1:1 with time. Time to fully charge should be 5 minutes. Having recharge gives light an extended flicker period which gives you some warning to return to light area.
|
||||
- type: PowerCellSlot
|
||||
cellSlotId: cell_slot
|
||||
- type: ItemSlots
|
||||
slots:
|
||||
cell_slot:
|
||||
name: power-cell-slot-component-slot-name-default
|
||||
startingItem: PowerCellMedium
|
||||
- type: ContainerContainer
|
||||
containers:
|
||||
cell_slot: !type:ContainerSlot {}
|
||||
|
||||
- type: entity
|
||||
abstract: true
|
||||
|
||||
@@ -35,14 +35,17 @@
|
||||
head:
|
||||
- state: on-equipped-HELMET
|
||||
- type: PowerCellSlot
|
||||
cellSlot:
|
||||
cellSlotId: cell_slot
|
||||
- type: ItemSlots
|
||||
slots:
|
||||
cell_slot:
|
||||
name: power-cell-slot-component-slot-name-default
|
||||
startingItem: PowerCellMedium
|
||||
- type: Item
|
||||
heldPrefix: off
|
||||
- type: ContainerContainer
|
||||
containers:
|
||||
cell_slot: !type:ContainerSlot
|
||||
- type: ItemSlots
|
||||
|
||||
- type: entity
|
||||
parent: ClothingHeadHatHardhatBase
|
||||
|
||||
@@ -207,9 +207,6 @@
|
||||
sprite: Clothing/Head/Helmets/firehelmet.rsi
|
||||
quickEquip: true
|
||||
- type: IngestionBlocker
|
||||
- type: PowerCellSlot
|
||||
cellSlot:
|
||||
startingItem: PowerCellMedium
|
||||
- type: TemperatureProtection
|
||||
coefficient: 0.01
|
||||
- type: Armor
|
||||
@@ -221,10 +218,10 @@
|
||||
Heat: 0.65
|
||||
Radiation: 1
|
||||
- type: IdentityBlocker
|
||||
- type: ItemSlots
|
||||
- type: ContainerContainer
|
||||
containers:
|
||||
cell_slot: !type:ContainerSlot {}
|
||||
- type: Tag
|
||||
tags:
|
||||
- HidesHair
|
||||
- WhitelistChameleon
|
||||
|
||||
- type: entity
|
||||
parent: ClothingHeadLightBase
|
||||
|
||||
@@ -8,12 +8,15 @@
|
||||
- type: ItemCooldown
|
||||
- type: UseDelay
|
||||
delay: 1.0
|
||||
- type: ItemSlots
|
||||
- type: ContainerContainer
|
||||
containers:
|
||||
cell_slot: !type:ContainerSlot {}
|
||||
- type: PowerCellSlot
|
||||
cellSlot:
|
||||
cellSlotId: cell_slot
|
||||
- type: ItemSlots
|
||||
slots:
|
||||
cell_slot:
|
||||
name: power-cell-slot-component-slot-name-default
|
||||
startingItem: PowerCellMedium
|
||||
- type: Sprite
|
||||
sprite: Objects/Devices/Holoprojectors/custodial.rsi
|
||||
|
||||
@@ -7,7 +7,11 @@
|
||||
- type: HandheldLight
|
||||
addPrefix: true
|
||||
- type: PowerCellSlot
|
||||
cellSlotId: cell_slot
|
||||
- type: ItemSlots
|
||||
slots:
|
||||
cell_slot:
|
||||
name: power-cell-slot-component-slot-name-default
|
||||
- type: ContainerContainer
|
||||
containers:
|
||||
cell_slot: !type:ContainerSlot
|
||||
|
||||
@@ -26,12 +26,15 @@
|
||||
- state: inhand-right-light
|
||||
shader: unshaded
|
||||
- type: PowerCellSlot
|
||||
cellSlot:
|
||||
startingItem: PowerCellMedium
|
||||
cellSlotId: cell_slot
|
||||
- type: ContainerContainer
|
||||
containers:
|
||||
cell_slot: !type:ContainerSlot
|
||||
- type: ItemSlots
|
||||
slots:
|
||||
cell_slot:
|
||||
name: power-cell-slot-component-slot-name-default
|
||||
startingItem: PowerCellMedium
|
||||
- type: Sprite
|
||||
sprite: Objects/Tools/flashlight.rsi
|
||||
netsync: false
|
||||
@@ -64,8 +67,10 @@
|
||||
- type: Tag
|
||||
tags:
|
||||
- SecBeltEquip
|
||||
- type: PowerCellSlot
|
||||
cellSlot:
|
||||
- type: ItemSlots
|
||||
slots:
|
||||
cell_slot:
|
||||
name: power-cell-slot-component-slot-name-default
|
||||
startingItem: PowerCellHigh
|
||||
- type: HandheldLight
|
||||
addPrefix: false
|
||||
|
||||
@@ -28,9 +28,12 @@
|
||||
- type: LanternVisualizer
|
||||
- type: ToggleableLightVisuals
|
||||
- type: PowerCellSlot
|
||||
cellSlot:
|
||||
startingItem: PowerCellMedium
|
||||
cellSlotId: cell_slot
|
||||
- type: ItemSlots
|
||||
slots:
|
||||
cell_slot:
|
||||
name: power-cell-slot-component-slot-name-default
|
||||
startingItem: PowerCellMedium
|
||||
- type: ContainerContainer
|
||||
containers:
|
||||
cell_slot: !type:ContainerSlot {}
|
||||
|
||||
Reference in New Issue
Block a user