From 008fa7ca4744a1f1a7035bb462e08ca330cc6d53 Mon Sep 17 00:00:00 2001 From: Milon Date: Mon, 23 Sep 2024 10:12:43 +0200 Subject: [PATCH 1/9] OMG FINALLY FIXED THIS JANKY SHIT --- .../DeltaV/Addictions/AddictionSystem.cs | 93 +++++++++++++++++++ .../DeltaV/EntityEffects/Effects/Addicted.cs | 17 ++++ .../DeltaV/Addictions/AddictedComponent.cs | 25 +++++ .../Addictions/SharedAddictionSystem.cs | 40 ++++++++ 4 files changed, 175 insertions(+) create mode 100644 Content.Server/DeltaV/Addictions/AddictionSystem.cs create mode 100644 Content.Server/DeltaV/EntityEffects/Effects/Addicted.cs create mode 100644 Content.Shared/DeltaV/Addictions/AddictedComponent.cs create mode 100644 Content.Shared/DeltaV/Addictions/SharedAddictionSystem.cs diff --git a/Content.Server/DeltaV/Addictions/AddictionSystem.cs b/Content.Server/DeltaV/Addictions/AddictionSystem.cs new file mode 100644 index 00000000000..83c8733a54e --- /dev/null +++ b/Content.Server/DeltaV/Addictions/AddictionSystem.cs @@ -0,0 +1,93 @@ +using Content.Shared.DeltaV.Addictions; +using Content.Shared.Popups; +using Content.Shared.StatusEffect; +using Robust.Shared.Prototypes; +using Robust.Shared.Timing; + +namespace Content.Server.DeltaV.Addictions; + +public sealed class AddictionSystem : SharedAddictionSystem +{ + [Dependency] private readonly SharedPopupSystem _popupSystem = default!; + [Dependency] private readonly IGameTiming _timing = default!; + + private readonly Dictionary _nextEffectTime = new(); + + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnShutdown); + } + + public override void Update(float frameTime) + { + base.Update(frameTime); + + var curTime = _timing.CurTime; + var query = EntityQueryEnumerator(); + + while (query.MoveNext(out var uid, out var component)) + { + if (component.Suppressed) + { + UpdateSuppressed(uid, component); + continue; + } + + if (!_nextEffectTime.TryGetValue(uid, out var nextTime)) + { + // _nextEffectTime[uid] = curTime + TimeSpan.FromSeconds(Random.NextDouble() * 9 + 1); + _nextEffectTime[uid] = curTime + TimeSpan.FromSeconds(5); + continue; + } + + if (curTime < nextTime) + continue; + + DoAddictionEffect(uid, component); + // _nextEffectTime[uid] = curTime + TimeSpan.FromSeconds(Random.NextDouble() * 9 + 1); + _nextEffectTime[uid] = curTime + TimeSpan.FromSeconds(5); + } + } + + private void OnShutdown(EntityUid uid, AddictedComponent component, ComponentShutdown args) + { + _nextEffectTime.Remove(uid); + } + + private void UpdateSuppressed(EntityUid uid, AddictedComponent component) + { + var componentTime = component.LastMetabolismTime + TimeSpan.FromSeconds(10); + if (componentTime > _timing.CurTime) + { + component.Suppressed = true; + Dirty(uid, component); + } + else + { + component.Suppressed = false; + Dirty(uid, component); + } + } + protected override void DoAddictionEffect(EntityUid uid, AddictedComponent component) + { + var message = Loc.GetString("addiction-effect", ("entity", uid)); + _popupSystem.PopupEntity(message, uid); + } + + public override void TryApplyAddiction(EntityUid uid, float addictionStrength = 1f, StatusEffectsComponent? status = null) + { + base.TryApplyAddiction(uid, addictionStrength, status); + } + + protected override void UpdateTime(EntityUid uid) + { + if (TryComp((uid), out var component)) + { + component.LastMetabolismTime = _timing.CurTime; + UpdateSuppressed(uid, component); + } + else + return; + } +} diff --git a/Content.Server/DeltaV/EntityEffects/Effects/Addicted.cs b/Content.Server/DeltaV/EntityEffects/Effects/Addicted.cs new file mode 100644 index 00000000000..957bb961d1b --- /dev/null +++ b/Content.Server/DeltaV/EntityEffects/Effects/Addicted.cs @@ -0,0 +1,17 @@ +using Content.Shared.DeltaV.Addictions; +using Content.Shared.EntityEffects; +using Robust.Shared.Prototypes; + +namespace Content.Server.EntityEffects.Effects; + +public sealed partial class Addicted : EntityEffect +{ + protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys) + => Loc.GetString("reagent-effect-guidebook-addicted", ("chance", Probability)); + + public override void Effect(EntityEffectBaseArgs args) + { + var addictionSystem = args.EntityManager.EntitySysManager.GetEntitySystem(); + addictionSystem.TryApplyAddiction(args.TargetEntity); + } +} diff --git a/Content.Shared/DeltaV/Addictions/AddictedComponent.cs b/Content.Shared/DeltaV/Addictions/AddictedComponent.cs new file mode 100644 index 00000000000..e40f043656a --- /dev/null +++ b/Content.Shared/DeltaV/Addictions/AddictedComponent.cs @@ -0,0 +1,25 @@ +using Robust.Shared.GameStates; +using Robust.Shared.Prototypes; +using Robust.Shared.Timing; + +namespace Content.Shared.DeltaV.Addictions; + +[RegisterComponent, NetworkedComponent] +[AutoGenerateComponentState] +public sealed partial class AddictedComponent : Component +{ + [DataField, AutoNetworkedField] + public float AddictionStrength = 0f; + + /// + /// Setting this to true will suppress any pop-ups. + /// + [DataField] + public bool Suppressed; + + /// + /// The timestamp of last StatusEffect trigger. + /// + [DataField(serverOnly: true)] + public TimeSpan? LastMetabolismTime; +} diff --git a/Content.Shared/DeltaV/Addictions/SharedAddictionSystem.cs b/Content.Shared/DeltaV/Addictions/SharedAddictionSystem.cs new file mode 100644 index 00000000000..1683297296c --- /dev/null +++ b/Content.Shared/DeltaV/Addictions/SharedAddictionSystem.cs @@ -0,0 +1,40 @@ + +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!; + + public ProtoId StatusEffectKey = "Addicted"; + + public override void Initialize() + { + base.Initialize(); + } + + protected abstract void DoAddictionEffect(EntityUid uid, AddictedComponent component); + + protected abstract void UpdateTime(EntityUid uid); + + public virtual void TryApplyAddiction(EntityUid uid, float addictionStrength = 1f, StatusEffectsComponent? status = null) + { + if (!Resolve(uid, ref status, false)) + return; + + UpdateTime(uid); + + if (!StatusEffects.HasStatusEffect(uid, StatusEffectKey, status)) + { + StatusEffects.TryAddStatusEffect(uid, StatusEffectKey, TimeSpan.FromSeconds(addictionStrength * 10), true, status); + } + else + { + StatusEffects.TryAddTime(uid, StatusEffectKey, TimeSpan.FromSeconds(addictionStrength * 10), status); + } + } +} From b8d49d411e34d07700a3e70c98a193cd199ba849 Mon Sep 17 00:00:00 2001 From: Milon Date: Mon, 23 Sep 2024 11:59:07 +0200 Subject: [PATCH 2/9] oh --- Resources/Prototypes/DeltaV/status_effects.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Resources/Prototypes/DeltaV/status_effects.yml b/Resources/Prototypes/DeltaV/status_effects.yml index e69de29bb2d..beb09d7addd 100644 --- a/Resources/Prototypes/DeltaV/status_effects.yml +++ b/Resources/Prototypes/DeltaV/status_effects.yml @@ -0,0 +1,2 @@ +- type: statusEffect + id: Addicted From 6ac5b10ccbc18d3ec9f1973c444f3ea6e13b7d09 Mon Sep 17 00:00:00 2001 From: Milon Date: Mon, 23 Sep 2024 13:16:03 +0200 Subject: [PATCH 3/9] no structure, zero fucks given --- .../DeltaV/Addictions/AddictionSystem.cs | 52 +++++++++++++++---- .../DeltaV/EntityEffects/Effects/Addicted.cs | 14 ++++- .../DeltaV/Addictions/AddictedComponent.cs | 6 +-- .../Addictions/SharedAddictionSystem.cs | 8 +-- 4 files changed, 59 insertions(+), 21 deletions(-) diff --git a/Content.Server/DeltaV/Addictions/AddictionSystem.cs b/Content.Server/DeltaV/Addictions/AddictionSystem.cs index 83c8733a54e..f4973514be8 100644 --- a/Content.Server/DeltaV/Addictions/AddictionSystem.cs +++ b/Content.Server/DeltaV/Addictions/AddictionSystem.cs @@ -1,7 +1,9 @@ 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; namespace Content.Server.DeltaV.Addictions; @@ -10,9 +12,18 @@ public sealed class AddictionSystem : SharedAddictionSystem { [Dependency] private readonly SharedPopupSystem _popupSystem = default!; [Dependency] private readonly IGameTiming _timing = default!; + [Dependency] private readonly IPlayerManager _playerManager = default!; + [Dependency] private readonly IRobustRandom _random = default!; private readonly Dictionary _nextEffectTime = new(); + // Define the numbers, we're not making another DeepFryerSystem.cs + // Minimum time between popups + private const int MinEffectInterval = 10; + + // Maximum time between popups + private const int MaxEffectInterval = 41; + public override void Initialize() { base.Initialize(); @@ -28,6 +39,7 @@ public override void Update(float frameTime) while (query.MoveNext(out var uid, out var component)) { + // If it's suppressed, check if it's still supposed to be if (component.Suppressed) { UpdateSuppressed(uid, component); @@ -36,17 +48,16 @@ public override void Update(float frameTime) if (!_nextEffectTime.TryGetValue(uid, out var nextTime)) { - // _nextEffectTime[uid] = curTime + TimeSpan.FromSeconds(Random.NextDouble() * 9 + 1); - _nextEffectTime[uid] = curTime + TimeSpan.FromSeconds(5); + // Between 10 and 40 seconds + _nextEffectTime[uid] = curTime + TimeSpan.FromSeconds(_random.Next(MinEffectInterval, MaxEffectInterval)); continue; } if (curTime < nextTime) continue; - DoAddictionEffect(uid, component); - // _nextEffectTime[uid] = curTime + TimeSpan.FromSeconds(Random.NextDouble() * 9 + 1); - _nextEffectTime[uid] = curTime + TimeSpan.FromSeconds(5); + DoAddictionEffect(uid); + _nextEffectTime[uid] = curTime + TimeSpan.FromSeconds(_random.Next(MinEffectInterval, MaxEffectInterval)); } } @@ -57,7 +68,7 @@ private void OnShutdown(EntityUid uid, AddictedComponent component, ComponentShu private void UpdateSuppressed(EntityUid uid, AddictedComponent component) { - var componentTime = component.LastMetabolismTime + TimeSpan.FromSeconds(10); + var componentTime = component.LastMetabolismTime + TimeSpan.FromSeconds(10); // Ten seconds after the last metabolism cycle if (componentTime > _timing.CurTime) { component.Suppressed = true; @@ -69,17 +80,36 @@ private void UpdateSuppressed(EntityUid uid, AddictedComponent component) Dirty(uid, component); } } - protected override void DoAddictionEffect(EntityUid uid, AddictedComponent component) + + private string GetRandomPopup() { - var message = Loc.GetString("addiction-effect", ("entity", uid)); - _popupSystem.PopupEntity(message, uid); + return _random.Pick(new[] + { + Loc.GetString("reagent-effect-medaddiction-1"), + Loc.GetString("reagent-effect-medaddiction-2"), + Loc.GetString("reagent-effect-medaddiction-3"), + Loc.GetString("reagent-effect-medaddiction-4"), + Loc.GetString("reagent-effect-medaddiction-5"), + Loc.GetString("reagent-effect-medaddiction-6"), + Loc.GetString("reagent-effect-medaddiction-7"), + Loc.GetString("reagent-effect-medaddiction-8") + }); } - public override void TryApplyAddiction(EntityUid uid, float addictionStrength = 1f, StatusEffectsComponent? status = null) + public override void TryApplyAddiction(EntityUid uid, float addictionTime, StatusEffectsComponent? status = null) { - base.TryApplyAddiction(uid, addictionStrength, status); + base.TryApplyAddiction(uid, addictionTime, status); + } + + protected override void DoAddictionEffect(EntityUid uid) + { + if (_playerManager.TryGetSessionByEntity(uid, out var session)) + { + _popupSystem.PopupEntity(GetRandomPopup(), uid, session); + } } + // Called each time a reagent with the Addicted effect gets metabolized protected override void UpdateTime(EntityUid uid) { if (TryComp((uid), out var component)) diff --git a/Content.Server/DeltaV/EntityEffects/Effects/Addicted.cs b/Content.Server/DeltaV/EntityEffects/Effects/Addicted.cs index 957bb961d1b..5e8e711a96e 100644 --- a/Content.Server/DeltaV/EntityEffects/Effects/Addicted.cs +++ b/Content.Server/DeltaV/EntityEffects/Effects/Addicted.cs @@ -6,12 +6,24 @@ namespace Content.Server.EntityEffects.Effects; public sealed partial class Addicted : EntityEffect { + /// + /// How long should each metabolism cycle make the effect last for. + /// + [DataField] + public float AddictionTime = 3f; + protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys) => Loc.GetString("reagent-effect-guidebook-addicted", ("chance", Probability)); public override void Effect(EntityEffectBaseArgs args) { + var addictionTime = AddictionTime; + + if (args is EntityEffectReagentArgs reagentArgs) { + addictionTime *= reagentArgs.Scale.Float(); + } + var addictionSystem = args.EntityManager.EntitySysManager.GetEntitySystem(); - addictionSystem.TryApplyAddiction(args.TargetEntity); + addictionSystem.TryApplyAddiction(args.TargetEntity, addictionTime); } } diff --git a/Content.Shared/DeltaV/Addictions/AddictedComponent.cs b/Content.Shared/DeltaV/Addictions/AddictedComponent.cs index e40f043656a..4539fde2622 100644 --- a/Content.Shared/DeltaV/Addictions/AddictedComponent.cs +++ b/Content.Shared/DeltaV/Addictions/AddictedComponent.cs @@ -5,14 +5,10 @@ namespace Content.Shared.DeltaV.Addictions; [RegisterComponent, NetworkedComponent] -[AutoGenerateComponentState] public sealed partial class AddictedComponent : Component { - [DataField, AutoNetworkedField] - public float AddictionStrength = 0f; - /// - /// Setting this to true will suppress any pop-ups. + /// Whether to suppress pop-ups. /// [DataField] public bool Suppressed; diff --git a/Content.Shared/DeltaV/Addictions/SharedAddictionSystem.cs b/Content.Shared/DeltaV/Addictions/SharedAddictionSystem.cs index 1683297296c..0724a1f492b 100644 --- a/Content.Shared/DeltaV/Addictions/SharedAddictionSystem.cs +++ b/Content.Shared/DeltaV/Addictions/SharedAddictionSystem.cs @@ -17,11 +17,11 @@ public override void Initialize() base.Initialize(); } - protected abstract void DoAddictionEffect(EntityUid uid, AddictedComponent component); + protected abstract void DoAddictionEffect(EntityUid uid); protected abstract void UpdateTime(EntityUid uid); - public virtual void TryApplyAddiction(EntityUid uid, float addictionStrength = 1f, StatusEffectsComponent? status = null) + public virtual void TryApplyAddiction(EntityUid uid, float addictionTime, StatusEffectsComponent? status = null) { if (!Resolve(uid, ref status, false)) return; @@ -30,11 +30,11 @@ public virtual void TryApplyAddiction(EntityUid uid, float addictionStrength = 1 if (!StatusEffects.HasStatusEffect(uid, StatusEffectKey, status)) { - StatusEffects.TryAddStatusEffect(uid, StatusEffectKey, TimeSpan.FromSeconds(addictionStrength * 10), true, status); + StatusEffects.TryAddStatusEffect(uid, StatusEffectKey, TimeSpan.FromSeconds(addictionTime), true, status); } else { - StatusEffects.TryAddTime(uid, StatusEffectKey, TimeSpan.FromSeconds(addictionStrength * 10), status); + StatusEffects.TryAddTime(uid, StatusEffectKey, TimeSpan.FromSeconds(addictionTime), status); } } } From c351c29fe205ebc97a69e58095be0febfae95507 Mon Sep 17 00:00:00 2001 From: Milon Date: Mon, 23 Sep 2024 13:23:18 +0200 Subject: [PATCH 4/9] this also --- Resources/Prototypes/Entities/Mobs/Species/base.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/Resources/Prototypes/Entities/Mobs/Species/base.yml b/Resources/Prototypes/Entities/Mobs/Species/base.yml index 489c5d3aa00..5e0fed26bd8 100644 --- a/Resources/Prototypes/Entities/Mobs/Species/base.yml +++ b/Resources/Prototypes/Entities/Mobs/Species/base.yml @@ -138,6 +138,7 @@ - Adrenaline - PsionicsDisabled #Nyano - Summary: PCs can have psionics disabled. - PsionicallyInsulated #Nyano - Summary: PCs can be made insulated from psionic powers. + - Addicted # DeltaV - Psych med addictions system - type: Body prototype: Human requiredLegs: 2 From f029c40a0938d4ce3ed789d405530678c997f8c8 Mon Sep 17 00:00:00 2001 From: Milon Date: Mon, 23 Sep 2024 13:34:41 +0200 Subject: [PATCH 5/9] trolled --- .../Locale/en-US/deltav/guidebook/chemistry/effects.ftl | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Resources/Locale/en-US/deltav/guidebook/chemistry/effects.ftl diff --git a/Resources/Locale/en-US/deltav/guidebook/chemistry/effects.ftl b/Resources/Locale/en-US/deltav/guidebook/chemistry/effects.ftl new file mode 100644 index 00000000000..886e5b0c4f0 --- /dev/null +++ b/Resources/Locale/en-US/deltav/guidebook/chemistry/effects.ftl @@ -0,0 +1,5 @@ +reagent-effect-guidebook-addicted = + { $chance -> + [1] Causes + *[other] cause + } an addiction. From bd658196586cc285ba9a292946cf94b5a0b21a74 Mon Sep 17 00:00:00 2001 From: Milon Date: Tue, 24 Sep 2024 19:52:36 +0200 Subject: [PATCH 6/9] shitcode v2 --- .../DeltaV/Addictions/AddictionSystem.cs | 8 +++ .../DeltaV/Addictions/AddictionSystem.cs | 60 ++++++------------- .../DeltaV/EntityEffects/Effects/Addicted.cs | 2 +- .../DeltaV/Addictions/AddictedComponent.cs | 11 +++- .../Addictions/SharedAddictionSystem.cs | 7 --- .../Prototypes/DeltaV/Datasets/addictions.yml | 5 ++ 6 files changed, 42 insertions(+), 51 deletions(-) create mode 100644 Content.Client/DeltaV/Addictions/AddictionSystem.cs create mode 100644 Resources/Prototypes/DeltaV/Datasets/addictions.yml diff --git a/Content.Client/DeltaV/Addictions/AddictionSystem.cs b/Content.Client/DeltaV/Addictions/AddictionSystem.cs new file mode 100644 index 00000000000..75ac6969a48 --- /dev/null +++ b/Content.Client/DeltaV/Addictions/AddictionSystem.cs @@ -0,0 +1,8 @@ +using Content.Shared.DeltaV.Addictions; + +namespace Content.Client.DeltaV.Addictions; + +public sealed class AddictionSystem : SharedAddictionSystem +{ + protected override void UpdateTime(EntityUid uid) {} +} diff --git a/Content.Server/DeltaV/Addictions/AddictionSystem.cs b/Content.Server/DeltaV/Addictions/AddictionSystem.cs index f4973514be8..987aeea421e 100644 --- a/Content.Server/DeltaV/Addictions/AddictionSystem.cs +++ b/Content.Server/DeltaV/Addictions/AddictionSystem.cs @@ -1,3 +1,4 @@ +using Content.Shared.Dataset; using Content.Shared.DeltaV.Addictions; using Content.Shared.Popups; using Content.Shared.StatusEffect; @@ -10,10 +11,10 @@ namespace Content.Server.DeltaV.Addictions; public sealed class AddictionSystem : SharedAddictionSystem { - [Dependency] private readonly SharedPopupSystem _popupSystem = default!; - [Dependency] private readonly IGameTiming _timing = default!; - [Dependency] private readonly IPlayerManager _playerManager = default!; + [Dependency] private readonly SharedPopupSystem _popup = default!; + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IRobustRandom _random = default!; + [Dependency] private readonly IGameTiming _timing = default!; private readonly Dictionary _nextEffectTime = new(); @@ -27,7 +28,7 @@ public sealed class AddictionSystem : SharedAddictionSystem public override void Initialize() { base.Initialize(); - SubscribeLocalEvent(OnShutdown); + SubscribeLocalEvent(OnInit); } public override void Update(float frameTime) @@ -46,54 +47,36 @@ public override void Update(float frameTime) continue; } - if (!_nextEffectTime.TryGetValue(uid, out var nextTime)) - { - // Between 10 and 40 seconds - _nextEffectTime[uid] = curTime + TimeSpan.FromSeconds(_random.Next(MinEffectInterval, MaxEffectInterval)); - continue; - } - - if (curTime < nextTime) + if (curTime < component.NextEffectTime) continue; DoAddictionEffect(uid); - _nextEffectTime[uid] = curTime + TimeSpan.FromSeconds(_random.Next(MinEffectInterval, MaxEffectInterval)); + component.NextEffectTime = curTime + TimeSpan.FromSeconds(_random.Next(MinEffectInterval, MaxEffectInterval)); } } - private void OnShutdown(EntityUid uid, AddictedComponent component, ComponentShutdown args) + // Make sure we don't get a popup on the first update + private void OnInit(EntityUid uid, AddictedComponent component, ComponentStartup args) { - _nextEffectTime.Remove(uid); + var curTime = _timing.CurTime; + component.NextEffectTime = curTime + TimeSpan.FromSeconds(_random.Next(MinEffectInterval, MaxEffectInterval)); } private void UpdateSuppressed(EntityUid uid, AddictedComponent component) { var componentTime = component.LastMetabolismTime + TimeSpan.FromSeconds(10); // Ten seconds after the last metabolism cycle - if (componentTime > _timing.CurTime) + var shouldBeSupressed = (componentTime > _timing.CurTime); + if (component.Suppressed != shouldBeSupressed) { - component.Suppressed = true; - Dirty(uid, component); + component.Suppressed = shouldBeSupressed; } else - { - component.Suppressed = false; - Dirty(uid, component); - } + return; } private string GetRandomPopup() { - return _random.Pick(new[] - { - Loc.GetString("reagent-effect-medaddiction-1"), - Loc.GetString("reagent-effect-medaddiction-2"), - Loc.GetString("reagent-effect-medaddiction-3"), - Loc.GetString("reagent-effect-medaddiction-4"), - Loc.GetString("reagent-effect-medaddiction-5"), - Loc.GetString("reagent-effect-medaddiction-6"), - Loc.GetString("reagent-effect-medaddiction-7"), - Loc.GetString("reagent-effect-medaddiction-8") - }); + return Loc.GetString(_random.Pick(_prototypeManager.Index("AddictionEffects").Values)); } public override void TryApplyAddiction(EntityUid uid, float addictionTime, StatusEffectsComponent? status = null) @@ -101,23 +84,18 @@ public override void TryApplyAddiction(EntityUid uid, float addictionTime, Statu base.TryApplyAddiction(uid, addictionTime, status); } - protected override void DoAddictionEffect(EntityUid uid) + private void DoAddictionEffect(EntityUid uid) { - if (_playerManager.TryGetSessionByEntity(uid, out var session)) - { - _popupSystem.PopupEntity(GetRandomPopup(), uid, session); - } + _popup.PopupEntity(GetRandomPopup(), uid, uid); } // Called each time a reagent with the Addicted effect gets metabolized protected override void UpdateTime(EntityUid uid) { - if (TryComp((uid), out var component)) + if (TryComp(uid, out var component)) { component.LastMetabolismTime = _timing.CurTime; UpdateSuppressed(uid, component); } - else - return; } } diff --git a/Content.Server/DeltaV/EntityEffects/Effects/Addicted.cs b/Content.Server/DeltaV/EntityEffects/Effects/Addicted.cs index 5e8e711a96e..591e51a3d62 100644 --- a/Content.Server/DeltaV/EntityEffects/Effects/Addicted.cs +++ b/Content.Server/DeltaV/EntityEffects/Effects/Addicted.cs @@ -23,7 +23,7 @@ public override void Effect(EntityEffectBaseArgs args) addictionTime *= reagentArgs.Scale.Float(); } - var addictionSystem = args.EntityManager.EntitySysManager.GetEntitySystem(); + var addictionSystem = args.EntityManager.System(); addictionSystem.TryApplyAddiction(args.TargetEntity, addictionTime); } } diff --git a/Content.Shared/DeltaV/Addictions/AddictedComponent.cs b/Content.Shared/DeltaV/Addictions/AddictedComponent.cs index 4539fde2622..2fa7d400152 100644 --- a/Content.Shared/DeltaV/Addictions/AddictedComponent.cs +++ b/Content.Shared/DeltaV/Addictions/AddictedComponent.cs @@ -4,13 +4,14 @@ namespace Content.Shared.DeltaV.Addictions; -[RegisterComponent, NetworkedComponent] +[RegisterComponent, NetworkedComponent, Access(typeof(SharedAddictionSystem))] +[AutoGenerateComponentState] public sealed partial class AddictedComponent : Component { /// /// Whether to suppress pop-ups. /// - [DataField] + [DataField, AutoNetworkedField] public bool Suppressed; /// @@ -18,4 +19,10 @@ public sealed partial class AddictedComponent : Component /// [DataField(serverOnly: true)] public TimeSpan? LastMetabolismTime; + + /// + /// The timestamp of the next popup. + /// + [DataField(serverOnly: true)] + public TimeSpan? NextEffectTime; } diff --git a/Content.Shared/DeltaV/Addictions/SharedAddictionSystem.cs b/Content.Shared/DeltaV/Addictions/SharedAddictionSystem.cs index 0724a1f492b..47cb865456f 100644 --- a/Content.Shared/DeltaV/Addictions/SharedAddictionSystem.cs +++ b/Content.Shared/DeltaV/Addictions/SharedAddictionSystem.cs @@ -12,13 +12,6 @@ public abstract class SharedAddictionSystem : EntitySystem public ProtoId StatusEffectKey = "Addicted"; - public override void Initialize() - { - base.Initialize(); - } - - protected abstract void DoAddictionEffect(EntityUid uid); - protected abstract void UpdateTime(EntityUid uid); public virtual void TryApplyAddiction(EntityUid uid, float addictionTime, StatusEffectsComponent? status = null) diff --git a/Resources/Prototypes/DeltaV/Datasets/addictions.yml b/Resources/Prototypes/DeltaV/Datasets/addictions.yml new file mode 100644 index 00000000000..7f8bc2a6730 --- /dev/null +++ b/Resources/Prototypes/DeltaV/Datasets/addictions.yml @@ -0,0 +1,5 @@ +- type: localizedDataset + id: AddictionEffects + values: + prefix: reagent-effect-medaddiction- + count: 8 From 3dc292bf662f8f2af21a1d02a6760ecf51db06ee Mon Sep 17 00:00:00 2001 From: Milon Date: Tue, 24 Sep 2024 19:54:22 +0200 Subject: [PATCH 7/9] FUCK --- Content.Server/DeltaV/Addictions/AddictionSystem.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Content.Server/DeltaV/Addictions/AddictionSystem.cs b/Content.Server/DeltaV/Addictions/AddictionSystem.cs index 987aeea421e..8dc4dc6aa53 100644 --- a/Content.Server/DeltaV/Addictions/AddictionSystem.cs +++ b/Content.Server/DeltaV/Addictions/AddictionSystem.cs @@ -16,8 +16,6 @@ public sealed class AddictionSystem : SharedAddictionSystem [Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly IGameTiming _timing = default!; - private readonly Dictionary _nextEffectTime = new(); - // Define the numbers, we're not making another DeepFryerSystem.cs // Minimum time between popups private const int MinEffectInterval = 10; From 5bbdb9c80703c372f6cf60190c2bea3748d94625 Mon Sep 17 00:00:00 2001 From: Milon Date: Sun, 3 Nov 2024 17:34:45 +0100 Subject: [PATCH 8/9] what was i even fucking thinking??? --- .../DeltaV/Addictions/AddictionSystem.cs | 39 +++++++------------ .../DeltaV/Addictions/AddictedComponent.cs | 17 ++++++-- .../Addictions/SharedAddictionSystem.cs | 11 ++---- 3 files changed, 32 insertions(+), 35 deletions(-) diff --git a/Content.Server/DeltaV/Addictions/AddictionSystem.cs b/Content.Server/DeltaV/Addictions/AddictionSystem.cs index 8dc4dc6aa53..038117b4664 100644 --- a/Content.Server/DeltaV/Addictions/AddictionSystem.cs +++ b/Content.Server/DeltaV/Addictions/AddictionSystem.cs @@ -1,8 +1,7 @@ using Content.Shared.Dataset; using Content.Shared.DeltaV.Addictions; using Content.Shared.Popups; -using Content.Shared.StatusEffect; -using Robust.Server.Player; +using Microsoft.CodeAnalysis; using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Timing; @@ -23,6 +22,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(); @@ -41,7 +43,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; } @@ -54,22 +56,15 @@ public override void Update(float frameTime) } // Make sure we don't get a popup on the first update - private void OnInit(EntityUid uid, AddictedComponent component, ComponentStartup args) + private void OnInit(Entity ent, ref ComponentStartup args) { var curTime = _timing.CurTime; - component.NextEffectTime = curTime + TimeSpan.FromSeconds(_random.Next(MinEffectInterval, MaxEffectInterval)); + ent.Comp.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() @@ -77,11 +72,6 @@ private string GetRandomPopup() return Loc.GetString(_random.Pick(_prototypeManager.Index("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); @@ -90,10 +80,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(uid, out var component)) - { - component.LastMetabolismTime = _timing.CurTime; - UpdateSuppressed(uid, component); - } + if (!TryComp(uid, out var component)) + return; + + component.LastMetabolismTime = _timing.CurTime; + component.SuppressionEndTime = _timing.CurTime + TimeSpan.FromSeconds(SuppressionDuration); + UpdateSuppressed(component); } } diff --git a/Content.Shared/DeltaV/Addictions/AddictedComponent.cs b/Content.Shared/DeltaV/Addictions/AddictedComponent.cs index 2fa7d400152..2f9169a7fb9 100644 --- a/Content.Shared/DeltaV/Addictions/AddictedComponent.cs +++ b/Content.Shared/DeltaV/Addictions/AddictedComponent.cs @@ -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 { /// @@ -17,12 +17,21 @@ public sealed partial class AddictedComponent : Component /// /// The timestamp of last StatusEffect trigger. /// - [DataField(serverOnly: true)] + [DataField(serverOnly: true, customTypeSerializer: typeof(TimeOffsetSerializer))] + [AutoPausedField] public TimeSpan? LastMetabolismTime; /// /// The timestamp of the next popup. /// - [DataField(serverOnly: true)] + [DataField(serverOnly: true, customTypeSerializer: typeof(TimeOffsetSerializer))] + [AutoPausedField] public TimeSpan? NextEffectTime; + + /// + /// The timestamp of the when the suppression ends + /// + [DataField(serverOnly: true, customTypeSerializer: typeof(TimeOffsetSerializer))] + [AutoPausedField] + public TimeSpan? SuppressionEndTime; } diff --git a/Content.Shared/DeltaV/Addictions/SharedAddictionSystem.cs b/Content.Shared/DeltaV/Addictions/SharedAddictionSystem.cs index 47cb865456f..f58534592d9 100644 --- a/Content.Shared/DeltaV/Addictions/SharedAddictionSystem.cs +++ b/Content.Shared/DeltaV/Addictions/SharedAddictionSystem.cs @@ -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 StatusEffectKey = "Addicted"; @@ -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(uid, StatusEffectKey, TimeSpan.FromSeconds(addictionTime), true, status); + _statusEffects.TryAddStatusEffect(uid, StatusEffectKey, TimeSpan.FromSeconds(addictionTime), true, status); } else { - StatusEffects.TryAddTime(uid, StatusEffectKey, TimeSpan.FromSeconds(addictionTime), status); + _statusEffects.TryAddTime(uid, StatusEffectKey, TimeSpan.FromSeconds(addictionTime), status); } } } From 8993a2b882a369fcb4f3a812309dfd93dd12c85c Mon Sep 17 00:00:00 2001 From: deltanedas <39013340+deltanedas@users.noreply.github.com> Date: Mon, 4 Nov 2024 14:42:25 +0000 Subject: [PATCH 9/9] remove unused codeanalysis import Signed-off-by: deltanedas <39013340+deltanedas@users.noreply.github.com> --- Content.Server/DeltaV/Addictions/AddictionSystem.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Content.Server/DeltaV/Addictions/AddictionSystem.cs b/Content.Server/DeltaV/Addictions/AddictionSystem.cs index 038117b4664..1df7eeecbee 100644 --- a/Content.Server/DeltaV/Addictions/AddictionSystem.cs +++ b/Content.Server/DeltaV/Addictions/AddictionSystem.cs @@ -1,7 +1,6 @@ using Content.Shared.Dataset; using Content.Shared.DeltaV.Addictions; using Content.Shared.Popups; -using Microsoft.CodeAnalysis; using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Timing;