From 7bee0063a6b49ab2bfd71669c44827cd2c0042d7 Mon Sep 17 00:00:00 2001 From: Rane <60792108+Elijahrane@users.noreply.github.com> Date: Wed, 31 Aug 2022 22:09:20 -0400 Subject: [PATCH] Split various drone behaviors out of drone component (innate tool, unpowered flashlight) (#10474) --- .../Drone/Components/DroneComponent.cs | 13 --- Content.Server/Drone/DroneSystem.cs | 70 ++------------ .../UnpoweredFlashlightSystem.cs | 6 ++ .../Tools/Innate/InnateToolComponent.cs | 11 +++ .../Tools/Innate/InnateToolSystem.cs | 91 +++++++++++++++++++ .../Weapon/Ranged/Systems/GunSystem.cs | 5 + .../Fills/Backpacks/StarterGear/satchel.yml | 2 +- .../Entities/Mobs/Player/silicon.yml | 6 +- Resources/Prototypes/tags.yml | 6 +- 9 files changed, 129 insertions(+), 81 deletions(-) create mode 100644 Content.Server/Tools/Innate/InnateToolComponent.cs create mode 100644 Content.Server/Tools/Innate/InnateToolSystem.cs diff --git a/Content.Server/Drone/Components/DroneComponent.cs b/Content.Server/Drone/Components/DroneComponent.cs index c21ce6aa39..73c75aefd4 100644 --- a/Content.Server/Drone/Components/DroneComponent.cs +++ b/Content.Server/Drone/Components/DroneComponent.cs @@ -1,21 +1,8 @@ -using Content.Shared.Storage; - namespace Content.Server.Drone.Components { [RegisterComponent] public sealed class DroneComponent : Component { - [DataField("tools")] public List Tools = new(); - public List ToolUids = new(); - public bool AlreadyAwoken = false; public float InteractionBlockRange = 2.15f; - - /// - /// If you are using drone component for - /// something that shouldn't have restrictions set this to - /// false. - /// - [DataField("applyLaws")] - public bool ApplyLaws = true; } } diff --git a/Content.Server/Drone/DroneSystem.cs b/Content.Server/Drone/DroneSystem.cs index db77db8e06..ad78d73825 100644 --- a/Content.Server/Drone/DroneSystem.cs +++ b/Content.Server/Drone/DroneSystem.cs @@ -1,7 +1,5 @@ using Content.Shared.Drone; using Content.Server.Drone.Components; -using Content.Shared.Actions; -using Content.Server.Light.Components; using Content.Shared.MobState; using Content.Shared.MobState.Components; using Content.Shared.Interaction.Events; @@ -12,19 +10,16 @@ using Content.Shared.Throwing; using Content.Shared.Item; using Content.Shared.Emoting; using Content.Shared.Body.Components; +using Content.Shared.IdentityManagement; +using Content.Shared.Popups; using Content.Server.Popups; using Content.Server.Mind.Components; using Content.Server.Ghost.Components; using Content.Server.Ghost.Roles.Components; -using Content.Server.Hands.Components; +using Content.Server.Tools.Innate; using Content.Server.UserInterface; using Robust.Shared.Player; -using Content.Shared.Hands.EntitySystems; -using Content.Shared.Popups; -using Content.Shared.Storage; -using Robust.Shared.Random; using Robust.Shared.Timing; -using Content.Shared.IdentityManagement; namespace Content.Server.Drone { @@ -33,10 +28,8 @@ namespace Content.Server.Drone [Dependency] private readonly PopupSystem _popupSystem = default!; [Dependency] private readonly TagSystem _tagSystem = default!; [Dependency] private readonly EntityLookupSystem _lookup = default!; - [Dependency] private readonly SharedHandsSystem _handsSystem = default!; - [Dependency] private readonly SharedActionsSystem _actionsSystem = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; - [Dependency] private readonly IRobustRandom _robustRandom = default!; + [Dependency] private readonly InnateToolSystem _innateToolSystem = default!; public override void Initialize() { @@ -53,8 +46,6 @@ namespace Content.Server.Drone private void OnInteractionAttempt(EntityUid uid, DroneComponent component, InteractionAttemptEvent args) { - if (!component.ApplyLaws) - return; if (args.Target != null && !HasComp(args.Target) && NonDronesInRange(uid, component)) args.Cancel(); @@ -67,8 +58,6 @@ namespace Content.Server.Drone private void OnActivateUIAttempt(EntityUid uid, DroneComponent component, UserOpenActivatableUIAttemptEvent args) { - if (!component.ApplyLaws) - return; if (!_tagSystem.HasTag(args.Target, "DroneUsable")) { args.Cancel(); @@ -89,23 +78,13 @@ namespace Content.Server.Drone private void OnMobStateChanged(EntityUid uid, DroneComponent drone, MobStateChangedEvent args) { - if (args.Component.IsDead()) + if (args.CurrentMobState == DamageState.Dead) { - var body = Comp(uid); //There's no way something can have a mobstate but not a body... + if (TryComp(uid, out var innate)) + _innateToolSystem.Cleanup(uid, innate); - foreach (var item in drone.ToolUids) - { - if (_tagSystem.HasTag(item, "Drone")) - { - RemComp(item); - } - else - { - Del(item); - } - } - - body.Gib(); + if (TryComp(uid, out var body)) + body.Gib(); Del(uid); } } @@ -115,37 +94,6 @@ namespace Content.Server.Drone UpdateDroneAppearance(uid, DroneStatus.On); _popupSystem.PopupEntity(Loc.GetString("drone-activated"), uid, Filter.Pvs(uid), PopupType.Large); - - if (drone.AlreadyAwoken == false) - { - var spawnCoord = Transform(uid).Coordinates; - - if (drone.Tools.Count == 0) return; - - if (TryComp(uid, out var hands) && hands.Count >= drone.Tools.Count) - { - var items = EntitySpawnCollection.GetSpawns(drone.Tools, _robustRandom); - foreach (var entry in items) - { - var item = Spawn(entry, spawnCoord); - AddComp(item); - if (!_handsSystem.TryPickupAnyHand(uid, item, checkActionBlocker: false)) - { - QueueDel(item); - Logger.Error($"Drone ({ToPrettyString(uid)}) failed to pick up innate item ({ToPrettyString(item)})"); - continue; - } - drone.ToolUids.Add(item); - } - } - - if (TryComp(uid, out var actions) && TryComp(uid, out var flashlight)) - { - _actionsSystem.AddAction(uid, flashlight.ToggleAction, null, actions); - } - - drone.AlreadyAwoken = true; - } } private void OnMindRemoved(EntityUid uid, DroneComponent drone, MindRemovedMessage args) diff --git a/Content.Server/Light/EntitySystems/UnpoweredFlashlightSystem.cs b/Content.Server/Light/EntitySystems/UnpoweredFlashlightSystem.cs index 34295ab6b7..3759820550 100644 --- a/Content.Server/Light/EntitySystems/UnpoweredFlashlightSystem.cs +++ b/Content.Server/Light/EntitySystems/UnpoweredFlashlightSystem.cs @@ -1,5 +1,6 @@ using Content.Server.Light.Components; using Content.Server.Light.Events; +using Content.Server.Mind.Components; using Content.Shared.Actions; using Content.Shared.Light; using Content.Shared.Toggleable; @@ -21,6 +22,7 @@ namespace Content.Server.Light.EntitySystems SubscribeLocalEvent>(AddToggleLightVerbs); SubscribeLocalEvent(OnGetActions); SubscribeLocalEvent(OnToggleAction); + SubscribeLocalEvent(OnMindAdded); } private void OnToggleAction(EntityUid uid, UnpoweredFlashlightComponent component, ToggleActionEvent args) @@ -52,6 +54,10 @@ namespace Content.Server.Light.EntitySystems args.Verbs.Add(verb); } + private void OnMindAdded(EntityUid uid, UnpoweredFlashlightComponent component, MindAddedMessage args) + { + _actionsSystem.AddAction(uid, component.ToggleAction, null); + } public void ToggleLight(UnpoweredFlashlightComponent flashlight) { if (!EntityManager.TryGetComponent(flashlight.Owner, out PointLightComponent? light)) diff --git a/Content.Server/Tools/Innate/InnateToolComponent.cs b/Content.Server/Tools/Innate/InnateToolComponent.cs new file mode 100644 index 0000000000..2f4486e857 --- /dev/null +++ b/Content.Server/Tools/Innate/InnateToolComponent.cs @@ -0,0 +1,11 @@ +using Content.Shared.Storage; + +namespace Content.Server.Tools.Innate +{ + [RegisterComponent] + public sealed class InnateToolComponent : Component + { + [DataField("tools")] public List Tools = new(); + public List ToolUids = new(); + } +} diff --git a/Content.Server/Tools/Innate/InnateToolSystem.cs b/Content.Server/Tools/Innate/InnateToolSystem.cs new file mode 100644 index 0000000000..2129239349 --- /dev/null +++ b/Content.Server/Tools/Innate/InnateToolSystem.cs @@ -0,0 +1,91 @@ + +using Content.Shared.Interaction.Components; +using Content.Server.Hands.Components; +using Content.Shared.Hands.EntitySystems; +using Content.Shared.Storage; +using Content.Shared.Tag; +using Content.Shared.Destructible; +using Robust.Shared.Random; + +namespace Content.Server.Tools.Innate +{ + /// + /// Spawns a list unremovable tools in hands if possible. Used for drones, + /// borgs, or maybe even stuff like changeling armblades! + /// + 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() + { + base.Initialize(); + SubscribeLocalEvent(OnStartup); + SubscribeLocalEvent(OnShutdown); + SubscribeLocalEvent(OnDestroyed); + } + + private void OnStartup(EntityUid uid, InnateToolComponent component, ComponentStartup args) + { + if (component.Tools.Count == 0) + return; + + var spawnCoord = Transform(uid).Coordinates; + + if (TryComp(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(item); + if (!_sharedHandsSystem.TryPickupAnyHand(uid, item, checkActionBlocker: false)) + { + QueueDel(item); + continue; + } + component.ToolUids.Add(item); + } + } + } + + private void OnShutdown(EntityUid uid, InnateToolComponent component, ComponentShutdown args) + { + foreach (var tool in component.ToolUids) + { + RemComp(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) + { + if (_tagSystem.HasTag(tool, "InnateDontDelete")) + { + RemComp(tool); + } + else + { + Del(tool); + } + + if (TryComp(uid, out var hands)) + { + foreach (var hand in hands.Hands) + { + _sharedHandsSystem.TryDrop(uid, hand.Value, checkActionBlocker: false, handsComp: hands); + } + } + } + + component.ToolUids.Clear(); + } + } +} diff --git a/Content.Server/Weapon/Ranged/Systems/GunSystem.cs b/Content.Server/Weapon/Ranged/Systems/GunSystem.cs index 551b26fd48..a8183ba57a 100644 --- a/Content.Server/Weapon/Ranged/Systems/GunSystem.cs +++ b/Content.Server/Weapon/Ranged/Systems/GunSystem.cs @@ -234,6 +234,11 @@ public sealed partial class GunSystem : SharedGunSystem // 3. Nothing var playedSound = false; + // woops the other entity is deleted + // someone needs to handle this better. for now i'm just gonna make it not crash the server -rane + if (Deleted(otherEntity)) + return; + if (!forceWeaponSound && modifiedDamage != null && modifiedDamage.Total > 0 && TryComp(otherEntity, out var rangedSound)) { var type = MeleeWeaponSystem.GetHighestDamageSound(modifiedDamage, ProtoManager); diff --git a/Resources/Prototypes/Catalog/Fills/Backpacks/StarterGear/satchel.yml b/Resources/Prototypes/Catalog/Fills/Backpacks/StarterGear/satchel.yml index 2899ba405a..d43340abd0 100644 --- a/Resources/Prototypes/Catalog/Fills/Backpacks/StarterGear/satchel.yml +++ b/Resources/Prototypes/Catalog/Fills/Backpacks/StarterGear/satchel.yml @@ -124,4 +124,4 @@ components: - type: Tag tags: - - Drone + - InnateDontDelete diff --git a/Resources/Prototypes/Entities/Mobs/Player/silicon.yml b/Resources/Prototypes/Entities/Mobs/Player/silicon.yml index 0b7d670d38..cf2c79a7a7 100644 --- a/Resources/Prototypes/Entities/Mobs/Player/silicon.yml +++ b/Resources/Prototypes/Entities/Mobs/Player/silicon.yml @@ -71,6 +71,7 @@ parent: PlayerSiliconBase components: - type: Drone + - type: InnateTool tools: - id: ClothingBackpackSatchelDrone - id: trayScanner @@ -173,8 +174,7 @@ id: Onestar parent: PlayerSiliconBase components: - - type: Drone - applyLaws: false + - type: InnateTool tools: - id: WeaponMinigun - id: EnergySword @@ -188,7 +188,7 @@ makeSentient: true name: Onestar Mecha description: You are an experimental mecha created by who-knows-what, all you know is that you have weapons and you detect fleshy moving targets nearby... - rules: Use your weapons to cause havok. You are an antagonist. + rules: Use your weapons to cause havoc. You are an antagonist. - type: MovementSpeedModifier baseWalkSpeed : 3 baseSprintSpeed : 2 diff --git a/Resources/Prototypes/tags.yml b/Resources/Prototypes/tags.yml index 3ce890d3fe..9699750de1 100644 --- a/Resources/Prototypes/tags.yml +++ b/Resources/Prototypes/tags.yml @@ -165,9 +165,6 @@ - type: Tag id: Donut -- type: Tag - id: Drone - - type: Tag id: DroneUsable @@ -237,6 +234,9 @@ - type: Tag id: Hoe +- type: Tag #Drop this innate tool instead of deleting it. + id: InnateDontDelete + - type: Tag id: Ingot