forked from space-wizards/space-station-14
-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1106 from TheGrimbeeper/artifacts
Artifacts can now make items attack you
- Loading branch information
Showing
5 changed files
with
92 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
.../_Impstation/Xenoarchaeology/XenoArtifacts/Effects/Components/AnimateArtifactComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components; | ||
|
||
/// <summary> | ||
/// Animates a number of entities within a range for a duration. Animated objects attack nearby beings. | ||
/// </summary> | ||
[RegisterComponent] | ||
public sealed partial class AnimateArtifactComponent : Component | ||
{ | ||
/// <summary> | ||
/// Distance from the artifact to animate objects | ||
/// </summary> | ||
[DataField("range"), ViewVariables(VVAccess.ReadWrite)] | ||
public float Range = 6f; | ||
|
||
/// <summary> | ||
/// Duration of the animation. | ||
/// </summary> | ||
[DataField("duration"), ViewVariables(VVAccess.ReadWrite)] | ||
public float Duration = 15f; | ||
|
||
/// <summary> | ||
/// Number of objects to animate | ||
/// </summary> | ||
[DataField("count"), ViewVariables(VVAccess.ReadWrite)] | ||
public int Count = 1; | ||
} |
52 changes: 52 additions & 0 deletions
52
...Server/_Impstation/Xenoarchaeology/XenoArtifacts/Effects/Systems/AnimateArtifactSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components; | ||
using Content.Server.Xenoarchaeology.XenoArtifacts.Events; | ||
using Content.Server.Revenant.EntitySystems; | ||
using Content.Shared.Item; | ||
using System.Linq; | ||
using Robust.Shared.Random; | ||
using Robust.Shared.Containers; | ||
|
||
namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Systems; | ||
|
||
public sealed class AnimateArtifactSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly EntityLookupSystem _lookup = default!; | ||
[Dependency] private readonly IRobustRandom _random = default!; | ||
[Dependency] private readonly RevenantAnimatedSystem _revenantAnimated = default!; | ||
[Dependency] private readonly SharedContainerSystem _container = default!; | ||
|
||
|
||
/// <inheritdoc/> | ||
public override void Initialize() | ||
{ | ||
SubscribeLocalEvent<AnimateArtifactComponent, ArtifactActivatedEvent>(OnActivated); | ||
} | ||
|
||
private void OnActivated(EntityUid uid, AnimateArtifactComponent component, ArtifactActivatedEvent args) | ||
{ | ||
// Get a list of all nearby objects in range | ||
|
||
var entsHash = _lookup.GetEntitiesInRange(uid, component.Range); | ||
entsHash.Add(uid); | ||
var numSuccessfulAnimates = 0; | ||
|
||
var unshuffledEnts = entsHash.ToList(); | ||
var ents = unshuffledEnts.OrderBy(_ => _random.Next()).ToList(); | ||
|
||
foreach (var ent in ents) | ||
{ | ||
if (numSuccessfulAnimates >= component.Count) | ||
{ | ||
break; | ||
} | ||
// need to only get items not in a container | ||
if (HasComp<ItemComponent>(ent) && _revenantAnimated.CanAnimateObject(ent) && !_container.IsEntityInContainer(ent)) | ||
{ | ||
if (_revenantAnimated.TryAnimateObject(ent, TimeSpan.FromSeconds(component.Duration))) | ||
{ | ||
numSuccessfulAnimates += 1; | ||
} | ||
} | ||
} | ||
} | ||
} |
4 changes: 0 additions & 4 deletions
4
...rver/_Impstation/Xenoarchaeology/XenoArtifacts/Effects/Systems/KnockdownArtifactSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters