CatStation/Content.Server/Power/EntitySystems/RiggableSystem.cs
Princess Cheeseballs ef3a0ecc2a
Solutions Refactor Part 1 - Solution Prototypes (#43412)
* Everything except the YAML slop...

* She solution on my manager till I sajfslkahfsjakfhaskjfshajksafhfsakhfasjfas

* another 1000 lines

* fix chem dispenser size

* go my shnelf

* Implicit ass

* rider is being mean for some reason

* dasdas

* borger

* better formatting go!

* clothes/bloodstream

* Cartons

* cups and bottles

* mmm soder

* bar drinks

* Spray bottles and some size tweaks with hindsight

* 99 bottles of beer on the wall I hate YAML

* push that shit

* mmm burger

* Sneed

* sheets

* condiments

* mmm yummy

* fridge yummyfood

* meat...

* sub 300

* burger...

* bready

* let them eat cake

* does she know how to make a grilled cheese?

* pizza pie!

* misc shit

* soup or salad

* Food and drinks, vanquished

* the cubes!!!

* Almost free from YAML...

* fix test fails and some yaml issues

* fix prediction, almost done

* fix all test fails

* remove master merge artifacts and undo autonetworking

* review and compatibility

* graaah

* unfuck master merge I hate github

* merg conflicts

* sfsa

* ehoop

* sadas

* afsafsaasf

* merge conflicts

* fucked up the merge conflicts

* merge conflict is fucked I might need to completely redo this branch

* test fail

* no calcium????

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
2026-04-25 02:00:34 +00:00

88 lines
3 KiB
C#

using Content.Server.Administration.Logs;
using Content.Server.Explosion.EntitySystems;
using Content.Server.Power.Components;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Database;
using Content.Shared.Kitchen;
using Content.Shared.Power;
using Content.Shared.Power.Components;
using Content.Shared.Power.EntitySystems;
using Content.Shared.Rejuvenate;
namespace Content.Server.Power.EntitySystems;
/// <summary>
/// Handles sabotaged/rigged objects
/// </summary>
public sealed class RiggableSystem : EntitySystem
{
[Dependency] private readonly ExplosionSystem _explosionSystem = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly SharedBatterySystem _battery = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RiggableComponent, RejuvenateEvent>(OnRejuvenate);
SubscribeLocalEvent<RiggableComponent, BeingMicrowavedEvent>(OnMicrowaved);
SubscribeLocalEvent<RiggableComponent, SolutionChangedEvent>(OnSolutionChanged);
SubscribeLocalEvent<RiggableComponent, ChargeChangedEvent>(OnChargeChanged);
}
private void OnRejuvenate(Entity<RiggableComponent> entity, ref RejuvenateEvent args)
{
entity.Comp.IsRigged = false;
}
private void OnMicrowaved(Entity<RiggableComponent> entity, ref BeingMicrowavedEvent args)
{
if (TryComp<BatteryComponent>(entity, out var batteryComponent))
{
var charge = _battery.GetCharge((entity, batteryComponent));
if (charge == 0f)
return;
Explode(entity, charge);
args.Handled = true;
}
}
private void OnSolutionChanged(Entity<RiggableComponent> entity, ref SolutionChangedEvent args)
{
if (args.Solution.Comp.Id != entity.Comp.Solution)
return;
var wasRigged = entity.Comp.IsRigged;
var solution = args.Solution.Comp.Solution;
var quantity = solution.GetReagentQuantity(entity.Comp.RequiredQuantity.Reagent);
entity.Comp.IsRigged = quantity >= entity.Comp.RequiredQuantity.Quantity;
if (entity.Comp.IsRigged && !wasRigged)
{
_adminLogger.Add(LogType.Explosion, LogImpact.Medium, $"{ToPrettyString(entity.Owner)} has been rigged up to explode when used.");
}
}
public void Explode(EntityUid uid, float charge, EntityUid? cause = null)
{
var radius = MathF.Min(5, MathF.Sqrt(charge) / 9);
_explosionSystem.TriggerExplosive(uid, radius: radius, user: cause);
QueueDel(uid);
}
private void OnChargeChanged(Entity<RiggableComponent> ent, ref ChargeChangedEvent args)
{
if (!ent.Comp.IsRigged)
return;
if (args.CurrentCharge == 0f)
return; // No charge to cause an explosion.
// Don't explode if we are not using any charge.
if (args.CurrentChargeRate == 0f && args.Delta == 0f)
return;
Explode(ent, args.CurrentCharge);
}
}