Files
tbd-station-14/Content.Shared/Charges/Systems/SharedChargesSystem.cs
chromiumboy 02273ca0e7 Improved RCDs (#22799)
* Initial radial menu prototyping for the RCD

* Radial UI buttons can send messages to the server

* Beginning to update RCDSystem

* RCD building system in progress

* Further updates

* Added extra effects, RCDSystem now reads RCD prototype data

* Replacing tiles is instant, multiple constructions are allowed, deconstruction is broken

* Added extra functionality to RadialContainers plus documentation

* Fixed localization of RCD UI strings

* Menu opens near cursor, added basic RCD

* Avoiding merge conflict

* Implemented atomized construction / deconstruction rules

* Increased RCD ammo base charges

* Moved input context definition to content

* Removed obsoleted code

* Updates to system

* Switch machine and computer frames for electrical cabling

* Added construction ghosts

* Fixed issue with keybind detection code

* Fixed RCD construction ghost mispredications

* Code clean up

* Updated deconstruction effects

* RCDs effects don't rotate

* Code clean up

* Balancing for ammo counts

* Code clean up

* Added missing localized strings

* More clean up

* Made directional window handling more robust

* Added documentation to radial menus and made them no longer dependent on Content

* Made radial containers more robust

* Further robustness to the radial menu

* The RCD submenu buttons are only shown when the destination layer has at least one children

* Expanded upon deconstructing plus construction balance

* Fixed line endings

* Updated list of RCD deconstructable entities. Now needs a component to deconstruct instead of a tag

* Bug fixes

* Revert unnecessary change

* Updated RCD strings

* Fixed bug

* More fixes

* Deconstructed tiles/subflooring convert to lattice instead

* Fixed failed tests (Linux doesn't like invalid spritespecifer paths)

* Fixing merge conflict

* Updated airlock assembly

* Fixing merge conflict

* Fixing merge conflict

* More fixing...

* Removed erroneous project file change

* Fixed string handling issue

* Trying to fix merge conflict

* Still fixing merge conflicts

* Balancing

* Hidden RCD construction ghosts when in 'build' mode

* Fixing merge conflict

* Implemented requested changes (Part 1)

* Added more requested changes

* Fix for failed test. Removed sussy null suppression

* Made requested changes - custom construction ghost system was replaced

* Fixing merge conflict

* Fixed merge conflict

* Fixed bug in RCD construction ghost validation

* Fixing merge conflict

* Merge conflict fixed

* Made required update

* Removed lingering RCD deconstruct tag

* Fixing merge conflict

* Merge conflict fixed

* Made requested changes

* Bug fixes and balancing

* Made string names more consistent

* Can no longer stack catwalks
2024-03-30 23:29:47 -05:00

87 lines
3.0 KiB
C#

using Content.Shared.Charges.Components;
using Content.Shared.Examine;
namespace Content.Shared.Charges.Systems;
public abstract class SharedChargesSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<LimitedChargesComponent, ExaminedEvent>(OnExamine);
}
protected virtual void OnExamine(EntityUid uid, LimitedChargesComponent comp, ExaminedEvent args)
{
if (!args.IsInDetailsRange)
return;
using (args.PushGroup(nameof(LimitedChargesComponent)))
{
args.PushMarkup(Loc.GetString("limited-charges-charges-remaining", ("charges", comp.Charges)));
if (comp.Charges == comp.MaxCharges)
{
args.PushMarkup(Loc.GetString("limited-charges-max-charges"));
}
}
}
/// <summary>
/// Tries to add a number of charges. If it over or underflows it will be clamped, wasting the extra charges.
/// </summary>
public void AddCharges(EntityUid uid, int change, LimitedChargesComponent? comp = null)
{
if (!Resolve(uid, ref comp, false))
return;
var old = comp.Charges;
comp.Charges = Math.Clamp(comp.Charges + change, 0, comp.MaxCharges);
if (comp.Charges != old)
Dirty(uid, comp);
}
/// <summary>
/// Gets the limited charges component and returns true if there are no charges. Will return false if there is no limited charges component.
/// </summary>
public bool IsEmpty(EntityUid uid, LimitedChargesComponent? comp = null)
{
// can't be empty if there are no limited charges
if (!Resolve(uid, ref comp, false))
return false;
return comp.Charges <= 0;
}
/// <summary>
/// Uses a single charge. Must check IsEmpty beforehand to prevent using with 0 charge.
/// </summary>
public virtual void UseCharge(EntityUid uid, LimitedChargesComponent? comp = null)
{
if (Resolve(uid, ref comp, false))
AddCharges(uid, -1, comp);
}
/// <summary>
/// Gets the limited charges component and returns true if the number of charges remaining is less than the specified value.
/// Will return false if there is no limited charges component.
/// </summary>
public bool HasInsufficientCharges(EntityUid uid, int requiredCharges, LimitedChargesComponent? comp = null)
{
// can't be empty if there are no limited charges
if (!Resolve(uid, ref comp, false))
return false;
return comp.Charges < requiredCharges;
}
/// <summary>
/// Uses up a specified number of charges. Must check HasInsufficentCharges beforehand to prevent using with insufficient remaining charges.
/// </summary>
public virtual void UseCharges(EntityUid uid, int chargesUsed, LimitedChargesComponent? comp = null)
{
if (Resolve(uid, ref comp, false))
AddCharges(uid, -chargesUsed, comp);
}
}