Skip to content

Commit

Permalink
what was i even fucking thinking???
Browse files Browse the repository at this point in the history
  • Loading branch information
MilonPL committed Nov 3, 2024
1 parent c215bbd commit 681a83e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 80 deletions.
34 changes: 12 additions & 22 deletions Content.Server/DeltaV/Addictions/AddictionSystem.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Content.Shared.Dataset;
using Content.Shared.DeltaV.Addictions;
using Content.Shared.Popups;
using Content.Shared.StatusEffect;
using Robust.Server.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Timing;
Expand All @@ -23,6 +21,9 @@ public sealed class AddictionSystem : SharedAddictionSystem
// Maximum time between popups
private const int MaxEffectInterval = 41;

// The time to add after the last metabolism cycle
private const int SuppressionDuration = 10;

public override void Initialize()
{
base.Initialize();
Expand All @@ -41,7 +42,7 @@ public override void Update(float frameTime)
// If it's suppressed, check if it's still supposed to be
if (component.Suppressed)
{
UpdateSuppressed(uid, component);
UpdateSuppressed(component);
continue;
}

Expand All @@ -60,28 +61,16 @@ private void OnInit(EntityUid uid, AddictedComponent component, ComponentStartup
component.NextEffectTime = curTime + TimeSpan.FromSeconds(_random.Next(MinEffectInterval, MaxEffectInterval));
}

private void UpdateSuppressed(EntityUid uid, AddictedComponent component)
private void UpdateSuppressed(AddictedComponent component)
{
var componentTime = component.LastMetabolismTime + TimeSpan.FromSeconds(10); // Ten seconds after the last metabolism cycle
var shouldBeSupressed = (componentTime > _timing.CurTime);
if (component.Suppressed != shouldBeSupressed)
{
component.Suppressed = shouldBeSupressed;
}
else
return;
component.Suppressed = (_timing.CurTime < component.SuppressionEndTime);
}

private string GetRandomPopup()
{
return Loc.GetString(_random.Pick(_prototypeManager.Index<LocalizedDatasetPrototype>("AddictionEffects").Values));
}

public override void TryApplyAddiction(EntityUid uid, float addictionTime, StatusEffectsComponent? status = null)
{
base.TryApplyAddiction(uid, addictionTime, status);
}

private void DoAddictionEffect(EntityUid uid)
{
_popup.PopupEntity(GetRandomPopup(), uid, uid);
Expand All @@ -90,10 +79,11 @@ private void DoAddictionEffect(EntityUid uid)
// Called each time a reagent with the Addicted effect gets metabolized
protected override void UpdateTime(EntityUid uid)
{
if (TryComp<AddictedComponent>(uid, out var component))
{
component.LastMetabolismTime = _timing.CurTime;
UpdateSuppressed(uid, component);
}
if (!TryComp<AddictedComponent>(uid, out var component))
return;

component.LastMetabolismTime = _timing.CurTime;
component.SuppressionEndTime = _timing.CurTime + TimeSpan.FromSeconds(SuppressionDuration);
UpdateSuppressed(component);
}
}
17 changes: 13 additions & 4 deletions Content.Shared/DeltaV/Addictions/AddictedComponent.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
using Robust.Shared.Timing;

namespace Content.Shared.DeltaV.Addictions;

[RegisterComponent, NetworkedComponent, Access(typeof(SharedAddictionSystem))]
[AutoGenerateComponentState]
[AutoGenerateComponentState, AutoGenerateComponentPause]
public sealed partial class AddictedComponent : Component
{
/// <summary>
Expand All @@ -17,12 +17,21 @@ public sealed partial class AddictedComponent : Component
/// <summary>
/// The <see cref="IGameTiming.CurTime"/> timestamp of last StatusEffect trigger.
/// </summary>
[DataField(serverOnly: true)]
[DataField(serverOnly: true, customTypeSerializer: typeof(TimeOffsetSerializer))]
[AutoPausedField]
public TimeSpan? LastMetabolismTime;

/// <summary>
/// The <see cref="IGameTiming.CurTime"/> timestamp of the next popup.
/// </summary>
[DataField(serverOnly: true)]
[DataField(serverOnly: true, customTypeSerializer: typeof(TimeOffsetSerializer))]
[AutoPausedField]
public TimeSpan? NextEffectTime;

/// <summary>
/// The <see cref="IGameTiming.CurTime"/> timestamp of the when the suppression ends
/// </summary>
[DataField(serverOnly: true, customTypeSerializer: typeof(TimeOffsetSerializer))]
[AutoPausedField]
public TimeSpan? SuppressionEndTime;
}
11 changes: 4 additions & 7 deletions Content.Shared/DeltaV/Addictions/SharedAddictionSystem.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@

using Content.Shared.DeltaV.Addictions;
using Content.Shared.StatusEffect;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;

namespace Content.Shared.DeltaV.Addictions;

public abstract class SharedAddictionSystem : EntitySystem
{
[Dependency] protected readonly StatusEffectsSystem StatusEffects = default!;
[Dependency] private readonly StatusEffectsSystem _statusEffects = default!;

public ProtoId<StatusEffectPrototype> StatusEffectKey = "Addicted";

Expand All @@ -21,13 +18,13 @@ public virtual void TryApplyAddiction(EntityUid uid, float addictionTime, Status

UpdateTime(uid);

if (!StatusEffects.HasStatusEffect(uid, StatusEffectKey, status))
if (!_statusEffects.HasStatusEffect(uid, StatusEffectKey, status))
{
StatusEffects.TryAddStatusEffect<AddictedComponent>(uid, StatusEffectKey, TimeSpan.FromSeconds(addictionTime), true, status);
_statusEffects.TryAddStatusEffect<AddictedComponent>(uid, StatusEffectKey, TimeSpan.FromSeconds(addictionTime), true, status);
}
else
{
StatusEffects.TryAddTime(uid, StatusEffectKey, TimeSpan.FromSeconds(addictionTime), status);
_statusEffects.TryAddTime(uid, StatusEffectKey, TimeSpan.FromSeconds(addictionTime), status);
}
}
}
50 changes: 3 additions & 47 deletions Resources/Prototypes/Reagents/medicine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,7 @@
Medicine:
metabolismRate: 0.1
effects:
- !type:GenericStatusEffect
key: PsionicallyInsulated #Nyano - Summary: makes the user psionically insulated from effects.
component: PsionicInsulation #Nyano - Summary: see above.
type: Add
- !type:GenericStatusEffect
key: Stutter
component: ScrambledAccent
- !type:GenericStatusEffect
key: PsionicsDisabled #Nyano - Summary: disables psinoics from being used by the wearer.
component: PsionicsDisabled #Nyano - Summary: see above.
type: Add
- !type:Drunk
slurSpeech: false
boozePower: 20
- !type:Addiction

- type: reagent
id: Dylovene
Expand All @@ -36,38 +23,7 @@
metabolisms:
Medicine:
effects:
- !type:HealthChange
damage:
types:
Poison: -1
- !type:HealthChange
conditions:
- !type:ReagentThreshold
min: 20
damage:
groups:
Brute: 2
- !type:Jitter
conditions:
- !type:ReagentThreshold
min: 20
- !type:PopupMessage
conditions:
- !type:ReagentThreshold
min: 20
type: Local
visualType: Medium
messages: [ "generic-reagent-effect-nauseous" ]
probability: 0.2
- !type:ChemVomit
conditions:
- !type:ReagentThreshold
min: 20
probability: 0.02
- !type:Drunk
conditions:
- !type:ReagentThreshold
min: 15
- !type:Addicted
plantMetabolism:
- !type:PlantAdjustToxins
amount: -10
Expand Down Expand Up @@ -1132,7 +1088,7 @@
conditions:
- !type:ReagentThreshold
min: 12

- type: reagent
id: Opporozidone #Name based of an altered version of the startreck chem "Opporozine"
name: reagent-name-opporozidone
Expand Down

0 comments on commit 681a83e

Please sign in to comment.