Modular landmines (#8351)
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.Explosion.EntitySystems;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Payload.Components;
|
||||
using Content.Shared.Tag;
|
||||
using Robust.Shared.Containers;
|
||||
@@ -27,22 +29,34 @@ public sealed class PayloadSystem : EntitySystem
|
||||
SubscribeLocalEvent<PayloadTriggerComponent, TriggerEvent>(OnTriggerTriggered);
|
||||
SubscribeLocalEvent<PayloadCaseComponent, EntInsertedIntoContainerMessage>(OnEntityInserted);
|
||||
SubscribeLocalEvent<PayloadCaseComponent, EntRemovedFromContainerMessage>(OnEntityRemoved);
|
||||
SubscribeLocalEvent<PayloadCaseComponent, ExaminedEvent>(OnExamined);
|
||||
SubscribeLocalEvent<ChemicalPayloadComponent, TriggerEvent>(HandleChemicalPayloadTrigger);
|
||||
}
|
||||
|
||||
public IEnumerable<EntityUid> GetAllPayloads(EntityUid uid, ContainerManagerComponent? contMan=null)
|
||||
{
|
||||
if (!Resolve(uid, ref contMan, false))
|
||||
yield break;
|
||||
|
||||
foreach (var container in contMan.Containers.Values)
|
||||
{
|
||||
foreach (var entity in container.ContainedEntities)
|
||||
{
|
||||
if (_tagSystem.HasTag(entity, "Payload"))
|
||||
yield return entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCaseTriggered(EntityUid uid, PayloadCaseComponent component, TriggerEvent args)
|
||||
{
|
||||
if (!TryComp(uid, out ContainerManagerComponent? contMan))
|
||||
return;
|
||||
|
||||
// Pass trigger event onto all contained payloads. Payload capacity configurable by construction graphs.
|
||||
foreach (var container in contMan.Containers.Values)
|
||||
foreach (var ent in GetAllPayloads(uid, contMan))
|
||||
{
|
||||
foreach (var entity in container.ContainedEntities)
|
||||
{
|
||||
if (_tagSystem.HasTag(entity, "Payload"))
|
||||
RaiseLocalEvent(entity, args, false);
|
||||
}
|
||||
RaiseLocalEvent(ent, args, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +120,24 @@ public sealed class PayloadSystem : EntitySystem
|
||||
trigger.GrantedComponents.Clear();
|
||||
}
|
||||
|
||||
private void OnExamined(EntityUid uid, PayloadCaseComponent component, ExaminedEvent args)
|
||||
{
|
||||
if (!args.IsInDetailsRange)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("payload-case-not-close-enough", ("ent", uid)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (GetAllPayloads(uid).Any())
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("payload-case-has-payload", ("ent", uid)));
|
||||
}
|
||||
else
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("payload-case-does-not-have-payload", ("ent", uid)));
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleChemicalPayloadTrigger(EntityUid uid, ChemicalPayloadComponent component, TriggerEvent args)
|
||||
{
|
||||
if (component.BeakerSlotA.Item is not EntityUid beakerA
|
||||
@@ -135,5 +167,7 @@ public sealed class PayloadSystem : EntitySystem
|
||||
_solutionSystem.TryAddSolution(beakerB, solutionB, tmpSol);
|
||||
solutionA.MaxVolume -= solutionB.MaxVolume;
|
||||
_solutionSystem.UpdateChemicals(beakerA, solutionA, false);
|
||||
|
||||
args.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user