Solution Entities (#21916)
* Creates Content.Shared.Chemistry.Solutions Copies Solution class to new namespace Obsoletes old Solution class * Switches over to the Solutions.Solution Solution * Creates Content.Shared.Chemistry.Containers Copies relevant components/systems to the new namespace Obsoletes old versions * Switches over to the Containers.XYZ namespace * Creates SolutionSystem and obsoletes old SolutionContainerSystem methods * Start using SolutionSystem for Solution manipulation * EnumerateSolutions * Move TryGetMixableSolution * Move EnsureSolution to Server * Create Solution Entities * Stop using obsolete solution system methods * Fix prototype component tests * Add using ..Audio.Systems; back * Wrap solution container slots in ContainerSlots * Actually add the slot to the solution container map * Dirty SolutionContainerComponent when ensuring solutions * Revert namespace changes * Remerge SolutionSystem and SolutionContainerSystem * SolutionContainerManagerComponent refactor * Avoid wrapping necessary code in DebugTools.Assert as it is removed when compiling for release * Readd examine reagent sorting * Fix errors * Poke tests * Fix solution names not being applied * Fix WoolyComponent including statement * Fix merge skew * Fix compile errors * Make reactions use solntities * Reindent solution class namespace * Field attribute changes * AutoGenerateComponentState for SolutionContainerComponent * SolutionContainerComponent -> ContainedSolutionComponent * ref ReactionAttemptEvent * Denetwork preinit solutions * Misc 1 * Nullable TryGetSolution out vars * Cache associated solutions * Fix merge skew * Use explicit regions in SharedSolutionContainerSystem.Capabilities * Add debug assert * Use explicit regions in SharedSolutionContainerSystem.Relay + ref SolutionContainerChangedEvent * ContainedSolutionComponent.Name -> ContainedSolutionComponent.ContainerName * SolutionComponent doc comments * Implicit DataField names and property purge * ReagentEffect DataField names * Local variables for readability * Sort using statements + Entity<T> event handlers * Fix compile erros * Fix compile errors --------- Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
This commit is contained in:
@@ -25,49 +25,50 @@ namespace Content.Server.Stunnable.Systems
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<BatteryComponent, ExaminedEvent>(OnExamined);
|
||||
SubscribeLocalEvent<StunbatonComponent, SolutionChangedEvent>(OnSolutionChange);
|
||||
SubscribeLocalEvent<StunbatonComponent, SolutionContainerChangedEvent>(OnSolutionChange);
|
||||
SubscribeLocalEvent<StunbatonComponent, StaminaDamageOnHitAttemptEvent>(OnStaminaHitAttempt);
|
||||
SubscribeLocalEvent<StunbatonComponent, ItemToggleActivateAttemptEvent>(TryTurnOn);
|
||||
SubscribeLocalEvent<StunbatonComponent, ItemToggleDoneEvent>(ToggleDone);
|
||||
}
|
||||
|
||||
private void OnStaminaHitAttempt(EntityUid uid, StunbatonComponent component, ref StaminaDamageOnHitAttemptEvent args)
|
||||
private void OnStaminaHitAttempt(Entity<StunbatonComponent> entity, ref StaminaDamageOnHitAttemptEvent args)
|
||||
{
|
||||
if (!_itemToggle.IsActivated(uid) ||
|
||||
!TryComp<BatteryComponent>(uid, out var battery) || !_battery.TryUseCharge(uid, component.EnergyPerUse, battery))
|
||||
if (!_itemToggle.IsActivated(entity.Owner) ||
|
||||
!TryComp<BatteryComponent>(entity.Owner, out var battery) || !_battery.TryUseCharge(entity.Owner, entity.Comp.EnergyPerUse, battery))
|
||||
{
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (battery.CurrentCharge < component.EnergyPerUse)
|
||||
if (battery.CurrentCharge < entity.Comp.EnergyPerUse)
|
||||
{
|
||||
_itemToggle.Toggle(uid, predicted: false);
|
||||
_itemToggle.Toggle(entity.Owner, predicted: false);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnExamined(EntityUid uid, BatteryComponent battery, ExaminedEvent args)
|
||||
private void OnExamined(Entity<BatteryComponent> entity, ref ExaminedEvent args)
|
||||
{
|
||||
var onMsg = _itemToggle.IsActivated(uid)
|
||||
var onMsg = _itemToggle.IsActivated(entity.Owner)
|
||||
? Loc.GetString("comp-stunbaton-examined-on")
|
||||
: Loc.GetString("comp-stunbaton-examined-off");
|
||||
args.PushMarkup(onMsg);
|
||||
|
||||
var chargeMessage = Loc.GetString("stunbaton-component-on-examine-charge",
|
||||
("charge", (int) (battery.CurrentCharge / battery.MaxCharge * 100)));
|
||||
("charge", (int) (entity.Comp.CurrentCharge / entity.Comp.MaxCharge * 100)));
|
||||
args.PushMarkup(chargeMessage);
|
||||
}
|
||||
|
||||
private void ToggleDone(EntityUid uid, StunbatonComponent comp, ref ItemToggleDoneEvent args)
|
||||
private void ToggleDone(Entity<StunbatonComponent> entity, ref ItemToggleDoneEvent args)
|
||||
{
|
||||
if (!TryComp<ItemComponent>(uid, out var item))
|
||||
if (!TryComp<ItemComponent>(entity, out var item))
|
||||
return;
|
||||
_item.SetHeldPrefix(uid, args.Activated ? "on" : "off", item);
|
||||
|
||||
_item.SetHeldPrefix(entity.Owner, args.Activated ? "on" : "off", item);
|
||||
}
|
||||
|
||||
private void TryTurnOn(EntityUid uid, StunbatonComponent comp, ref ItemToggleActivateAttemptEvent args)
|
||||
private void TryTurnOn(Entity<StunbatonComponent> entity, ref ItemToggleActivateAttemptEvent args)
|
||||
{
|
||||
if (!TryComp<BatteryComponent>(uid, out var battery) || battery.CurrentCharge < comp.EnergyPerUse)
|
||||
if (!TryComp<BatteryComponent>(entity, out var battery) || battery.CurrentCharge < entity.Comp.EnergyPerUse)
|
||||
{
|
||||
args.Cancelled = true;
|
||||
if (args.User != null)
|
||||
@@ -77,22 +78,22 @@ namespace Content.Server.Stunnable.Systems
|
||||
return;
|
||||
}
|
||||
|
||||
if (TryComp<RiggableComponent>(uid, out var rig) && rig.IsRigged)
|
||||
if (TryComp<RiggableComponent>(entity, out var rig) && rig.IsRigged)
|
||||
{
|
||||
_riggableSystem.Explode(uid, battery, args.User);
|
||||
_riggableSystem.Explode(entity.Owner, battery, args.User);
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/space-wizards/space-station-14/pull/17288#discussion_r1241213341
|
||||
private void OnSolutionChange(EntityUid uid, StunbatonComponent component, SolutionChangedEvent args)
|
||||
private void OnSolutionChange(Entity<StunbatonComponent> entity, ref SolutionContainerChangedEvent args)
|
||||
{
|
||||
// Explode if baton is activated and rigged.
|
||||
if (!TryComp<RiggableComponent>(uid, out var riggable) ||
|
||||
!TryComp<BatteryComponent>(uid, out var battery))
|
||||
if (!TryComp<RiggableComponent>(entity, out var riggable) ||
|
||||
!TryComp<BatteryComponent>(entity, out var battery))
|
||||
return;
|
||||
|
||||
if (_itemToggle.IsActivated(uid) && riggable.IsRigged)
|
||||
_riggableSystem.Explode(uid, battery);
|
||||
if (_itemToggle.IsActivated(entity.Owner) && riggable.IsRigged)
|
||||
_riggableSystem.Explode(entity.Owner, battery);
|
||||
}
|
||||
|
||||
private void SendPowerPulse(EntityUid target, EntityUid? user, EntityUid used)
|
||||
|
||||
Reference in New Issue
Block a user