From bf43141c9632a1c60f5da1e101225112f8c3cf1d Mon Sep 17 00:00:00 2001 From: ScalyChimp <72841710+scaly-chimp@users.noreply.github.com> Date: Tue, 3 Aug 2021 11:32:08 +0800 Subject: [PATCH] Meth (#4186) * adds an overdose metabolism with sensible default settings * adds the compoenents for the run fast part of meth * not sure what I changed here but I trust my past self to not fuck up for once * adds basic meth recipe * correctly names comething * I really should've checked my spelling before making this pr Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * adds suggestion from the maintaner, who managed to get to this pr suprisingly fast * Revert "adds suggestion from the maintaner, who managed to get to this pr suprisingly fast" This reverts commit 9b0f07402e35ed5890b3af805691b690671b950c. * tweak * tweak * git's gitting on my nerves * some small tweaks * don't need these anymore * makes some stuff required * changes the meth recipe to arbitary bullshit to get the yaml thingy to leave me alone goddamnit * extremely minor change * removes overdose, because however it's gonna be done, it's definitely not my way * i should really double check every key I press * hm * sigh, I should be more thorough with looking at error messages. * beenus * gay sex is gay * this one goes out to bingo * reviews * not sure why status lifetime description wasn't being commited * Update MovespeedModifierMetabolism.cs Co-authored-by: mirrorcult * adds VV to component variables * rebalances meth, and makes the completely unrealistic recipe properly work now * meth effects should go away now or something do you think I test these changes before pushing?? * ah yes, orginization * adds proper recipe and prequisite chemicals * fixes linter hopefully * Update chemicals.yml * a * starts working on prediction * thing * predmiction?? * changes thing * does it properly * uses timespan instead of timer * uses dif timers and adds a system * updates robust and tweaks a small thing * Fixes * "Fix" prediction * starts changing the timer to timespans to avoid icky on timer end * okay fixes the check thing but now meth is broken and I don't know why * fixes predicition (partially) * Delete ContentNetIDs.cs whoops * some changes advised by sloth * certified scalycode fix right here * moves resettimer to the metabolism to make it less oop stinky * moves resettimer to the metabolism to make it less oop stinky * gamin * when the is * updates mth colour to be accurate because I forgot * abc hard ok * everything should be up to date now * makes MovespeedModifierMetabolism ECS and cleans up some other stuff * does a fixy wixy * fix thing * Revert "Merge branch 'master' of https://github.com/space-wizards/space-station-14 into meth" This reverts commit 62886561098be02f9adb6352f4e858a8269d5bd5, reversing changes made to ca34fffb5b7a40f19aec7b9e4bc37bdeab914bc1. * Revert "Revert "Merge branch 'master' of https://github.com/space-wizards/space-station-14 into meth"" This reverts commit 4f550da19656abfd0be05f818fc6b7100252d5b8. * fix hopefully * updates metabolism to works with mirror's fancy new system * updates yaml + tweaks * bruh * yaml moment * :yaml moment * Revert " :yaml moment" This reverts commit 8cb51573c64db76d989de22acdbb9c50b2c6d052. * 99th commit yay, also I need to not do this * removes something that I don't need * makes system work with this and gets rid of unnesescary check * make the update only work on active components * oops * Cleanup * alphabetise this shit * Touchup * Woops stupid alloc by me * Nerf nyoom for now Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: mirrorcult Co-authored-by: metalgearsloth --- .../ReagentEffects/MovespeedModifier.cs | 69 +++++++++++++++++ .../MovespeedModifierMetabolismComponent.cs | 54 +++++++++++++ .../MetabolismMovespeedModifierSystem.cs | 77 +++++++++++++++++++ .../Prototypes/Body/Mechanisms/human.yml | 39 ++++++---- .../Catalog/ReagentDispensers/chemical.yml | 2 + Resources/Prototypes/Reagents/chemicals.yml | 27 +++++++ .../Recipes/Reactions/chemicals.yml | 28 +++++++ 7 files changed, 283 insertions(+), 13 deletions(-) create mode 100644 Content.Server/Chemistry/ReagentEffects/MovespeedModifier.cs create mode 100644 Content.Shared/Chemistry/Components/MovespeedModifierMetabolismComponent.cs create mode 100644 Content.Shared/Chemistry/MetabolismMovespeedModifierSystem.cs diff --git a/Content.Server/Chemistry/ReagentEffects/MovespeedModifier.cs b/Content.Server/Chemistry/ReagentEffects/MovespeedModifier.cs new file mode 100644 index 0000000000..9031737443 --- /dev/null +++ b/Content.Server/Chemistry/ReagentEffects/MovespeedModifier.cs @@ -0,0 +1,69 @@ +using Content.Shared.Chemistry.Reagent; +using Robust.Shared.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; +using Content.Shared.Movement.Components; +using Content.Shared.Chemistry.Components; +using Robust.Shared.Timing; +using Robust.Shared.IoC; +using System; +using Content.Shared.Chemistry.Solution; + +namespace Content.Server.Chemistry.ReagentEffects +{ + /// + /// Default metabolism for stimulants and tranqs. Attempts to find a MovementSpeedModifier on the target, + /// adding one if not there and to change the movespeed + /// + public class MovespeedModifier : ReagentEffect + { + /// + /// How much the entities' walk speed is multiplied by. + /// + [DataField("walkSpeedModifier")] + public float WalkSpeedModifier { get; set; } = 1; + + /// + /// How much the entities' run speed is multiplied by. + /// + [DataField("sprintSpeedModifier")] + public float SprintSpeedModifier { get; set; } = 1; + + /// + /// How long the modifier applies (in seconds) when metabolized. + /// + [DataField("statusLifetime")] + public float StatusLifetime = 2f; + + /// + /// Remove reagent at set rate, changes the movespeed modifiers and adds a MovespeedModifierMetabolismComponent if not already there. + /// + public override void Metabolize(IEntity solutionEntity, Solution.ReagentQuantity amount) + { + if (!solutionEntity.TryGetComponent(out MovementSpeedModifierComponent? movement)) return; + + solutionEntity.EnsureComponent(out MovespeedModifierMetabolismComponent status); + + // Only refresh movement if we need to. + var modified = !status.WalkSpeedModifier.Equals(WalkSpeedModifier) || + !status.SprintSpeedModifier.Equals(SprintSpeedModifier); + + status.WalkSpeedModifier = WalkSpeedModifier; + status.SprintSpeedModifier = SprintSpeedModifier; + + IncreaseTimer(status, StatusLifetime * amount.Quantity.Float()); + + if (modified) + movement.RefreshMovementSpeedModifiers(); + + } + public void IncreaseTimer(MovespeedModifierMetabolismComponent status, float time) + { + var gameTiming = IoCManager.Resolve(); + + var offsetTime = Math.Max(status.ModifierTimer.TotalSeconds, gameTiming.CurTime.TotalSeconds); + + status.ModifierTimer = TimeSpan.FromSeconds(offsetTime + time); + status.Dirty(); + } + } +} diff --git a/Content.Shared/Chemistry/Components/MovespeedModifierMetabolismComponent.cs b/Content.Shared/Chemistry/Components/MovespeedModifierMetabolismComponent.cs new file mode 100644 index 0000000000..afcd0f3f42 --- /dev/null +++ b/Content.Shared/Chemistry/Components/MovespeedModifierMetabolismComponent.cs @@ -0,0 +1,54 @@ +using Content.Shared.Movement.Components; +using Robust.Shared.GameObjects; +using Robust.Shared.Players; +using Robust.Shared.Serialization; +using Robust.Shared.ViewVariables; +using System; +using Robust.Shared.GameStates; +using Robust.Shared.Timing; +using Robust.Shared.IoC; + +namespace Content.Shared.Chemistry.Components +{ + //TODO: refactor movement modifier component because this is a pretty poor solution + [RegisterComponent] + [NetworkedComponent] + public sealed class MovespeedModifierMetabolismComponent : Component, IMoveSpeedModifier + { + [ViewVariables] + public override string Name => "MovespeedModifierMetabolism"; + + [ViewVariables] + public float WalkSpeedModifier { get; set; } + + [ViewVariables] + public float SprintSpeedModifier { get; set; } + + /// + /// When the current modifier is expected to end. + /// + [ViewVariables] + public TimeSpan ModifierTimer { get; set; } = TimeSpan.Zero; + + public override ComponentState GetComponentState(ICommonSession player) + { + return new MovespeedModifierMetabolismComponentState(WalkSpeedModifier, SprintSpeedModifier, ModifierTimer); + } + + [Serializable, NetSerializable] + public class MovespeedModifierMetabolismComponentState : ComponentState + { + public float WalkSpeedModifier { get; } + public float SprintSpeedModifier { get; } + public TimeSpan ModifierTimer { get; } + + public MovespeedModifierMetabolismComponentState(float walkSpeedModifier, float sprintSpeedModifier, TimeSpan modifierTimer) + { + WalkSpeedModifier = walkSpeedModifier; + SprintSpeedModifier = sprintSpeedModifier; + ModifierTimer = modifierTimer; + } + } + } +} + diff --git a/Content.Shared/Chemistry/MetabolismMovespeedModifierSystem.cs b/Content.Shared/Chemistry/MetabolismMovespeedModifierSystem.cs new file mode 100644 index 0000000000..e67f5ae7da --- /dev/null +++ b/Content.Shared/Chemistry/MetabolismMovespeedModifierSystem.cs @@ -0,0 +1,77 @@ +using Content.Shared.Chemistry.Components; +using Robust.Shared.GameObjects; +using Robust.Shared.GameStates; +using Robust.Shared.IoC; +using Robust.Shared.Timing; +using System.Collections.Generic; +using System.Linq; +using Content.Shared.Movement.Components; +using static Content.Shared.Chemistry.Components.MovespeedModifierMetabolismComponent; + +namespace Content.Shared.Chemistry +{ + public class MetabolismMovespeedModifierSystem : EntitySystem + { + [Dependency] private readonly IGameTiming _gameTiming = default!; + + private readonly List _components = new(); + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnMovespeedHandleState); + SubscribeLocalEvent(AddComponent); + } + + private void OnMovespeedHandleState(EntityUid uid, MovespeedModifierMetabolismComponent component, ComponentHandleState args) + { + if (args.Current is not MovespeedModifierMetabolismComponentState cast) + return; + + if (ComponentManager.TryGetComponent(uid, out var modifier) && + (!component.WalkSpeedModifier.Equals(cast.WalkSpeedModifier) || + !component.SprintSpeedModifier.Equals(cast.SprintSpeedModifier))) + { + modifier.RefreshMovementSpeedModifiers(); + } + + component.WalkSpeedModifier = cast.WalkSpeedModifier; + component.SprintSpeedModifier = cast.SprintSpeedModifier; + component.ModifierTimer = cast.ModifierTimer; + + } + private void AddComponent(EntityUid uid, MovespeedModifierMetabolismComponent component, ComponentStartup args) + { + _components.Add(component); + } + + public override void Update(float frameTime) + { + base.Update(frameTime); + + var currentTime = _gameTiming.CurTime; + + for (var i = _components.Count - 1; i >= 0; i--) + { + var component = _components[i]; + + if (component.Deleted) + { + _components.RemoveAt(i); + continue; + } + + if (component.ModifierTimer > currentTime) continue; + + _components.RemoveAt(i); + ComponentManager.RemoveComponent(component.Owner.Uid); + + if (component.Owner.TryGetComponent(out MovementSpeedModifierComponent? modifier)) + { + modifier.RefreshMovementSpeedModifiers(); + } + } + } + } +} diff --git a/Resources/Prototypes/Body/Mechanisms/human.yml b/Resources/Prototypes/Body/Mechanisms/human.yml index 8de6180529..44652e4e65 100644 --- a/Resources/Prototypes/Body/Mechanisms/human.yml +++ b/Resources/Prototypes/Body/Mechanisms/human.yml @@ -121,11 +121,6 @@ # You're technically 'immune to poison' without a heart, but.. uhh, you'll have bigger problems on your hands. - type: Metabolizer metabolisms: - Dylovene: - effects: - - !type:HealthChange - damageClass: Toxin - healthChange: -1 Arithrazine: effects: - !type:HealthChange @@ -154,26 +149,39 @@ - !type:HealthChange damageClass: Airloss healthChange: -3 - Kelotane: + Dylovene: effects: - - !type:HealthChange - damageClass: Burn - healthChange: -1 - Synaptizine: + - !type:HealthChange + damageClass: Toxin + healthChange: -1 + Ephedrine: effects: - - !type:HealthChange - damageClass: Toxin - healthChange: 0.5 + - !type:MovespeedModifier + walkSpeedModifier: 1.2 + sprintSpeedModifier: 1.2 HeartbreakerToxin: effects: - !type:HealthChange damageClass: Airloss healthChange: 4 + Kelotane: + effects: + - !type:HealthChange + damageClass: Burn + healthChange: -1 Lexorin: effects: - !type:HealthChange damageClass: Airloss healthChange: 7 + Meth: + effects: + - !type:HealthChange + healthChange: 2.5 + damageClass: Toxin + - !type:MovespeedModifier + walkSpeedModifier: 1.3 + sprintSpeedModifier: 1.3 Omnizine: effects: - !type:HealthChange @@ -188,6 +196,11 @@ - !type:HealthChange healthChange: -2 damageClass: Brute + Synaptizine: + effects: + - !type:HealthChange + damageClass: Toxin + healthChange: 0.5 - type: entity id: OrganHumanStomach diff --git a/Resources/Prototypes/Catalog/ReagentDispensers/chemical.yml b/Resources/Prototypes/Catalog/ReagentDispensers/chemical.yml index 70073d0dde..a13d46df4b 100644 --- a/Resources/Prototypes/Catalog/ReagentDispensers/chemical.yml +++ b/Resources/Prototypes/Catalog/ReagentDispensers/chemical.yml @@ -9,6 +9,7 @@ - Fluorine - Glucose - Hydrogen + - Iodine - Iron - Lithium - Mercury @@ -25,3 +26,4 @@ - SulfuricAcid - Uranium - Water + diff --git a/Resources/Prototypes/Reagents/chemicals.yml b/Resources/Prototypes/Reagents/chemicals.yml index ff882e463c..fb5be33970 100644 --- a/Resources/Prototypes/Reagents/chemicals.yml +++ b/Resources/Prototypes/Reagents/chemicals.yml @@ -222,6 +222,33 @@ - !type:AdjustWater amount: 1 +- type: reagent + id: Meth + name: meth + desc: Methamphetamine, more commonly know as meth, is a potent stimulant, with dangerous side-effects if too much is consumed. + physicalDesc: translucent + color: "#FAFAFA" + boilingPoint: 212.0 #Meth vape when? + meltingPoint: 170.0 + +- type: reagent + id: Iodine + name: iodine + desc: Commonly added to table salt as a nutrient. On its own it tastes far less pleasing. + physicalDesc: Dark Brown + color: "#BC8A00" + boilingPoint: 184.3 + meltingPoint: 113.7 + +- type: reagent + id: Ephedrine + name: ephedrine + desc: Increases stun resistance and movement speed, giving you hand cramps. Overdose deals toxin damage and inhibits breathing + physicalDesc: Bone white + color: "#D2FFFA" + boilingPoint: 255.0 + meltingPoint: 36.0 + - type: reagent id: Oil name: oil diff --git a/Resources/Prototypes/Recipes/Reactions/chemicals.yml b/Resources/Prototypes/Recipes/Reactions/chemicals.yml index e719e598fe..511edf22e3 100644 --- a/Resources/Prototypes/Recipes/Reactions/chemicals.yml +++ b/Resources/Prototypes/Recipes/Reactions/chemicals.yml @@ -226,3 +226,31 @@ amount: 1 products: Fluorosurfactant: 5 + +- type: reaction + id: Meth + reactants: + Ephedrine: + amount: 1 + Carbon: + amount: 1 + Iodine: + amount: 1 + Phosphorus: + amount: 1 + products: + Meth: 4 #I kinda remember having to heat this up, and if you heated it up too much, it went boom, I can't remember the specific values tho. + +- type: reaction + id: Ephedrine + reactants: + Oil: + amount: 1 + Hydrogen: + amount: 1 + Sugar: + amount: 1 + Diethylamine: + amount: 1 + products: + Ephedrine: 4