Salvage mob restrictions (#8080)
This commit is contained in:
23
Content.Server/Salvage/SalvageMobRestrictionsComponent.cs
Normal file
23
Content.Server/Salvage/SalvageMobRestrictionsComponent.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using System;
|
||||
|
||||
namespace Content.Server.Salvage;
|
||||
|
||||
/// <summary>
|
||||
/// This component exists as a sort of stateful marker for a
|
||||
/// killswitch meant to keep salvage mobs from doing stuff they
|
||||
/// really shouldn't (attacking station).
|
||||
/// The main thing is that adding this component ties the mob to
|
||||
/// whatever it's currently parented to.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class SalvageMobRestrictionsComponent : Component
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
[DataField("linkedGridEntity")]
|
||||
public EntityUid LinkedGridEntity = EntityUid.Invalid;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using System;
|
||||
|
||||
namespace Content.Server.Salvage;
|
||||
|
||||
/// <summary>
|
||||
/// This component is attached to grids when a salvage mob is
|
||||
/// spawned on them.
|
||||
/// This attachment is done by SalvageMobRestrictionsSystem.
|
||||
/// *Simply put, when this component is removed, the mobs die.*
|
||||
/// *This applies even if the mobs are off-grid at the time.*
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class SalvageMobRestrictionsGridComponent : Component
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
[DataField("mobsToKill")]
|
||||
public List<EntityUid> MobsToKill = new();
|
||||
}
|
||||
|
||||
80
Content.Server/Salvage/SalvageMobRestrictionsSystem.cs
Normal file
80
Content.Server/Salvage/SalvageMobRestrictionsSystem.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Server.Body.Components;
|
||||
using Robust.Server.Maps;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Content.Server.Salvage;
|
||||
|
||||
public sealed class SalvageMobRestrictionsSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SalvageMobRestrictionsComponent, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<SalvageMobRestrictionsComponent, ComponentRemove>(OnRemove);
|
||||
SubscribeLocalEvent<SalvageMobRestrictionsGridComponent, ComponentRemove>(OnRemoveGrid);
|
||||
}
|
||||
|
||||
private void OnInit(EntityUid uid, SalvageMobRestrictionsComponent component, ComponentInit args)
|
||||
{
|
||||
var gridUid = Transform(uid).ParentUid;
|
||||
if (!EntityManager.EntityExists(gridUid))
|
||||
{
|
||||
// Give up, we were spawned improperly
|
||||
return;
|
||||
}
|
||||
// When this code runs, the salvage magnet hasn't actually gotten ahold of the entity yet.
|
||||
// So it therefore isn't in a position to do this.
|
||||
if (!TryComp(gridUid, out SalvageMobRestrictionsGridComponent? rg))
|
||||
{
|
||||
rg = AddComp<SalvageMobRestrictionsGridComponent>(gridUid);
|
||||
}
|
||||
rg!.MobsToKill.Add(uid);
|
||||
component.LinkedGridEntity = gridUid;
|
||||
}
|
||||
|
||||
private void OnRemove(EntityUid uid, SalvageMobRestrictionsComponent component, ComponentRemove args)
|
||||
{
|
||||
if (TryComp(component.LinkedGridEntity, out SalvageMobRestrictionsGridComponent? rg))
|
||||
{
|
||||
rg.MobsToKill.Remove(uid);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRemoveGrid(EntityUid uid, SalvageMobRestrictionsGridComponent component, ComponentRemove args)
|
||||
{
|
||||
foreach (EntityUid target in component.MobsToKill)
|
||||
{
|
||||
if (TryComp(target, out BodyComponent? body))
|
||||
{
|
||||
// Just because.
|
||||
body.Gib();
|
||||
}
|
||||
else if (TryComp(target, out DamageableComponent? dc))
|
||||
{
|
||||
_damageableSystem.SetAllDamage(dc, 200);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,8 +189,13 @@ namespace Content.Server.Salvage
|
||||
{
|
||||
if (player.AttachedEntity.HasValue)
|
||||
{
|
||||
var playerTransform = EntityManager.GetComponent<TransformComponent>(player.AttachedEntity.Value);
|
||||
playerTransform.AttachParent(parentTransform);
|
||||
var playerEntityUid = player.AttachedEntity.Value;
|
||||
if (HasComp<SalvageMobRestrictionsComponent>(playerEntityUid))
|
||||
{
|
||||
// Salvage mobs are NEVER immune (even if they're from a different salvage, they shouldn't be here)
|
||||
continue;
|
||||
}
|
||||
Transform(playerEntityUid).AttachParent(parentTransform);
|
||||
}
|
||||
}
|
||||
EntityManager.QueueDeleteEntity(salvage);
|
||||
|
||||
Reference in New Issue
Block a user