52
Content.Shared/Anomaly/Components/AnomalyCoreComponent.cs
Normal file
52
Content.Shared/Anomaly/Components/AnomalyCoreComponent.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
|
||||
namespace Content.Shared.Anomaly.Components;
|
||||
|
||||
/// <summary>
|
||||
/// This component exists for a limited time, and after it expires it modifies the entity, greatly reducing its value and changing its visuals
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent, Access(typeof(SharedAnomalyCoreSystem))]
|
||||
[AutoGenerateComponentState]
|
||||
public sealed partial class AnomalyCoreComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Amount of time required for the core to decompose into an inert core
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public double TimeToDecay = 600;
|
||||
|
||||
/// <summary>
|
||||
/// The moment of core decay. It is set during entity initialization.
|
||||
/// </summary>
|
||||
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
|
||||
[AutoNetworkedField]
|
||||
public TimeSpan DecayMoment;
|
||||
|
||||
/// <summary>
|
||||
/// The starting value of the entity.
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public double StartPrice = 10000;
|
||||
|
||||
/// <summary>
|
||||
/// The value of the object sought during decaying
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public double EndPrice = 200;
|
||||
|
||||
/// <summary>
|
||||
/// Has the core decayed?
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
[AutoNetworkedField]
|
||||
public bool IsDecayed;
|
||||
|
||||
/// <summary>
|
||||
/// The amount of GORILLA charges the core has.
|
||||
/// Not used when <see cref="IsDecayed"/> is false.
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
[AutoNetworkedField]
|
||||
public int Charge = 5;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Numerics;
|
||||
using Content.Shared.Weapons.Melee.Components;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Anomaly.Components;
|
||||
|
||||
/// <summary>
|
||||
/// This is used for an entity with <see cref="MeleeThrowOnHitComponent"/> that is governed by an anomaly core inside of it.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
[Access(typeof(SharedAnomalyCoreSystem))]
|
||||
public sealed partial class CorePoweredThrowerComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The ID of the item slot containing the core.
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public string CoreSlotId = "core_slot";
|
||||
|
||||
/// <summary>
|
||||
/// A range for how much the stability variable on the anomaly will increase with each throw.
|
||||
/// </summary>
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public Vector2 StabilityPerThrow = new(0.1f, 0.2f);
|
||||
}
|
||||
112
Content.Shared/Anomaly/SharedAnomalyCoreSystem.cs
Normal file
112
Content.Shared/Anomaly/SharedAnomalyCoreSystem.cs
Normal file
@@ -0,0 +1,112 @@
|
||||
using Content.Shared.Anomaly.Components;
|
||||
using Content.Shared.Construction.Components;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Weapons.Melee.Components;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared.Anomaly;
|
||||
|
||||
/// <summary>
|
||||
/// This component reduces the value of the entity during decay
|
||||
/// </summary>
|
||||
public sealed class SharedAnomalyCoreSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly ItemSlotsSystem _itemSlots = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<AnomalyCoreComponent, MapInitEvent>(OnMapInit);
|
||||
SubscribeLocalEvent<CorePoweredThrowerComponent, AttemptMeleeThrowOnHitEvent>(OnAttemptMeleeThrowOnHit);
|
||||
SubscribeLocalEvent<CorePoweredThrowerComponent, ExaminedEvent>(OnCorePoweredExamined);
|
||||
}
|
||||
|
||||
private void OnMapInit(Entity<AnomalyCoreComponent> core, ref MapInitEvent args)
|
||||
{
|
||||
core.Comp.DecayMoment = _gameTiming.CurTime + TimeSpan.FromSeconds(core.Comp.TimeToDecay);
|
||||
Dirty(core, core.Comp);
|
||||
}
|
||||
|
||||
private void OnAttemptMeleeThrowOnHit(Entity<CorePoweredThrowerComponent> ent, ref AttemptMeleeThrowOnHitEvent args)
|
||||
{
|
||||
var (uid, comp) = ent;
|
||||
|
||||
// don't waste charges on non-anchorable non-anomalous static bodies.
|
||||
if (!HasComp<AnomalyComponent>(args.Hit)
|
||||
&& !HasComp<AnchorableComponent>(args.Hit)
|
||||
&& TryComp<PhysicsComponent>(args.Hit, out var body)
|
||||
&& body.BodyType == BodyType.Static)
|
||||
return;
|
||||
|
||||
args.Cancelled = true;
|
||||
args.Handled = true;
|
||||
|
||||
if (!_itemSlots.TryGetSlot(uid, comp.CoreSlotId, out var slot))
|
||||
return;
|
||||
|
||||
if (!TryComp<AnomalyCoreComponent>(slot.Item, out var coreComponent))
|
||||
return;
|
||||
|
||||
if (coreComponent.IsDecayed)
|
||||
{
|
||||
if (coreComponent.Charge <= 0)
|
||||
return;
|
||||
args.Cancelled = false;
|
||||
coreComponent.Charge--;
|
||||
}
|
||||
else
|
||||
{
|
||||
args.Cancelled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCorePoweredExamined(Entity<CorePoweredThrowerComponent> ent, ref ExaminedEvent args)
|
||||
{
|
||||
var (uid, comp) = ent;
|
||||
if (!args.IsInDetailsRange)
|
||||
return;
|
||||
|
||||
if (!_itemSlots.TryGetSlot(uid, comp.CoreSlotId, out var slot) ||
|
||||
!TryComp<AnomalyCoreComponent>(slot.Item, out var coreComponent))
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("anomaly-gorilla-charge-none"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (coreComponent.IsDecayed)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("anomaly-gorilla-charge-limit", ("count", coreComponent.Charge)));
|
||||
}
|
||||
else
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("anomaly-gorilla-charge-infinite"));
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
var query = EntityQueryEnumerator<AnomalyCoreComponent>();
|
||||
while (query.MoveNext(out var uid, out var component))
|
||||
{
|
||||
if (component.IsDecayed)
|
||||
continue;
|
||||
|
||||
//When time runs out, we completely decompose
|
||||
if (component.DecayMoment < _gameTiming.CurTime)
|
||||
Decay(uid, component);
|
||||
}
|
||||
}
|
||||
|
||||
private void Decay(EntityUid uid, AnomalyCoreComponent component)
|
||||
{
|
||||
_appearance.SetData(uid, AnomalyCoreVisuals.Decaying, false);
|
||||
component.IsDecayed = true;
|
||||
Dirty(uid, component);
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,13 @@ using Content.Shared.Damage;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Weapons.Melee.Components;
|
||||
using Content.Shared.Weapons.Melee.Events;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
@@ -23,6 +26,7 @@ public abstract class SharedAnomalySystem : EntitySystem
|
||||
[Dependency] private readonly DamageableSystem _damageable = default!;
|
||||
[Dependency] protected readonly SharedAudioSystem Audio = default!;
|
||||
[Dependency] protected readonly SharedAppearanceSystem Appearance = default!;
|
||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||
[Dependency] protected readonly SharedPopupSystem Popup = default!;
|
||||
|
||||
private ISawmill _sawmill = default!;
|
||||
@@ -33,6 +37,8 @@ public abstract class SharedAnomalySystem : EntitySystem
|
||||
|
||||
SubscribeLocalEvent<AnomalyComponent, InteractHandEvent>(OnInteractHand);
|
||||
SubscribeLocalEvent<AnomalyComponent, AttackedEvent>(OnAttacked);
|
||||
SubscribeLocalEvent<AnomalyComponent, MeleeThrowOnHitStartEvent>(OnAnomalyThrowStart);
|
||||
SubscribeLocalEvent<AnomalyComponent, MeleeThrowOnHitEndEvent>(OnAnomalyThrowEnd);
|
||||
|
||||
SubscribeLocalEvent<AnomalyComponent, EntityUnpausedEvent>(OnAnomalyUnpause);
|
||||
SubscribeLocalEvent<AnomalyPulsingComponent, EntityUnpausedEvent>(OnPulsingUnpause);
|
||||
@@ -49,9 +55,25 @@ public abstract class SharedAnomalySystem : EntitySystem
|
||||
|
||||
private void OnAttacked(EntityUid uid, AnomalyComponent component, AttackedEvent args)
|
||||
{
|
||||
if (HasComp<CorePoweredThrowerComponent>(args.Used))
|
||||
return;
|
||||
|
||||
DoAnomalyBurnDamage(uid, args.User, component);
|
||||
}
|
||||
|
||||
private void OnAnomalyThrowStart(Entity<AnomalyComponent> ent, ref MeleeThrowOnHitStartEvent args)
|
||||
{
|
||||
if (!TryComp<CorePoweredThrowerComponent>(args.Used, out var corePowered) || !TryComp<PhysicsComponent>(ent, out var body))
|
||||
return;
|
||||
_physics.SetBodyType(ent, BodyType.Dynamic, body: body);
|
||||
ChangeAnomalyStability(ent, Random.NextFloat(corePowered.StabilityPerThrow.X, corePowered.StabilityPerThrow.Y), ent.Comp);
|
||||
}
|
||||
|
||||
private void OnAnomalyThrowEnd(Entity<AnomalyComponent> ent, ref MeleeThrowOnHitEndEvent args)
|
||||
{
|
||||
_physics.SetBodyType(ent, BodyType.Static);
|
||||
}
|
||||
|
||||
public void DoAnomalyBurnDamage(EntityUid source, EntityUid target, AnomalyComponent component)
|
||||
{
|
||||
_damageable.TryChangeDamage(target, component.AnomalyContactDamage, true);
|
||||
@@ -111,7 +133,7 @@ public abstract class SharedAnomalySystem : EntitySystem
|
||||
var pulse = EnsureComp<AnomalyPulsingComponent>(uid);
|
||||
pulse.EndTime = Timing.CurTime + pulse.PulseDuration;
|
||||
Appearance.SetData(uid, AnomalyVisuals.IsPulsing, true);
|
||||
|
||||
|
||||
var ev = new AnomalyPulseEvent(uid, component.Stability, component.Severity);
|
||||
RaiseLocalEvent(uid, ref ev, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user