Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chitinid (From Delta-V) #1644

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Content.Server/Chemistry/EntitySystems/InjectorSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Server.Abilities.Chitinid;
using Content.Server.Body.Components;
using Content.Server.Body.Systems;
using Content.Shared.Chemistry;
Expand Down Expand Up @@ -114,6 +115,12 @@ private void OnInjectorAfterInteract(Entity<InjectorComponent> entity, ref After
/// </summary>
private void InjectDoAfter(Entity<InjectorComponent> injector, EntityUid target, EntityUid user)
{
if (HasComp<BlockInjectionComponent>(target)) // DeltaV
{
Popup.PopupEntity(Loc.GetString("injector-component-deny-user"), target, user);
return;
}

// Create a pop-up for the user
if (injector.Comp.ToggleState == InjectorToggleMode.Draw)
{
Expand Down Expand Up @@ -254,6 +261,9 @@ private void TryInjectIntoBloodstream(Entity<InjectorComponent> injector, Entity
private void TryInject(Entity<InjectorComponent> injector, EntityUid targetEntity,
Entity<SolutionComponent> targetSolution, EntityUid user, bool asRefill)
{
if (HasComp<BlockInjectionComponent>(targetEntity)) // DeltaV
return;

if (!SolutionContainers.TryGetSolution(injector.Owner, injector.Comp.SolutionName, out var soln,
out var solution) || solution.Volume == 0)
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Content.Server.Administration.Logs;
using Content.Server.Construction.Components;
using Content.Server.Temperature.Components;
using Content.Server.Temperature.Systems;
using Content.Shared.Construction;
using Content.Shared.Construction.Components;
using Content.Shared.Construction.EntitySystems;
Expand All @@ -11,6 +10,7 @@
using Content.Shared.Interaction;
using Content.Shared.Prying.Systems;
using Content.Shared.Radio.EntitySystems;
using Content.Shared.Temperature;
using Content.Shared.Tools.Systems;
using Robust.Shared.Containers;
using Robust.Shared.Utility;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private void CookItem(EntityUid uid, DeepFryerComponent component, EntityUid ite
if (TryComp<TemperatureComponent>(item, out var tempComp))
{
// Push the temperature towards what it should be but no higher.
var delta = (component.PoweredTemperature - tempComp.CurrentTemperature) * tempComp.HeatCapacity;
var delta = (component.PoweredTemperature - tempComp.CurrentTemperature) * _temperature.GetHeatCapacity(item, tempComp);

if (delta > 0f)
_temperature.ChangeHeat(item, delta, false, tempComp);
Expand Down
14 changes: 2 additions & 12 deletions Content.Server/Temperature/Components/TemperatureComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Content.Server.Temperature.Systems;
using Content.Shared.Alert;
using Content.Shared.Atmos;
using Content.Shared.Damage;
Expand Down Expand Up @@ -51,15 +50,6 @@ public sealed partial class TemperatureComponent : Component
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float AtmosTemperatureTransferEfficiency = 0.1f;

[Obsolete("Use system method")]
public float HeatCapacity
{
get
{
return IoCManager.Resolve<IEntityManager>().System<TemperatureSystem>().GetHeatCapacity(Owner, this);
}
}

[DataField, ViewVariables(VVAccess.ReadWrite)]
public DamageSpecifier ColdDamage = new();

Expand All @@ -71,15 +61,15 @@ public float HeatCapacity
/// </summary>
/// <remarks>
/// Okay it genuinely reaches this basically immediately for a plasma fire.
/// </summary>
/// </remarks>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public FixedPoint2 DamageCap = FixedPoint2.New(8);

/// <summary>
/// Used to keep track of when damage starts/stops. Useful for logs.
/// </summary>
[DataField]
public bool TakingDamage = false;
public bool TakingDamage;

[DataField]
public ProtoId<AlertPrototype> HotAlert = "Hot";
Expand Down
14 changes: 0 additions & 14 deletions Content.Server/Temperature/Systems/TemperatureSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,17 +414,3 @@ private void RecalculateAndApplyParentThresholds(EntityUid uid,
return (newHeatThreshold, newColdThreshold);
}
}

public sealed class OnTemperatureChangeEvent : EntityEventArgs
{
public float CurrentTemperature { get; }
public float LastTemperature { get; }
public float TemperatureDelta { get; }

public OnTemperatureChangeEvent(float current, float last, float delta)
{
CurrentTemperature = current;
LastTemperature = last;
TemperatureDelta = delta;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace Content.Server.Abilities.Chitinid;

[RegisterComponent]
public sealed partial class BlockInjectionComponent : Component;
41 changes: 41 additions & 0 deletions Content.Server/_DV/Abilities/Chitinid/ChitinidComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
using Content.Shared.FixedPoint;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;

namespace Content.Server.Abilities.Chitinid;

[RegisterComponent]
public sealed partial class ChitinidComponent : Component
{
[DataField]
public EntProtoId ChitzitePrototype = "Chitzite";

[DataField]
public EntProtoId ChitziteActionId = "ActionChitzite";

[DataField]
public EntityUid? ChitziteAction;

[DataField]
public FixedPoint2 AmountAbsorbed = 0f;

[DataField]
public DamageSpecifier Healing = new()
{
DamageDict = new()
{
{ "Radiation", -0.5 },
}
};

[DataField]
public FixedPoint2 MaximumAbsorbed = 30f;

[DataField]
public TimeSpan UpdateInterval = TimeSpan.FromSeconds(1);

[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan NextUpdate;
}
97 changes: 97 additions & 0 deletions Content.Server/_DV/Abilities/Chitinid/ChitinidSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using Content.Server.Nutrition.Components;
using Content.Shared.Actions;
using Content.Shared.Actions.Events;
using Content.Shared.Audio;
using Content.Shared.Damage;
using Content.Shared.IdentityManagement;
using Content.Shared.Inventory;
using Content.Shared.Mobs.Systems;
using Content.Shared.Popups;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;

namespace Content.Server.Abilities.Chitinid;

public sealed partial class ChitinidSystem : EntitySystem
{
[Dependency] private readonly SharedActionsSystem _actions = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly DamageableSystem _damageable = default!;
[Dependency] private readonly MobStateSystem _mobState = default!;

public override void Initialize()
{
SubscribeLocalEvent<ChitinidComponent, ChitziteActionEvent>(OnChitzite);
SubscribeLocalEvent<ChitinidComponent, MapInitEvent>(OnMapInit);
}

public override void Update(float frameTime)
{
base.Update(frameTime);
var query = EntityQueryEnumerator<ChitinidComponent, DamageableComponent>();
while (query.MoveNext(out var uid, out var chitinid, out var damageable))
{
if (_timing.CurTime < chitinid.NextUpdate)
continue;

chitinid.NextUpdate += chitinid.UpdateInterval;

if (chitinid.AmountAbsorbed >= chitinid.MaximumAbsorbed || _mobState.IsDead(uid))
continue;

if (_damageable.TryChangeDamage(uid, chitinid.Healing, damageable: damageable) is {} delta)
{
chitinid.AmountAbsorbed += -delta.GetTotal().Float();
if (chitinid.ChitziteAction != null && chitinid.AmountAbsorbed >= chitinid.MaximumAbsorbed)
{
_actions.SetCharges(chitinid.ChitziteAction, 1); // You get the charge back and that's it. Tough.
_actions.SetEnabled(chitinid.ChitziteAction, true);
}
}
}

var entQuery = EntityQueryEnumerator<CoughingUpChitziteComponent, ChitinidComponent>();
while (entQuery.MoveNext(out var ent, out var chitzite, out var chitinid))
{
if (_timing.CurTime < chitzite.NextCough)
continue;

Spawn(chitinid.ChitzitePrototype, Transform(ent).Coordinates);
chitinid.AmountAbsorbed = 0f;
RemCompDeferred(ent, chitzite);
}
}

private void OnMapInit(Entity<ChitinidComponent> ent, ref MapInitEvent args)
{
if (ent.Comp.ChitziteAction != null)
return;

ent.Comp.NextUpdate = _timing.CurTime + ent.Comp.UpdateInterval;

_actions.AddAction(ent, ref ent.Comp.ChitziteAction, ent.Comp.ChitziteActionId);
}

private void OnChitzite(Entity<ChitinidComponent> ent, ref ChitziteActionEvent args)
{
if (_inventory.TryGetSlotEntity(ent, "mask", out var maskUid) &&
TryComp<IngestionBlockerComponent>(maskUid, out var blocker) &&
blocker.Enabled)
{
_popup.PopupEntity(Loc.GetString("chitzite-mask", ("mask", maskUid)), ent, ent);
return;
}

_popup.PopupEntity(Loc.GetString("chitzite-cough", ("name", Identity.Entity(ent, EntityManager))), ent);
_audio.PlayPvs("/Audio/Animals/cat_hiss.ogg", ent, AudioHelpers.WithVariation(0.15f));

var chitzite = EnsureComp<CoughingUpChitziteComponent>(ent);
chitzite.NextCough = _timing.CurTime + chitzite.CoughUpTime;
args.Handled = true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;

namespace Content.Server.Abilities.Chitinid;

[RegisterComponent, AutoGenerateComponentPause]
public sealed partial class CoughingUpChitziteComponent : Component
{
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
[AutoPausedField]
public TimeSpan NextCough;

[DataField]
public TimeSpan CoughUpTime = TimeSpan.FromSeconds(2.15);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Content.Shared.Temperature.Systems;
using Robust.Shared.GameStates;

namespace Content.Shared.Temperature.Components;

/// <summary>
/// This is used for an entity that varies in speed based on current temperature.
/// </summary>
[RegisterComponent, NetworkedComponent, Access(typeof(SharedTemperatureSystem)), AutoGenerateComponentState, AutoGenerateComponentPause]
public sealed partial class TemperatureSpeedComponent : Component
{
/// <summary>
/// Pairs of temperature thresholds to applied slowdown values.
/// </summary>
[DataField]
public Dictionary<float, float> Thresholds = new();

/// <summary>
/// The current speed modifier from <see cref="Thresholds"/> we reached.
/// Stored and networked so that the client doesn't mispredict temperature
/// </summary>
[DataField, AutoNetworkedField]
public float? CurrentSpeedModifier;

/// <summary>
/// The time at which the temperature slowdown is updated.
/// </summary>
[DataField, AutoNetworkedField, AutoPausedField]
public TimeSpan? NextSlowdownUpdate;
}
80 changes: 80 additions & 0 deletions Content.Shared/Temperature/Systems/SharedTemperatureSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System.Linq;
using Content.Shared.Movement.Components;
using Content.Shared.Movement.Systems;
using Content.Shared.Temperature.Components;
using Robust.Shared.Timing;

namespace Content.Shared.Temperature.Systems;

/// <summary>
/// This handles predicting temperature based speedup.
/// </summary>
public sealed class SharedTemperatureSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly MovementSpeedModifierSystem _movementSpeedModifier = default!;

/// <summary>
/// Band-aid for unpredicted atmos. Delays the application for a short period so that laggy clients can get the replicated temperature.
/// </summary>
private static readonly TimeSpan SlowdownApplicationDelay = TimeSpan.FromSeconds(1f);

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<TemperatureSpeedComponent, OnTemperatureChangeEvent>(OnTemperatureChanged);
SubscribeLocalEvent<TemperatureSpeedComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovementSpeedModifiers);
}

private void OnTemperatureChanged(Entity<TemperatureSpeedComponent> ent, ref OnTemperatureChangeEvent args)
{
foreach (var (threshold, modifier) in ent.Comp.Thresholds)
{
if (args.CurrentTemperature < threshold && args.LastTemperature > threshold ||
args.CurrentTemperature > threshold && args.LastTemperature < threshold)
{
ent.Comp.NextSlowdownUpdate = _timing.CurTime + SlowdownApplicationDelay;
ent.Comp.CurrentSpeedModifier = modifier;
Dirty(ent);
break;
}
}

var maxThreshold = ent.Comp.Thresholds.Max(p => p.Key);
if (args.CurrentTemperature > maxThreshold && args.LastTemperature < maxThreshold)
{
ent.Comp.NextSlowdownUpdate = _timing.CurTime + SlowdownApplicationDelay;
ent.Comp.CurrentSpeedModifier = null;
Dirty(ent);
}
}

private void OnRefreshMovementSpeedModifiers(Entity<TemperatureSpeedComponent> ent, ref RefreshMovementSpeedModifiersEvent args)
{
// Don't update speed and mispredict while we're compensating for lag.
if (ent.Comp.NextSlowdownUpdate != null || ent.Comp.CurrentSpeedModifier == null)
return;

args.ModifySpeed(ent.Comp.CurrentSpeedModifier.Value, ent.Comp.CurrentSpeedModifier.Value);
}

public override void Update(float frameTime)
{
base.Update(frameTime);

var query = EntityQueryEnumerator<TemperatureSpeedComponent, MovementSpeedModifierComponent>();
while (query.MoveNext(out var uid, out var temp, out var movement))
{
if (temp.NextSlowdownUpdate == null)
continue;

if (_timing.CurTime < temp.NextSlowdownUpdate)
continue;

temp.NextSlowdownUpdate = null;
_movementSpeedModifier.RefreshMovementSpeedModifiers(uid, movement);
Dirty(uid, temp);
}
}
}
Loading
Loading