Split various drone behaviors out of drone component (innate tool, unpowered flashlight) (#10474)
This commit is contained in:
@@ -1,21 +1,8 @@
|
||||
using Content.Shared.Storage;
|
||||
|
||||
namespace Content.Server.Drone.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class DroneComponent : Component
|
||||
{
|
||||
[DataField("tools")] public List<EntitySpawnEntry> Tools = new();
|
||||
public List<EntityUid> ToolUids = new();
|
||||
public bool AlreadyAwoken = false;
|
||||
public float InteractionBlockRange = 2.15f;
|
||||
|
||||
/// <summary>
|
||||
/// If you are using drone component for
|
||||
/// something that shouldn't have restrictions set this to
|
||||
/// false.
|
||||
/// </summary>
|
||||
[DataField("applyLaws")]
|
||||
public bool ApplyLaws = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<UnremoveableComponent>(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,22 +78,12 @@ 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<SharedBodyComponent>(uid); //There's no way something can have a mobstate but not a body...
|
||||
|
||||
foreach (var item in drone.ToolUids)
|
||||
{
|
||||
if (_tagSystem.HasTag(item, "Drone"))
|
||||
{
|
||||
RemComp<UnremoveableComponent>(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
Del(item);
|
||||
}
|
||||
}
|
||||
if (TryComp<InnateToolComponent>(uid, out var innate))
|
||||
_innateToolSystem.Cleanup(uid, innate);
|
||||
|
||||
if (TryComp<SharedBodyComponent>(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<HandsComponent>(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<UnremoveableComponent>(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<ActionsComponent>(uid, out var actions) && TryComp<UnpoweredFlashlightComponent>(uid, out var flashlight))
|
||||
{
|
||||
_actionsSystem.AddAction(uid, flashlight.ToggleAction, null, actions);
|
||||
}
|
||||
|
||||
drone.AlreadyAwoken = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMindRemoved(EntityUid uid, DroneComponent drone, MindRemovedMessage args)
|
||||
|
||||
@@ -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<UnpoweredFlashlightComponent, GetVerbsEvent<ActivationVerb>>(AddToggleLightVerbs);
|
||||
SubscribeLocalEvent<UnpoweredFlashlightComponent, GetItemActionsEvent>(OnGetActions);
|
||||
SubscribeLocalEvent<UnpoweredFlashlightComponent, ToggleActionEvent>(OnToggleAction);
|
||||
SubscribeLocalEvent<UnpoweredFlashlightComponent, MindAddedMessage>(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))
|
||||
|
||||
11
Content.Server/Tools/Innate/InnateToolComponent.cs
Normal file
11
Content.Server/Tools/Innate/InnateToolComponent.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Content.Shared.Storage;
|
||||
|
||||
namespace Content.Server.Tools.Innate
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class InnateToolComponent : Component
|
||||
{
|
||||
[DataField("tools")] public List<EntitySpawnEntry> Tools = new();
|
||||
public List<EntityUid> ToolUids = new();
|
||||
}
|
||||
}
|
||||
91
Content.Server/Tools/Innate/InnateToolSystem.cs
Normal file
91
Content.Server/Tools/Innate/InnateToolSystem.cs
Normal file
@@ -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
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<InnateToolComponent, ComponentStartup>(OnStartup);
|
||||
SubscribeLocalEvent<InnateToolComponent, ComponentShutdown>(OnShutdown);
|
||||
SubscribeLocalEvent<InnateToolComponent, DestructionEventArgs>(OnDestroyed);
|
||||
}
|
||||
|
||||
private void OnStartup(EntityUid uid, InnateToolComponent component, ComponentStartup args)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnShutdown(EntityUid uid, InnateToolComponent component, ComponentShutdown args)
|
||||
{
|
||||
foreach (var tool in component.ToolUids)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
component.ToolUids.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<RangedDamageSoundComponent>(otherEntity, out var rangedSound))
|
||||
{
|
||||
var type = MeleeWeaponSystem.GetHighestDamageSound(modifiedDamage, ProtoManager);
|
||||
|
||||
@@ -124,4 +124,4 @@
|
||||
components:
|
||||
- type: Tag
|
||||
tags:
|
||||
- Drone
|
||||
- InnateDontDelete
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user