Skip to content

Commit

Permalink
Merge pull request #1106 from TheGrimbeeper/artifacts
Browse files Browse the repository at this point in the history
Artifacts can now make items attack you
  • Loading branch information
Darkmajia authored Dec 24, 2024
2 parents 00288db + dfa73db commit 42b8ff4
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using Content.Shared.Mobs.Systems;
using Content.Shared.Mobs;
using Robust.Shared.Timing;
using Content.Shared.Construction.Components;

namespace Content.Server.Revenant.EntitySystems;

Expand Down Expand Up @@ -176,7 +177,8 @@ private void OnMobStateChange(Entity<RevenantAnimatedComponent> ent, ref MobStat

public bool CanAnimateObject(EntityUid target)
{
return !(HasComp<MindContainerComponent>(target) || HasComp<HTNComponent>(target) || HasComp<RevenantAnimatedComponent>(target));
return !(HasComp<AnchorableComponent>(target) || HasComp<MindContainerComponent>(target)
|| HasComp<HTNComponent>(target) || HasComp<RevenantAnimatedComponent>(target));
}

public bool TryAnimateObject(EntityUid target, TimeSpan? duration = null, Entity<RevenantComponent>? revenant = null)
Expand Down
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;
}
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;
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components;
using Content.Shared.Buckle.Components;
using Content.Server.Xenoarchaeology.XenoArtifacts.Events;
using Content.Shared.Maps;
using Content.Shared.Throwing;
using Robust.Server.GameObjects;
using Robust.Shared.Random;
using Content.Shared.StatusEffect;
using Content.Server.Stunnable;

Expand Down
11 changes: 11 additions & 0 deletions Resources/Prototypes/XenoArch/Effects/normal_effects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,17 @@
knockdownTime: 2.5
range: 15

- type: artifactEffect
id: EffectAnimateSingle
targetDepth: 4
effectHint: artifact-effect-hint-sentience
effectProb: 0.5
components:
- type: AnimateArtifact
range: 6
duration: 10
count: 1

- type: artifactEffect
id: EffectSingulo
targetDepth: 10
Expand Down

0 comments on commit 42b8ff4

Please sign in to comment.