Salvage mob restrictions (#8080)

This commit is contained in:
20kdc
2022-05-13 20:01:30 +01:00
committed by GitHub
parent 2c927bb24e
commit 90cce82a47
8 changed files with 181 additions and 22 deletions

View 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;
}

View 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 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();
}

View 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);
}
}
}
}

View File

@@ -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);