Remove drones, fix InnateToolSystem (#25372)

* Fix drones

* They dont need a full bloodstream

* Incorrect indentation

* Nuke drones

* Fix ClothingHeadHatCatEars

* Remove last mention of drones

* Implement requested changes
This commit is contained in:
Debug
2024-02-21 07:23:04 +01:00
committed by GitHub
parent 37a4f2db3a
commit 8c6a8c3c5c
57 changed files with 123 additions and 730 deletions

View File

@@ -1,8 +0,0 @@
namespace Content.Server.Drone.Components
{
[RegisterComponent]
public sealed partial class DroneComponent : Component
{
public float InteractionBlockRange = 2.15f;
}
}

View File

@@ -1,146 +0,0 @@
using Content.Server.Body.Systems;
using Content.Server.Drone.Components;
using Content.Server.Ghost.Roles.Components;
using Content.Server.Popups;
using Content.Server.Tools.Innate;
using Content.Shared.UserInterface;
using Content.Shared.Body.Components;
using Content.Shared.Drone;
using Content.Shared.Emoting;
using Content.Shared.Examine;
using Content.Shared.Ghost;
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction.Components;
using Content.Shared.Interaction.Events;
using Content.Shared.Item;
using Content.Shared.Mind.Components;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
using Content.Shared.Popups;
using Content.Shared.Tag;
using Content.Shared.Throwing;
using Robust.Shared.Timing;
namespace Content.Server.Drone
{
public sealed class DroneSystem : SharedDroneSystem
{
[Dependency] private readonly BodySystem _bodySystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly TagSystem _tagSystem = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly InnateToolSystem _innateToolSystem = default!;
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<DroneComponent, InteractionAttemptEvent>(OnInteractionAttempt);
SubscribeLocalEvent<DroneComponent, UserOpenActivatableUIAttemptEvent>(OnActivateUIAttempt);
SubscribeLocalEvent<DroneComponent, MobStateChangedEvent>(OnMobStateChanged);
SubscribeLocalEvent<DroneComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<DroneComponent, MindAddedMessage>(OnMindAdded);
SubscribeLocalEvent<DroneComponent, MindRemovedMessage>(OnMindRemoved);
SubscribeLocalEvent<DroneComponent, EmoteAttemptEvent>(OnEmoteAttempt);
SubscribeLocalEvent<DroneComponent, ThrowAttemptEvent>(OnThrowAttempt);
}
private void OnInteractionAttempt(EntityUid uid, DroneComponent component, InteractionAttemptEvent args)
{
if (args.Target != null && !HasComp<UnremoveableComponent>(args.Target) && NonDronesInRange(uid, component))
args.Cancel();
if (HasComp<ItemComponent>(args.Target) && !HasComp<UnremoveableComponent>(args.Target))
{
if (!_tagSystem.HasAnyTag(args.Target.Value, "DroneUsable", "Trash"))
args.Cancel();
}
}
private void OnActivateUIAttempt(EntityUid uid, DroneComponent component, UserOpenActivatableUIAttemptEvent args)
{
if (!_tagSystem.HasTag(args.Target, "DroneUsable"))
{
args.Cancel();
}
}
private void OnExamined(EntityUid uid, DroneComponent component, ExaminedEvent args)
{
if (TryComp<MindContainerComponent>(uid, out var mind) && mind.HasMind)
{
args.PushMarkup(Loc.GetString("drone-active"));
}
else
{
args.PushMarkup(Loc.GetString("drone-dormant"));
}
}
private void OnMobStateChanged(EntityUid uid, DroneComponent drone, MobStateChangedEvent args)
{
if (args.NewMobState == MobState.Dead)
{
if (TryComp<InnateToolComponent>(uid, out var innate))
_innateToolSystem.Cleanup(uid, innate);
if (TryComp<BodyComponent>(uid, out var body))
_bodySystem.GibBody(uid, body: body);
QueueDel(uid);
}
}
private void OnMindAdded(EntityUid uid, DroneComponent drone, MindAddedMessage args)
{
UpdateDroneAppearance(uid, DroneStatus.On);
_popupSystem.PopupEntity(Loc.GetString("drone-activated"), uid, PopupType.Large);
}
private void OnMindRemoved(EntityUid uid, DroneComponent drone, MindRemovedMessage args)
{
UpdateDroneAppearance(uid, DroneStatus.Off);
EnsureComp<GhostTakeoverAvailableComponent>(uid);
}
private void OnEmoteAttempt(EntityUid uid, DroneComponent component, EmoteAttemptEvent args)
{
// No.
args.Cancel();
}
private void OnThrowAttempt(EntityUid uid, DroneComponent drone, ThrowAttemptEvent args)
{
args.Cancel();
}
private void UpdateDroneAppearance(EntityUid uid, DroneStatus status)
{
if (TryComp<AppearanceComponent>(uid, out var appearance))
{
_appearance.SetData(uid, DroneVisuals.Status, status, appearance);
}
}
private bool NonDronesInRange(EntityUid uid, DroneComponent component)
{
var xform = Comp<TransformComponent>(uid);
foreach (var entity in _lookup.GetEntitiesInRange(xform.MapPosition, component.InteractionBlockRange))
{
// Return true if the entity is/was controlled by a player and is not a drone or ghost.
if (HasComp<MindContainerComponent>(entity) && !HasComp<DroneComponent>(entity) && !HasComp<GhostComponent>(entity))
{
// Filter out dead ghost roles. Dead normal players are intended to block.
if ((TryComp<MobStateComponent>(entity, out var entityMobState) && HasComp<GhostTakeoverAvailableComponent>(entity) && _mobStateSystem.IsDead(entity, entityMobState)))
continue;
if (_gameTiming.IsFirstTimePredicted)
_popupSystem.PopupEntity(Loc.GetString("drone-too-close", ("being", Identity.Entity(entity, EntityManager))), uid, uid);
return true;
}
}
return false;
}
}
}

View File

@@ -7,5 +7,6 @@ namespace Content.Server.Tools.Innate
{
[DataField("tools")] public List<EntitySpawnEntry> Tools = new();
public List<EntityUid> ToolUids = new();
public List<string> ToSpawn = new();
}
}

View File

@@ -1,90 +1,99 @@
using System.Linq;
using Content.Shared.Body.Part;
using Content.Shared.Destructible;
using Content.Shared.Hands;
using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction.Components;
using Content.Shared.Storage;
using Content.Shared.Tag;
using Robust.Shared.Network;
using Robust.Shared.Random;
namespace Content.Server.Tools.Innate
namespace Content.Server.Tools.Innate;
/// <summary>
/// Spawns a list unremovable tools in hands if possible. Used for drones,
/// borgs, or maybe even stuff like changeling armblades!
/// </summary>
public sealed class InnateToolSystem : EntitySystem
{
/// <summary>
/// Spawns a list unremovable tools in hands if possible. Used for drones,
/// borgs, or maybe even stuff like changeling armblades!
/// </summary>
public sealed class InnateToolSystem : EntitySystem
[Dependency] private readonly IRobustRandom _robustRandom = default!;
[Dependency] private readonly SharedHandsSystem _sharedHandsSystem = default!;
[Dependency] private readonly TagSystem _tagSystem = default!;
public override void Initialize()
{
[Dependency] private readonly IRobustRandom _robustRandom = default!;
[Dependency] private readonly SharedHandsSystem _sharedHandsSystem = default!;
[Dependency] private readonly TagSystem _tagSystem = default!;
public override void Initialize()
base.Initialize();
SubscribeLocalEvent<InnateToolComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<InnateToolComponent, HandCountChangedEvent>(OnHandCountChanged);
SubscribeLocalEvent<InnateToolComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<InnateToolComponent, DestructionEventArgs>(OnDestroyed);
}
private void OnMapInit(EntityUid uid, InnateToolComponent component, MapInitEvent args)
{
if (component.Tools.Count == 0)
return;
component.ToSpawn = EntitySpawnCollection.GetSpawns(component.Tools, _robustRandom);
}
private void OnHandCountChanged(EntityUid uid, InnateToolComponent component, HandCountChangedEvent args)
{
if (component.ToSpawn.Count == 0)
return;
var spawnCoord = Transform(uid).Coordinates;
var toSpawn = component.ToSpawn.First();
var item = Spawn(toSpawn, spawnCoord);
AddComp<UnremoveableComponent>(item);
if (!_sharedHandsSystem.TryPickupAnyHand(uid, item, checkActionBlocker: false))
{
base.Initialize();
SubscribeLocalEvent<InnateToolComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<InnateToolComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<InnateToolComponent, DestructionEventArgs>(OnDestroyed);
QueueDel(item);
component.ToSpawn.Clear();
}
component.ToSpawn.Remove(toSpawn);
component.ToolUids.Add(item);
}
private void OnStartup(EntityUid uid, InnateToolComponent component, ComponentStartup args)
private void OnShutdown(EntityUid uid, InnateToolComponent component, ComponentShutdown args)
{
foreach (var tool in component.ToolUids)
{
if (component.Tools.Count == 0)
return;
var spawnCoord = Transform(uid).Coordinates;
if (TryComp<HandsComponent>(uid, out var hands) && hands.Count >= component.Tools.Count)
{
var items = EntitySpawnCollection.GetSpawns(component.Tools, _robustRandom);
foreach (var entry in items)
{
var item = Spawn(entry, spawnCoord);
AddComp<UnremoveableComponent>(item);
if (!_sharedHandsSystem.TryPickupAnyHand(uid, item, checkActionBlocker: false))
{
QueueDel(item);
continue;
}
component.ToolUids.Add(item);
}
}
RemComp<UnremoveableComponent>(tool);
}
}
private void OnShutdown(EntityUid uid, InnateToolComponent component, ComponentShutdown args)
private void OnDestroyed(EntityUid uid, InnateToolComponent component, DestructionEventArgs args)
{
Cleanup(uid, component);
}
public void Cleanup(EntityUid uid, InnateToolComponent component)
{
foreach (var tool in component.ToolUids)
{
foreach (var tool in component.ToolUids)
if (_tagSystem.HasTag(tool, "InnateDontDelete"))
{
RemComp<UnremoveableComponent>(tool);
}
}
private void OnDestroyed(EntityUid uid, InnateToolComponent component, DestructionEventArgs args)
{
Cleanup(uid, component);
}
public void Cleanup(EntityUid uid, InnateToolComponent component)
{
foreach (var tool in component.ToolUids)
else
{
if (_tagSystem.HasTag(tool, "InnateDontDelete"))
{
RemComp<UnremoveableComponent>(tool);
}
else
{
Del(tool);
}
if (TryComp<HandsComponent>(uid, out var hands))
{
foreach (var hand in hands.Hands)
{
_sharedHandsSystem.TryDrop(uid, hand.Value, checkActionBlocker: false, handsComp: hands);
}
}
Del(tool);
}
component.ToolUids.Clear();
if (TryComp<HandsComponent>(uid, out var hands))
{
foreach (var hand in hands.Hands)
{
_sharedHandsSystem.TryDrop(uid, hand.Value, checkActionBlocker: false, handsComp: hands);
}
}
}
component.ToolUids.Clear();
}
}

View File

@@ -3,7 +3,6 @@ using Content.Server.Body.Systems;
using Content.Server.Chat;
using Content.Server.Chat.Systems;
using Content.Server.Cloning;
using Content.Server.Drone.Components;
using Content.Server.Emoting.Systems;
using Content.Server.Inventory;
using Content.Server.Speech.EntitySystems;
@@ -214,7 +213,7 @@ namespace Content.Server.Zombies
if (args.User == entity)
continue;
if (!TryComp<MobStateComponent>(entity, out var mobState) || HasComp<DroneComponent>(entity))
if (!TryComp<MobStateComponent>(entity, out var mobState))
continue;
if (HasComp<ZombieComponent>(entity))