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
|
namespace Content.Server.Drone.Components
|
||||||
{
|
{
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public sealed class DroneComponent : Component
|
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;
|
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.Shared.Drone;
|
||||||
using Content.Server.Drone.Components;
|
using Content.Server.Drone.Components;
|
||||||
using Content.Shared.Actions;
|
|
||||||
using Content.Server.Light.Components;
|
|
||||||
using Content.Shared.MobState;
|
using Content.Shared.MobState;
|
||||||
using Content.Shared.MobState.Components;
|
using Content.Shared.MobState.Components;
|
||||||
using Content.Shared.Interaction.Events;
|
using Content.Shared.Interaction.Events;
|
||||||
@@ -12,19 +10,16 @@ using Content.Shared.Throwing;
|
|||||||
using Content.Shared.Item;
|
using Content.Shared.Item;
|
||||||
using Content.Shared.Emoting;
|
using Content.Shared.Emoting;
|
||||||
using Content.Shared.Body.Components;
|
using Content.Shared.Body.Components;
|
||||||
|
using Content.Shared.IdentityManagement;
|
||||||
|
using Content.Shared.Popups;
|
||||||
using Content.Server.Popups;
|
using Content.Server.Popups;
|
||||||
using Content.Server.Mind.Components;
|
using Content.Server.Mind.Components;
|
||||||
using Content.Server.Ghost.Components;
|
using Content.Server.Ghost.Components;
|
||||||
using Content.Server.Ghost.Roles.Components;
|
using Content.Server.Ghost.Roles.Components;
|
||||||
using Content.Server.Hands.Components;
|
using Content.Server.Tools.Innate;
|
||||||
using Content.Server.UserInterface;
|
using Content.Server.UserInterface;
|
||||||
using Robust.Shared.Player;
|
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 Robust.Shared.Timing;
|
||||||
using Content.Shared.IdentityManagement;
|
|
||||||
|
|
||||||
namespace Content.Server.Drone
|
namespace Content.Server.Drone
|
||||||
{
|
{
|
||||||
@@ -33,10 +28,8 @@ namespace Content.Server.Drone
|
|||||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||||
[Dependency] private readonly TagSystem _tagSystem = default!;
|
[Dependency] private readonly TagSystem _tagSystem = default!;
|
||||||
[Dependency] private readonly EntityLookupSystem _lookup = 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 IGameTiming _gameTiming = default!;
|
||||||
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
[Dependency] private readonly InnateToolSystem _innateToolSystem = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
@@ -53,8 +46,6 @@ namespace Content.Server.Drone
|
|||||||
|
|
||||||
private void OnInteractionAttempt(EntityUid uid, DroneComponent component, InteractionAttemptEvent args)
|
private void OnInteractionAttempt(EntityUid uid, DroneComponent component, InteractionAttemptEvent args)
|
||||||
{
|
{
|
||||||
if (!component.ApplyLaws)
|
|
||||||
return;
|
|
||||||
if (args.Target != null && !HasComp<UnremoveableComponent>(args.Target) && NonDronesInRange(uid, component))
|
if (args.Target != null && !HasComp<UnremoveableComponent>(args.Target) && NonDronesInRange(uid, component))
|
||||||
args.Cancel();
|
args.Cancel();
|
||||||
|
|
||||||
@@ -67,8 +58,6 @@ namespace Content.Server.Drone
|
|||||||
|
|
||||||
private void OnActivateUIAttempt(EntityUid uid, DroneComponent component, UserOpenActivatableUIAttemptEvent args)
|
private void OnActivateUIAttempt(EntityUid uid, DroneComponent component, UserOpenActivatableUIAttemptEvent args)
|
||||||
{
|
{
|
||||||
if (!component.ApplyLaws)
|
|
||||||
return;
|
|
||||||
if (!_tagSystem.HasTag(args.Target, "DroneUsable"))
|
if (!_tagSystem.HasTag(args.Target, "DroneUsable"))
|
||||||
{
|
{
|
||||||
args.Cancel();
|
args.Cancel();
|
||||||
@@ -89,22 +78,12 @@ namespace Content.Server.Drone
|
|||||||
|
|
||||||
private void OnMobStateChanged(EntityUid uid, DroneComponent drone, MobStateChangedEvent args)
|
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...
|
if (TryComp<InnateToolComponent>(uid, out var innate))
|
||||||
|
_innateToolSystem.Cleanup(uid, innate);
|
||||||
foreach (var item in drone.ToolUids)
|
|
||||||
{
|
|
||||||
if (_tagSystem.HasTag(item, "Drone"))
|
|
||||||
{
|
|
||||||
RemComp<UnremoveableComponent>(item);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Del(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (TryComp<SharedBodyComponent>(uid, out var body))
|
||||||
body.Gib();
|
body.Gib();
|
||||||
Del(uid);
|
Del(uid);
|
||||||
}
|
}
|
||||||
@@ -115,37 +94,6 @@ namespace Content.Server.Drone
|
|||||||
UpdateDroneAppearance(uid, DroneStatus.On);
|
UpdateDroneAppearance(uid, DroneStatus.On);
|
||||||
_popupSystem.PopupEntity(Loc.GetString("drone-activated"), uid,
|
_popupSystem.PopupEntity(Loc.GetString("drone-activated"), uid,
|
||||||
Filter.Pvs(uid), PopupType.Large);
|
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)
|
private void OnMindRemoved(EntityUid uid, DroneComponent drone, MindRemovedMessage args)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Content.Server.Light.Components;
|
using Content.Server.Light.Components;
|
||||||
using Content.Server.Light.Events;
|
using Content.Server.Light.Events;
|
||||||
|
using Content.Server.Mind.Components;
|
||||||
using Content.Shared.Actions;
|
using Content.Shared.Actions;
|
||||||
using Content.Shared.Light;
|
using Content.Shared.Light;
|
||||||
using Content.Shared.Toggleable;
|
using Content.Shared.Toggleable;
|
||||||
@@ -21,6 +22,7 @@ namespace Content.Server.Light.EntitySystems
|
|||||||
SubscribeLocalEvent<UnpoweredFlashlightComponent, GetVerbsEvent<ActivationVerb>>(AddToggleLightVerbs);
|
SubscribeLocalEvent<UnpoweredFlashlightComponent, GetVerbsEvent<ActivationVerb>>(AddToggleLightVerbs);
|
||||||
SubscribeLocalEvent<UnpoweredFlashlightComponent, GetItemActionsEvent>(OnGetActions);
|
SubscribeLocalEvent<UnpoweredFlashlightComponent, GetItemActionsEvent>(OnGetActions);
|
||||||
SubscribeLocalEvent<UnpoweredFlashlightComponent, ToggleActionEvent>(OnToggleAction);
|
SubscribeLocalEvent<UnpoweredFlashlightComponent, ToggleActionEvent>(OnToggleAction);
|
||||||
|
SubscribeLocalEvent<UnpoweredFlashlightComponent, MindAddedMessage>(OnMindAdded);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnToggleAction(EntityUid uid, UnpoweredFlashlightComponent component, ToggleActionEvent args)
|
private void OnToggleAction(EntityUid uid, UnpoweredFlashlightComponent component, ToggleActionEvent args)
|
||||||
@@ -52,6 +54,10 @@ namespace Content.Server.Light.EntitySystems
|
|||||||
args.Verbs.Add(verb);
|
args.Verbs.Add(verb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnMindAdded(EntityUid uid, UnpoweredFlashlightComponent component, MindAddedMessage args)
|
||||||
|
{
|
||||||
|
_actionsSystem.AddAction(uid, component.ToggleAction, null);
|
||||||
|
}
|
||||||
public void ToggleLight(UnpoweredFlashlightComponent flashlight)
|
public void ToggleLight(UnpoweredFlashlightComponent flashlight)
|
||||||
{
|
{
|
||||||
if (!EntityManager.TryGetComponent(flashlight.Owner, out PointLightComponent? light))
|
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
|
// 3. Nothing
|
||||||
var playedSound = false;
|
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))
|
if (!forceWeaponSound && modifiedDamage != null && modifiedDamage.Total > 0 && TryComp<RangedDamageSoundComponent>(otherEntity, out var rangedSound))
|
||||||
{
|
{
|
||||||
var type = MeleeWeaponSystem.GetHighestDamageSound(modifiedDamage, ProtoManager);
|
var type = MeleeWeaponSystem.GetHighestDamageSound(modifiedDamage, ProtoManager);
|
||||||
|
|||||||
@@ -124,4 +124,4 @@
|
|||||||
components:
|
components:
|
||||||
- type: Tag
|
- type: Tag
|
||||||
tags:
|
tags:
|
||||||
- Drone
|
- InnateDontDelete
|
||||||
|
|||||||
@@ -71,6 +71,7 @@
|
|||||||
parent: PlayerSiliconBase
|
parent: PlayerSiliconBase
|
||||||
components:
|
components:
|
||||||
- type: Drone
|
- type: Drone
|
||||||
|
- type: InnateTool
|
||||||
tools:
|
tools:
|
||||||
- id: ClothingBackpackSatchelDrone
|
- id: ClothingBackpackSatchelDrone
|
||||||
- id: trayScanner
|
- id: trayScanner
|
||||||
@@ -173,8 +174,7 @@
|
|||||||
id: Onestar
|
id: Onestar
|
||||||
parent: PlayerSiliconBase
|
parent: PlayerSiliconBase
|
||||||
components:
|
components:
|
||||||
- type: Drone
|
- type: InnateTool
|
||||||
applyLaws: false
|
|
||||||
tools:
|
tools:
|
||||||
- id: WeaponMinigun
|
- id: WeaponMinigun
|
||||||
- id: EnergySword
|
- id: EnergySword
|
||||||
@@ -188,7 +188,7 @@
|
|||||||
makeSentient: true
|
makeSentient: true
|
||||||
name: Onestar Mecha
|
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...
|
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
|
- type: MovementSpeedModifier
|
||||||
baseWalkSpeed : 3
|
baseWalkSpeed : 3
|
||||||
baseSprintSpeed : 2
|
baseSprintSpeed : 2
|
||||||
|
|||||||
@@ -165,9 +165,6 @@
|
|||||||
- type: Tag
|
- type: Tag
|
||||||
id: Donut
|
id: Donut
|
||||||
|
|
||||||
- type: Tag
|
|
||||||
id: Drone
|
|
||||||
|
|
||||||
- type: Tag
|
- type: Tag
|
||||||
id: DroneUsable
|
id: DroneUsable
|
||||||
|
|
||||||
@@ -237,6 +234,9 @@
|
|||||||
- type: Tag
|
- type: Tag
|
||||||
id: Hoe
|
id: Hoe
|
||||||
|
|
||||||
|
- type: Tag #Drop this innate tool instead of deleting it.
|
||||||
|
id: InnateDontDelete
|
||||||
|
|
||||||
- type: Tag
|
- type: Tag
|
||||||
id: Ingot
|
id: Ingot
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user