From 3d708971f6e0ba9578e68cb97698452fd17c372e Mon Sep 17 00:00:00 2001 From: MLGTASTICa Date: Fri, 22 Oct 2021 13:31:06 +0300 Subject: [PATCH 01/24] part 1 --- .../Sanity/MobSanityComponent.Designer.cs | 37 ++++++++++++++ Content.Server/Sanity/MobSanityComponent.cs | 49 +++++++++++++++++++ Content.Shared/Alert/AlertType.cs | 12 +++-- 3 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 Content.Server/Sanity/MobSanityComponent.Designer.cs create mode 100644 Content.Server/Sanity/MobSanityComponent.cs diff --git a/Content.Server/Sanity/MobSanityComponent.Designer.cs b/Content.Server/Sanity/MobSanityComponent.Designer.cs new file mode 100644 index 000000000000..e24439411ea0 --- /dev/null +++ b/Content.Server/Sanity/MobSanityComponent.Designer.cs @@ -0,0 +1,37 @@ + +namespace Content.Server.Sanity +{ + partial class MobSanityComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + + #endregion + } +} diff --git a/Content.Server/Sanity/MobSanityComponent.cs b/Content.Server/Sanity/MobSanityComponent.cs new file mode 100644 index 000000000000..8be5f7b93191 --- /dev/null +++ b/Content.Server/Sanity/MobSanityComponent.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using Content.Server.Alert; +using Content.Shared.Alert; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Content.Server.Sanity +{ + public partial class MobSanityComponent : Component + { + public int Sanity = 0; + + public int SanityGainDefault = 5; + + public int MaxSanityDecayPerCycle = 20; + + public Dictionary SanityThresholds { get; } = new() + { + { SanityThreshold.FeelingGreat, 80 }, + { SanityThreshold.Happy , 60 }, + { SanityThreshold.Normal, 40 }, + { SanityThreshold.Unhinged, 30}, + { SanityThreshold.Crazy, 15}, + }; + + public static readonly Dictionary SanityThresholdAlertTypes = new() + { + { SanityThreshold.FeelingGreat, AlertType.FeelingGreat }, + { SanityThreshold.Happy, AlertType.Happy }, + { SanityThreshold.Normal, AlertType.Normal }, + { SanityThreshold.Unhinged, AlertType.Unhinged }, + { SanityThreshold.Crazy, AlertType.Crazy }, + }; + + public enum SanityThreshold : byte + { + // psychohomies + FeelingGreat, + Happy, + Normal, + Unhinged, + Crazy, + } + } +} diff --git a/Content.Shared/Alert/AlertType.cs b/Content.Shared/Alert/AlertType.cs index a4962a1d36fa..9d776faf0c95 100644 --- a/Content.Shared/Alert/AlertType.cs +++ b/Content.Shared/Alert/AlertType.cs @@ -1,4 +1,4 @@ -namespace Content.Shared.Alert +namespace Content.Shared.Alert { /// /// Every category of alert. Corresponds to category field in alert prototypes defined in YML @@ -12,7 +12,8 @@ public enum AlertCategory Health, Piloting, Hunger, - Thirst + Thirst, + Sanity } /// @@ -51,7 +52,12 @@ public enum AlertType : byte Debug3, Debug4, Debug5, - Debug6 + Debug6, + Crazy, + Unhinged, + Normal, + Happy, + FeelingGreat } } From 079f534affe2816c9c806ca4cc6a5505e7365eb4 Mon Sep 17 00:00:00 2001 From: MLGTASTICa Date: Fri, 22 Oct 2021 18:43:50 +0300 Subject: [PATCH 02/24] part2 --- Content.Client/Entry/IgnoredComponents.cs | 3 +- .../Sanity/MobSanityComponent.Designer.cs | 37 -------- Content.Server/Sanity/MobSanityComponent.cs | 31 ++++++- Content.Server/Sanity/SanitySystem.cs | 80 ++++++++++++++++++ Content.Shared/Alert/AlertType.cs | 6 +- Content.Shared/Content.Shared.csproj | 3 + .../{ => Alerts}/Actions/actions.yml | 0 .../{ => Alerts}/Actions/item_actions.yml | 0 .../{ => Alerts}/Actions/magboots.yml | 0 .../{ => Alerts}/Actions/spells.yml | 0 Resources/Prototypes/Alerts/alerts.yml | 11 +++ .../Prototypes/Entities/Mobs/Player/human.yml | 1 + .../Interface/Alerts/sanity.rsi/meta.json | 29 +++++++ .../Interface/Alerts/sanity.rsi/sanity0.png | Bin 0 -> 359 bytes .../Interface/Alerts/sanity.rsi/sanity1.png | Bin 0 -> 354 bytes .../Interface/Alerts/sanity.rsi/sanity2.png | Bin 0 -> 359 bytes .../Interface/Alerts/sanity.rsi/sanity3.png | Bin 0 -> 361 bytes .../Interface/Alerts/sanity.rsi/sanity4.png | Bin 0 -> 356 bytes .../Interface/Alerts/sanity.rsi/sanity5.png | Bin 0 -> 344 bytes 19 files changed, 154 insertions(+), 47 deletions(-) create mode 100644 Content.Server/Sanity/SanitySystem.cs rename Resources/Prototypes/{ => Alerts}/Actions/actions.yml (100%) rename Resources/Prototypes/{ => Alerts}/Actions/item_actions.yml (100%) rename Resources/Prototypes/{ => Alerts}/Actions/magboots.yml (100%) rename Resources/Prototypes/{ => Alerts}/Actions/spells.yml (100%) create mode 100644 Resources/Textures/Interface/Alerts/sanity.rsi/meta.json create mode 100644 Resources/Textures/Interface/Alerts/sanity.rsi/sanity0.png create mode 100644 Resources/Textures/Interface/Alerts/sanity.rsi/sanity1.png create mode 100644 Resources/Textures/Interface/Alerts/sanity.rsi/sanity2.png create mode 100644 Resources/Textures/Interface/Alerts/sanity.rsi/sanity3.png create mode 100644 Resources/Textures/Interface/Alerts/sanity.rsi/sanity4.png create mode 100644 Resources/Textures/Interface/Alerts/sanity.rsi/sanity5.png diff --git a/Content.Client/Entry/IgnoredComponents.cs b/Content.Client/Entry/IgnoredComponents.cs index 4d710806f9c7..f01c8d773454 100644 --- a/Content.Client/Entry/IgnoredComponents.cs +++ b/Content.Client/Entry/IgnoredComponents.cs @@ -284,7 +284,8 @@ public static class IgnoredComponents "ToggleDoorOnTrigger", "DeviceNetworkConnection", "WiredNetworkConnection", - "WirelessNetworkConnection" + "WirelessNetworkConnection", + "Sanity" }; } } diff --git a/Content.Server/Sanity/MobSanityComponent.Designer.cs b/Content.Server/Sanity/MobSanityComponent.Designer.cs index e24439411ea0..e69de29bb2d1 100644 --- a/Content.Server/Sanity/MobSanityComponent.Designer.cs +++ b/Content.Server/Sanity/MobSanityComponent.Designer.cs @@ -1,37 +0,0 @@ - -namespace Content.Server.Sanity -{ - partial class MobSanityComponent - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Component Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - components = new System.ComponentModel.Container(); - } - - #endregion - } -} diff --git a/Content.Server/Sanity/MobSanityComponent.cs b/Content.Server/Sanity/MobSanityComponent.cs index 8be5f7b93191..8801709f8520 100644 --- a/Content.Server/Sanity/MobSanityComponent.cs +++ b/Content.Server/Sanity/MobSanityComponent.cs @@ -1,23 +1,45 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using Content.Server.Alert; using Content.Shared.Alert; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; +using Robust.Shared.GameObjects.Components; +using Robust.Server.GameObjects; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Server.Player; +using Robust.Shared.GameObjects; +using Robust.Shared.Map; namespace Content.Server.Sanity { + [RegisterComponent()] public partial class MobSanityComponent : Component { - public int Sanity = 0; + public override string Name => "Sanity"; + public int Sanity + { + get => Sanity; + set + { + if (Sanity + value > MaxSanity) + { + Sanity = MaxSanity; + } + else + Sanity += value; + + } + } public int SanityGainDefault = 5; public int MaxSanityDecayPerCycle = 20; + public int MaxSanity = 100; + /* public Dictionary SanityThresholds { get; } = new() { { SanityThreshold.FeelingGreat, 80 }, @@ -35,15 +57,16 @@ public partial class MobSanityComponent : Component { SanityThreshold.Unhinged, AlertType.Unhinged }, { SanityThreshold.Crazy, AlertType.Crazy }, }; - + public enum SanityThreshold : byte { - // psychohomies + // psychomies FeelingGreat, Happy, Normal, Unhinged, Crazy, } + */ } } diff --git a/Content.Server/Sanity/SanitySystem.cs b/Content.Server/Sanity/SanitySystem.cs new file mode 100644 index 000000000000..7a1601e1ce7b --- /dev/null +++ b/Content.Server/Sanity/SanitySystem.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Robust.Server.GameObjects; +using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects.Components; +using Robust.Server.Placement; +using Robust.Server.Player; +using Content.Shared.Alert; +using Content.Server.Alert; + +namespace Content.Server.Sanity +{ + public class SanitySystem : EntitySystem + { + + public float frameaccul = 0.0f; + public HashSet SanityCompsToTick = new(); + + + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnInit); + SubscribeLocalEvent(OnDelete); + } + + public void OnInit(EntityUid uid, MobSanityComponent component, ComponentInit args) + { + SanityCompsToTick.Add(component); + } + + public void OnDelete(EntityUid uid, MobSanityComponent component, ComponentRemove args) + { + SanityCompsToTick.Remove(component); + } + + + public override void Update(float frameTime) + { + frameaccul += frameTime; + if(frameaccul > 10.0f) + { + frameaccul = 0.0f; + } + else + { + return; + } + /* + if(Counter > 10) + { + Counter = 0; + } + else + { + Counter++; + return; + } + */ + + foreach (MobSanityComponent component in EntityManager.EntityQuery()) + { + component.Sanity += component.SanityGainDefault; + if (!component.Owner.TryGetComponent(out ServerAlertsComponent? alerts)) + { + continue; + } + short variable = 2; + alerts.ShowAlert(AlertType.MobSanity, variable); + } + + } + } +} + + + diff --git a/Content.Shared/Alert/AlertType.cs b/Content.Shared/Alert/AlertType.cs index 9d776faf0c95..3e5198030791 100644 --- a/Content.Shared/Alert/AlertType.cs +++ b/Content.Shared/Alert/AlertType.cs @@ -53,11 +53,7 @@ public enum AlertType : byte Debug4, Debug5, Debug6, - Crazy, - Unhinged, - Normal, - Happy, - FeelingGreat + MobSanity } } diff --git a/Content.Shared/Content.Shared.csproj b/Content.Shared/Content.Shared.csproj index 86e05845c9fa..6d14c455e689 100644 --- a/Content.Shared/Content.Shared.csproj +++ b/Content.Shared/Content.Shared.csproj @@ -29,6 +29,9 @@ + + + diff --git a/Resources/Prototypes/Actions/actions.yml b/Resources/Prototypes/Alerts/Actions/actions.yml similarity index 100% rename from Resources/Prototypes/Actions/actions.yml rename to Resources/Prototypes/Alerts/Actions/actions.yml diff --git a/Resources/Prototypes/Actions/item_actions.yml b/Resources/Prototypes/Alerts/Actions/item_actions.yml similarity index 100% rename from Resources/Prototypes/Actions/item_actions.yml rename to Resources/Prototypes/Alerts/Actions/item_actions.yml diff --git a/Resources/Prototypes/Actions/magboots.yml b/Resources/Prototypes/Alerts/Actions/magboots.yml similarity index 100% rename from Resources/Prototypes/Actions/magboots.yml rename to Resources/Prototypes/Alerts/Actions/magboots.yml diff --git a/Resources/Prototypes/Actions/spells.yml b/Resources/Prototypes/Alerts/Actions/spells.yml similarity index 100% rename from Resources/Prototypes/Actions/spells.yml rename to Resources/Prototypes/Alerts/Actions/spells.yml diff --git a/Resources/Prototypes/Alerts/alerts.yml b/Resources/Prototypes/Alerts/alerts.yml index a4fbd86d5c4b..42d41a52b846 100644 --- a/Resources/Prototypes/Alerts/alerts.yml +++ b/Resources/Prototypes/Alerts/alerts.yml @@ -231,3 +231,14 @@ icon: /Textures/Interface/Alerts/human_health.rsi/health6.png name: Debug6 description: Debug + +- type: alert + alertType: MobSanity + category: Sanity + icon: + sprite: /Textures/Interface/Alerts/sanity.rsi + state: sanity + name: Sanity + description: How nuts are you right now? + minSeverity: 0 + maxSeverity: 5 diff --git a/Resources/Prototypes/Entities/Mobs/Player/human.yml b/Resources/Prototypes/Entities/Mobs/Player/human.yml index 8f5ef460c7d1..30e4e797f0ee 100644 --- a/Resources/Prototypes/Entities/Mobs/Player/human.yml +++ b/Resources/Prototypes/Entities/Mobs/Player/human.yml @@ -17,6 +17,7 @@ - CombatMode - Disarm - HumanScream + - type: Sanity - type: Eye - type: CameraRecoil - type: Examiner diff --git a/Resources/Textures/Interface/Alerts/sanity.rsi/meta.json b/Resources/Textures/Interface/Alerts/sanity.rsi/meta.json new file mode 100644 index 000000000000..a47c0f06b5e4 --- /dev/null +++ b/Resources/Textures/Interface/Alerts/sanity.rsi/meta.json @@ -0,0 +1,29 @@ +{ + "version": 1, + "license": "CC-BY-SA-3.0", + "copyright": "https://github.com/discordia-space/CEV-Eris/pull/4028", + "size": { + "x": 32, + "y": 32 + }, + "states": [ + { + "name": "sanity0" + }, + { + "name": "sanity1" + }, + { + "name": "sanity2" + }, + { + "name": "sanity3" + }, + { + "name": "sanity4" + }, + { + "name": "sanity5" + } + ] +} \ No newline at end of file diff --git a/Resources/Textures/Interface/Alerts/sanity.rsi/sanity0.png b/Resources/Textures/Interface/Alerts/sanity.rsi/sanity0.png new file mode 100644 index 0000000000000000000000000000000000000000..ba61cf1ea30b28577beb9cb4d0b0a0517dc74981 GIT binary patch literal 359 zcmV-t0hs=YP)uk;reiZp7A`AJrFZaS+pt3dqW6ZUN^RDYA8i7|~|AYN;Q!o~Ce!~S<1E2L; zGC5Z3)zcfHB0L*HaW~uOf>r?(6j0L0?KBj?B3L?qvP^VNWywK2-AW(5WVN zL69Q=(L)%`yA6VP?Lz>m&N&b-gd_zTA`6RAQUp-8;%)xl5e~&eEChg|LkI+sM1!{K zxUZ8^Kp_wW#ldK1k8fs(01yHk5Eq6MI)6YQB{74@2jbfYyK}1r63zqkKthcrZHcyr z#hB}Ld`cG-(f>@?wTyZp!$^oh(Ld}6DC&wPxL zjH~&m@rJ7iLqk-yn`MlGQUNMTprU)ASb&CL91AV;$Pf!adyFL5GZX+D``&H<(+1i( zL3{waf;eCpWV5{s0Na-Z0`|T_^xFMpF&`2%vFA z%84Lb0JPQI6pdi%C(LpTln_xIK+5x%12m983xN4bg+%%S!p}W(q)43v00000NkvXX Hu0mjf?dXkT literal 0 HcmV?d00001 diff --git a/Resources/Textures/Interface/Alerts/sanity.rsi/sanity4.png b/Resources/Textures/Interface/Alerts/sanity.rsi/sanity4.png new file mode 100644 index 0000000000000000000000000000000000000000..8a612392d0b951f325c4a5e40974e3ae784b1d18 GIT binary patch literal 356 zcmV-q0h|7bP)FUBE$AX8ujz};1E0B# z7bRA6D|v^@gl9u2TW21pAXfl|2+Dc|vIVHX&aserjto};v>q`WOrHfniD`E9TW`df z{>l+|2tXz$(V(;)dTkUx2#`$(7l6+UYPdxpn-Kq=0wa-$Ie_klAm zB)b*$F30zsFiQ`Vh$soLSKTfJXple)fO$(rB7Fg&us9J7iR@|s00006E>jD479;_ z{_hl>F}CAZ!GC8SLRg<|`SGC20>HCU{FV2>yKwMHU*r%hg@TWGu;sw#D0`;B-BEgO za3x`Ch|XqgW)?IF&`|+3-2=@648-QKkX}c&TmUZ*9}cEc0U$71hj(@2r|pBoF9<*e zhm`rI?W3@f@#P?=5H0|p7L4Q;Ku#e_&4Q>N0J)@J$lf9hNsz93fI}b;HU`1P^8`~B zkbeyUuY?D(Rmj%}`JYuGIp9?x{eo%VnH>8{OcHu6Fh;Yv?-X$!NO2&!+)?lC_&yUh qnFBo)lmxii-Le8qR6zh(sgl05x-|N$ijpw^0000 Date: Sat, 23 Oct 2021 14:14:19 +0300 Subject: [PATCH 03/24] Update MobSanityComponent.cs --- Content.Server/Sanity/MobSanityComponent.cs | 65 ++++++++++----------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/Content.Server/Sanity/MobSanityComponent.cs b/Content.Server/Sanity/MobSanityComponent.cs index 8801709f8520..464fcb870b5e 100644 --- a/Content.Server/Sanity/MobSanityComponent.cs +++ b/Content.Server/Sanity/MobSanityComponent.cs @@ -12,61 +12,60 @@ using Robust.Server.Player; using Robust.Shared.GameObjects; using Robust.Shared.Map; +using Robust.Shared.ViewVariables; namespace Content.Server.Sanity { [RegisterComponent()] - public partial class MobSanityComponent : Component + public class MobSanityComponent : Component { public override string Name => "Sanity"; + public int Sanity { - get => Sanity; + get => _sanity; set { - if (Sanity + value > MaxSanity) + if (_sanity + value > MaxSanity) { - Sanity = MaxSanity; + _sanity = MaxSanity; } else - Sanity += value; + _sanity += value; } - } + } + /// + /// Internal variable for handling sanity set and get. + /// + private int _sanity = 0; public int SanityGainDefault = 5; + /// + /// Maximum sanity to lose per cycle. Can be influenced + /// public int MaxSanityDecayPerCycle = 20; + /// + /// This divides max sanity to show the sanity hud element sprite, automatically updated when max sanity changes , do not touch. + /// - public int MaxSanity = 100; - /* - public Dictionary SanityThresholds { get; } = new() - { - { SanityThreshold.FeelingGreat, 80 }, - { SanityThreshold.Happy , 60 }, - { SanityThreshold.Normal, 40 }, - { SanityThreshold.Unhinged, 30}, - { SanityThreshold.Crazy, 15}, - }; + public int SanitySteps = 20; - public static readonly Dictionary SanityThresholdAlertTypes = new() - { - { SanityThreshold.FeelingGreat, AlertType.FeelingGreat }, - { SanityThreshold.Happy, AlertType.Happy }, - { SanityThreshold.Normal, AlertType.Normal }, - { SanityThreshold.Unhinged, AlertType.Unhinged }, - { SanityThreshold.Crazy, AlertType.Crazy }, - }; - - public enum SanityThreshold : byte + /// + /// This is the maximum sanity , the more a player has the bigger the buffer between the stages becomes + /// + public int MaxSanity { - // psychomies - FeelingGreat, - Happy, - Normal, - Unhinged, - Crazy, + get => _maxSanity; + set + { + _maxSanity = value; + SanitySteps = _maxSanity / 6; + } } - */ + + private int _maxSanity = 100; + } } From 482db1c0bf626e38655497842ccb5fe8b139aa0b Mon Sep 17 00:00:00 2001 From: MLGTASTICa Date: Sat, 23 Oct 2021 17:33:01 +0300 Subject: [PATCH 04/24] Part4 --- Content.Client/Content.Client.csproj | 8 ++ Content.Client/Sanity/UI/SanityInterface.cs | 54 ++++++++++++ Content.Client/Sanity/UI/SanityUI.cs | 26 ++++++ Content.Client/Sanity/UI/SanityWindow.xaml | 8 ++ Content.Server/Sanity/MobSanityComponent.cs | 83 +++++++++++++++++- Content.Server/Sanity/SanitySystem.cs | 32 +++---- Content.Shared/Content.Shared.csproj | 3 - .../Sanity/SharedMobSanityComponent.cs | 61 +++++++++++++ .../Interface/Alerts/sanity.rsi/sanity0.png | Bin 359 -> 344 bytes .../Interface/Alerts/sanity.rsi/sanity2.png | Bin 359 -> 356 bytes .../Interface/Alerts/sanity.rsi/sanity4.png | Bin 356 -> 359 bytes .../Interface/Alerts/sanity.rsi/sanity5.png | Bin 344 -> 359 bytes 12 files changed, 246 insertions(+), 29 deletions(-) create mode 100644 Content.Client/Sanity/UI/SanityInterface.cs create mode 100644 Content.Client/Sanity/UI/SanityUI.cs create mode 100644 Content.Client/Sanity/UI/SanityWindow.xaml create mode 100644 Content.Shared/Sanity/SharedMobSanityComponent.cs diff --git a/Content.Client/Content.Client.csproj b/Content.Client/Content.Client.csproj index 183e06394f9f..0b372159d220 100644 --- a/Content.Client/Content.Client.csproj +++ b/Content.Client/Content.Client.csproj @@ -26,5 +26,13 @@ + + + + + + MSBuild:Compile + + diff --git a/Content.Client/Sanity/UI/SanityInterface.cs b/Content.Client/Sanity/UI/SanityInterface.cs new file mode 100644 index 000000000000..a8c9f4cb13ba --- /dev/null +++ b/Content.Client/Sanity/UI/SanityInterface.cs @@ -0,0 +1,54 @@ +using Content.Shared.Sanity; +using Robust.Client.GameObjects; +using Robust.Shared.GameObjects; +using Content.Client.Sanity; + +namespace Content.Client.Sanity.UI +{ + /// + /// Initializes a and updates it when new server messages are received. + /// + public class SanityBoundUserInterface : BoundUserInterface + { + private SanityWindow? _window; + + public SanityBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) + { + } + + protected override void Open() + { + base.Open(); + + _window = new SanityWindow(); + if (State != null) + UpdateState(State); + + _window.OpenCentered(); + + _window.OnClose += Close; + + } + + /// + /// Update the UI state based on server-sent info + /// + /// + protected override void UpdateState(BoundUserInterfaceState state) + { + base.UpdateState(state); + if (_window == null || state is not SanityBoundUserInterface cast) + return; + + _window.SetCurrentLabel(cast.CurrentLabel); + } + + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + if (!disposing) return; + _window?.Dispose(); + } + } + +} diff --git a/Content.Client/Sanity/UI/SanityUI.cs b/Content.Client/Sanity/UI/SanityUI.cs new file mode 100644 index 000000000000..c335caf681ee --- /dev/null +++ b/Content.Client/Sanity/UI/SanityUI.cs @@ -0,0 +1,26 @@ +using System; +using Content.Shared.Sanity; +using Robust.Client.UserInterface.CustomControls; +using Robust.Client.AutoGenerated; +using Robust.Client.UserInterface.Controls; +using Robust.Client.UserInterface.XAML; + + +namespace Content.Client.Sanity.UI +{ + [GenerateTypedNameReferences] + public partial class SanityWindow : SS14Window + { + public SanityWindow() + { + RobustXamlLoader.Load(this); + + + } + + } + + + + +} diff --git a/Content.Client/Sanity/UI/SanityWindow.xaml b/Content.Client/Sanity/UI/SanityWindow.xaml new file mode 100644 index 000000000000..1b09257a43ef --- /dev/null +++ b/Content.Client/Sanity/UI/SanityWindow.xaml @@ -0,0 +1,8 @@ + + + + diff --git a/Content.Server/Sanity/MobSanityComponent.cs b/Content.Server/Sanity/MobSanityComponent.cs index 464fcb870b5e..50fb9aeb1787 100644 --- a/Content.Server/Sanity/MobSanityComponent.cs +++ b/Content.Server/Sanity/MobSanityComponent.cs @@ -13,13 +13,17 @@ using Robust.Shared.GameObjects; using Robust.Shared.Map; using Robust.Shared.ViewVariables; +using Content.Shared.Sanity; namespace Content.Server.Sanity { [RegisterComponent()] - public class MobSanityComponent : Component + public class MobSanityComponent : SharedMobSanityComponent { - public override string Name => "Sanity"; + + /// + /// Sanity variables + /// public int Sanity { @@ -39,33 +43,104 @@ public int Sanity /// Internal variable for handling sanity set and get. /// private int _sanity = 0; + /// + /// How much sanity points are given per second, this rounds itself , but losses are aceptable. + /// - public int SanityGainDefault = 5; + [ViewVariables(VVAccess.ReadWrite)] + public float SanityGainPerSecond = 0.1f; /// /// Maximum sanity to lose per cycle. Can be influenced /// + [ViewVariables(VVAccess.ReadWrite)] public int MaxSanityDecayPerCycle = 20; /// /// This divides max sanity to show the sanity hud element sprite, automatically updated when max sanity changes , do not touch. /// + [ViewVariables(VVAccess.ReadOnly)] public int SanitySteps = 20; /// /// This is the maximum sanity , the more a player has the bigger the buffer between the stages becomes /// + [ViewVariables(VVAccess.ReadWrite)] public int MaxSanity { get => _maxSanity; set { _maxSanity = value; + // 6 Sprites so far. SanitySteps = _maxSanity / 6; } } private int _maxSanity = 100; - + + /// + /// Insight variables + /// + [ViewVariables(VVAccess.ReadWrite)] + public int Insight + { + get => _insight; + set + { + if (_insight + value > RequiredInsight) + { + InsightPoints += (_insight + value) / RequiredInsight; + _insight = (_insight + value) % RequiredInsight; + } + else + _insight += value; + } + } + + private int _insight = 0; + + [ViewVariables(VVAccess.ReadWrite)] + public int RequiredInsight = 100; + + [ViewVariables(VVAccess.ReadWrite)] + public int InsightPoints = 0; + + [ViewVariables(VVAccess.ReadWrite)] + public float PassiveInsightGainPerSecond = 0.75f; + + /// + /// Rest variables + /// + [ViewVariables(VVAccess.ReadWrite)] + public int Rest + { + get => _rest; + set + { + if (_rest + value > RestRequired) + { + RestPoints += (_rest + value) / RestRequired; + _rest = (_rest + value) % RestRequired; + } + else + _rest += value; + } + } + + + private int _rest = 0; + + [ViewVariables(VVAccess.ReadWrite)] + public int RestPoints = 0; + + [ViewVariables(VVAccess.ReadWrite)] + public int RestRequired = 100; + + [ViewVariables(VVAccess.ReadWrite)] + public float RestGainPerSecond = 0.75f; + + + } } diff --git a/Content.Server/Sanity/SanitySystem.cs b/Content.Server/Sanity/SanitySystem.cs index 7a1601e1ce7b..e76af03f02b4 100644 --- a/Content.Server/Sanity/SanitySystem.cs +++ b/Content.Server/Sanity/SanitySystem.cs @@ -16,7 +16,8 @@ namespace Content.Server.Sanity public class SanitySystem : EntitySystem { - public float frameaccul = 0.0f; + public float TimeAccumulator = 0.0f; + public float TimeBetweenTicks = 15.0f; public HashSet SanityCompsToTick = new(); @@ -40,36 +41,23 @@ public void OnDelete(EntityUid uid, MobSanityComponent component, ComponentRemov public override void Update(float frameTime) { - frameaccul += frameTime; - if(frameaccul > 10.0f) + TimeAccumulator += frameTime; + if (TimeAccumulator < TimeBetweenTicks) { - frameaccul = 0.0f; - } - else - { - return; - } - /* - if(Counter > 10) - { - Counter = 0; - } - else - { - Counter++; + TimeAccumulator += frameTime; return; } - */ + TimeAccumulator = 0.0f; + - foreach (MobSanityComponent component in EntityManager.EntityQuery()) + foreach (MobSanityComponent component in SanityCompsToTick) { - component.Sanity += component.SanityGainDefault; + component.Sanity += Math.Max((int)(component.SanityGainPerSecond * TimeBetweenTicks), 0); if (!component.Owner.TryGetComponent(out ServerAlertsComponent? alerts)) { continue; } - short variable = 2; - alerts.ShowAlert(AlertType.MobSanity, variable); + alerts.ShowAlert(AlertType.MobSanity, (short)(component.Sanity/component.SanitySteps)); } } diff --git a/Content.Shared/Content.Shared.csproj b/Content.Shared/Content.Shared.csproj index 6d14c455e689..86e05845c9fa 100644 --- a/Content.Shared/Content.Shared.csproj +++ b/Content.Shared/Content.Shared.csproj @@ -29,9 +29,6 @@ - - - diff --git a/Content.Shared/Sanity/SharedMobSanityComponent.cs b/Content.Shared/Sanity/SharedMobSanityComponent.cs new file mode 100644 index 000000000000..e93fea610c82 --- /dev/null +++ b/Content.Shared/Sanity/SharedMobSanityComponent.cs @@ -0,0 +1,61 @@ +using System; +using Robust.Shared.GameObjects; +using Robust.Shared.GameStates; +using Robust.Shared.Serialization; + + +namespace Content.Shared.Sanity +{ + public class SharedMobSanityComponent : Component + { + public override string Name => "Sanity"; + + [Serializable, NetSerializable] + public enum SanityUiKey + { + Key, + } + + [Serializable, NetSerializable] + public class SanityBoundUserInterfaceState : BoundUserInterfaceMessage + { + public int Insight { get; } + public int Sanity { get; } + public int Rest { get; } + + + public SanityBoundUserInterfaceState(int insight, int sanity, int rest) + { + Insight = insight; + Sanity = sanity; + Rest = rest; + } + } + + } + + + + + + + + + + + + + + + + + + + + + + + + + +} diff --git a/Resources/Textures/Interface/Alerts/sanity.rsi/sanity0.png b/Resources/Textures/Interface/Alerts/sanity.rsi/sanity0.png index ba61cf1ea30b28577beb9cb4d0b0a0517dc74981..660a962bec08b40372b9f1db297039895122a3de 100644 GIT binary patch delta 296 zcmV+@0oVTL0@wnOIe!XCL_t(|ob8so5rZ%chE=3t23j`ACM>}Q>1n+|mS7V$pv?@l z!FT@e6rC})<5$6dXC6XWpKbZ^pvnTkvr_z(_rSYw@JV0f5G;j)k9e@oR>=CP1oN48u5FApCMrhifaATU~ocXi^Y?SsQF z2tWphl=-IZqp*?jbzga@)!$kzz@pH(3_;8h|0f@$BG9Q#U45_&B#Mzgu^6mcF%aUi+eQSa^e uJ`*;X13eX#1R=QE-Le8qR6zh(sgl05x-|N$ijpw^0000n0k3S7HBy{c%$;7IJ>W1y=)~ z^;$AHR_oQ%8=)dR8$xk6+vtK;0TdKa(-CMEKm+MxM|O_PxqkreWc~bMPc#5NRPyi8 zsU~(okRt%mLm17w4T5;>LjbAHIS?;|Bn28G3yV=w1W>l(ZT{a84#h((1c0GK2n3Nt zgSP6puai@?LOp&}Oik`2)J97TUe8?^6A|;_SAPMt9x)tDp9MgPX?FBm zZ^W7Y$`N-6Kqe>AptK!&Z4^HUkWB~|fX@tSxJ4kF5dWS6uYE?~3J|%Z?_i%%i-2mn zw*nl3d@wKwF76ZV4T1~a0zL>&WE+q_Bjo?AI^qGZ0r3lFVqb97l@Js98V_r7qY(l3 zfio^7yA|~=$1V4rFiQ`Vh$soLSKTfJXple)fO$(rB7Fg&us9J7iR@|s0000XP{++Y?39|z&&j?$P#Rl4QMk1 zCBcZ3UQXs5S;lt3llYNweBb@RIX5b-4PaT8dkN!B)4VYPugvy)cakX>GZ}yIjjski z>oK2X*sMp316mQLhA_UtI^Kd>0SskO)e)!`pd)yXh1_>!I)4km1`J8CXDR?T9P(}g zqaFNC1qlI2<68J}9>XxmA%q5i9-v1A<5t`w9K-N4FGNfVa4}p|8nWV+g-zc zohf2JkYYm;>@cWTJHGaWRn|aD86^RXP{++Y?39|z&&j?$P#Rl4QMk1 zCBcZ3UQXs5S;lt3llYNweBb@RIX5b-4PaT8dkN!B)4VYPugvy)cakX>GZ}yIjjski z>oK2X*sMp316mQLhA_UtI^Kd>0SskO)e)!`pd)yXh1_>!I)4km1`J8CXDR?T9P(}g zqaFNC1qlI2<68J}9>XxmA%q5i9-v1A<5t`w9K-N4FGNfVa4}p|8nWV+g-zc zohf2JkYYm;>@cWTJHGaWRn|aD86^RLOp&}Oik`2)J97TUe8?^6A|;_SAPMt9x)tDp9MgPX?FBm zZ^W7Y$`N-6Kqe>AptK!&Z4^HUkWB~|fX@tSxJ4kF5dWS6uYE?~3J|%Z?_i%%i-2mn zw*nl3d@wKwF76ZV4T1~a0zL>&WE+q_Bjo?AI^qGZ0r3lFVqb97l@Js98V_r7qY(l3 zfio^7yA|~=$1V4rFiQ`Vh$soLSKTfJXple)fO$(rB7Fg&us9J7iR@|s0000n0k3S7HBy{c%$;7IJ>W1y=)~ z^;$AHR_oQ%8=)dR8$xk6+vtK;0TdKa(-CMEKm+MxM|O_PxqkreWc~bMPc#5NRPyi8 zsU~(okRt%mLm17w4T5;>LjbAHIS?;|Bn28G3yV=w1W>l(ZT{a84#h((1c0GK2n3Nt zgSP6puai@?}Q>1n+|mS7V$pv?@l z!FT@e6rC})<5$6dXC6XWpKbZ^pvnTkvr_z(_rSYw@JV0f5G;j)k9e@oR>=CP1oN48u5FApCMrhifaATU~ocXi^Y?SsQF z2tWphl=-IZqp*?jbzga@)!$kzz@pH(3_;8h|0f@$BG9Q#U45_&B#Mzgu^6mcF%aUi+eQSa^e uJ`*;X13eX#1R=QE-Le8qR6zh(sgl05x-|N$ijpw^0000 Date: Sun, 24 Oct 2021 13:47:54 +0300 Subject: [PATCH 05/24] e --- Content.Client/Sanity/UI/SanityInterface.cs | 6 ++-- Content.Client/Sanity/UI/SanityUI.cs | 2 -- Content.Client/Sanity/UI/SanityWindow.xaml | 4 +-- .../Sanity/SharedMobSanityComponent.cs | 29 +------------------ 4 files changed, 5 insertions(+), 36 deletions(-) diff --git a/Content.Client/Sanity/UI/SanityInterface.cs b/Content.Client/Sanity/UI/SanityInterface.cs index a8c9f4cb13ba..5c62eba678a4 100644 --- a/Content.Client/Sanity/UI/SanityInterface.cs +++ b/Content.Client/Sanity/UI/SanityInterface.cs @@ -1,7 +1,7 @@ -using Content.Shared.Sanity; using Robust.Client.GameObjects; using Robust.Shared.GameObjects; using Content.Client.Sanity; +using Content.Shared.Sanity; namespace Content.Client.Sanity.UI { @@ -33,14 +33,12 @@ protected override void Open() /// /// Update the UI state based on server-sent info /// - /// protected override void UpdateState(BoundUserInterfaceState state) { base.UpdateState(state); - if (_window == null || state is not SanityBoundUserInterface cast) + if (_window == null || state is not SanityBoundUserInterfaceState cast) return; - _window.SetCurrentLabel(cast.CurrentLabel); } protected override void Dispose(bool disposing) diff --git a/Content.Client/Sanity/UI/SanityUI.cs b/Content.Client/Sanity/UI/SanityUI.cs index c335caf681ee..e3edaa50b994 100644 --- a/Content.Client/Sanity/UI/SanityUI.cs +++ b/Content.Client/Sanity/UI/SanityUI.cs @@ -14,8 +14,6 @@ public partial class SanityWindow : SS14Window public SanityWindow() { RobustXamlLoader.Load(this); - - } } diff --git a/Content.Client/Sanity/UI/SanityWindow.xaml b/Content.Client/Sanity/UI/SanityWindow.xaml index 1b09257a43ef..24e1a89c0445 100644 --- a/Content.Client/Sanity/UI/SanityWindow.xaml +++ b/Content.Client/Sanity/UI/SanityWindow.xaml @@ -1,8 +1,8 @@ + Title="Sanity"> - diff --git a/Content.Shared/Sanity/SharedMobSanityComponent.cs b/Content.Shared/Sanity/SharedMobSanityComponent.cs index e93fea610c82..ced04d4580d3 100644 --- a/Content.Shared/Sanity/SharedMobSanityComponent.cs +++ b/Content.Shared/Sanity/SharedMobSanityComponent.cs @@ -22,8 +22,6 @@ public class SanityBoundUserInterfaceState : BoundUserInterfaceMessage public int Insight { get; } public int Sanity { get; } public int Rest { get; } - - public SanityBoundUserInterfaceState(int insight, int sanity, int rest) { Insight = insight; @@ -31,31 +29,6 @@ public SanityBoundUserInterfaceState(int insight, int sanity, int rest) Rest = rest; } } - } - - - - - - - - - - - - - - - - - - - - - - - - - } + From 587321fa3af2d3bbbff31c650ad6244fc632ca3c Mon Sep 17 00:00:00 2001 From: MLGTASTICa Date: Sun, 24 Oct 2021 14:03:30 +0300 Subject: [PATCH 06/24] ee --- Content.Client/Sanity/UI/SanityInterface.cs | 3 ++- Content.Client/Sanity/UI/SanityWindow.xaml | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Content.Client/Sanity/UI/SanityInterface.cs b/Content.Client/Sanity/UI/SanityInterface.cs index 5c62eba678a4..554dc20c6569 100644 --- a/Content.Client/Sanity/UI/SanityInterface.cs +++ b/Content.Client/Sanity/UI/SanityInterface.cs @@ -36,9 +36,10 @@ protected override void Open() protected override void UpdateState(BoundUserInterfaceState state) { base.UpdateState(state); + /* if (_window == null || state is not SanityBoundUserInterfaceState cast) return; - + */ } protected override void Dispose(bool disposing) diff --git a/Content.Client/Sanity/UI/SanityWindow.xaml b/Content.Client/Sanity/UI/SanityWindow.xaml index 24e1a89c0445..9c708f81e579 100644 --- a/Content.Client/Sanity/UI/SanityWindow.xaml +++ b/Content.Client/Sanity/UI/SanityWindow.xaml @@ -2,7 +2,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Sanity"> - From 26c8a5912be9e8ec80a35b622e48d684f012b002 Mon Sep 17 00:00:00 2001 From: MLGTASTICa Date: Mon, 25 Oct 2021 15:41:14 +0300 Subject: [PATCH 07/24] Create sanity_UI.ftl --- Resources/Locale/en-US/sanity/sanity_UI.ftl | 1 + 1 file changed, 1 insertion(+) create mode 100644 Resources/Locale/en-US/sanity/sanity_UI.ftl diff --git a/Resources/Locale/en-US/sanity/sanity_UI.ftl b/Resources/Locale/en-US/sanity/sanity_UI.ftl new file mode 100644 index 000000000000..01dd0ee9835c --- /dev/null +++ b/Resources/Locale/en-US/sanity/sanity_UI.ftl @@ -0,0 +1 @@ +sanity-current-amount = Sanity \ No newline at end of file From cad43972c8d831061b71bd59e8331e993c4549ff Mon Sep 17 00:00:00 2001 From: MLGTASTICa Date: Mon, 25 Oct 2021 18:48:07 +0300 Subject: [PATCH 08/24] Part i lost count of --- Content.Client/Sanity/UI/SanityInterface.cs | 8 ++-- Content.Client/Sanity/UI/SanityUI.cs | 4 ++ Content.Server/Alert/Click/SanityMenu.cs | 27 ++++++++++++++ Content.Server/Sanity/MobSanityComponent.cs | 4 +- Content.Server/Sanity/SanitySystem.cs | 10 +++++ .../Sanity/SharedMobSanityComponent.cs | 37 +++++++++---------- Resources/Locale/en-US/sanity/sanity_UI.ftl | 2 +- Resources/Prototypes/Alerts/alerts.yml | 1 + 8 files changed, 69 insertions(+), 24 deletions(-) create mode 100644 Content.Server/Alert/Click/SanityMenu.cs diff --git a/Content.Client/Sanity/UI/SanityInterface.cs b/Content.Client/Sanity/UI/SanityInterface.cs index 554dc20c6569..9334d7ae88c6 100644 --- a/Content.Client/Sanity/UI/SanityInterface.cs +++ b/Content.Client/Sanity/UI/SanityInterface.cs @@ -2,11 +2,11 @@ using Robust.Shared.GameObjects; using Content.Client.Sanity; using Content.Shared.Sanity; +using System; namespace Content.Client.Sanity.UI { /// - /// Initializes a and updates it when new server messages are received. /// public class SanityBoundUserInterface : BoundUserInterface { @@ -36,10 +36,12 @@ protected override void Open() protected override void UpdateState(BoundUserInterfaceState state) { base.UpdateState(state); - /* + if (_window == null || state is not SanityBoundUserInterfaceState cast) return; - */ + + _window.UpdateData(cast.Sanity); + } protected override void Dispose(bool disposing) diff --git a/Content.Client/Sanity/UI/SanityUI.cs b/Content.Client/Sanity/UI/SanityUI.cs index e3edaa50b994..bc3c973a91da 100644 --- a/Content.Client/Sanity/UI/SanityUI.cs +++ b/Content.Client/Sanity/UI/SanityUI.cs @@ -16,6 +16,10 @@ public SanityWindow() RobustXamlLoader.Load(this); } + public void UpdateData(int sanity) + { + SanityLineEdit.Text = sanity.ToString(); + } } diff --git a/Content.Server/Alert/Click/SanityMenu.cs b/Content.Server/Alert/Click/SanityMenu.cs new file mode 100644 index 000000000000..2ce825d2ef24 --- /dev/null +++ b/Content.Server/Alert/Click/SanityMenu.cs @@ -0,0 +1,27 @@ +using Content.Server.Cuffs.Components; +using Content.Shared.Alert; +using JetBrains.Annotations; +using Robust.Shared.Serialization.Manager.Attributes; +using Content.Server.Sanity; +using Robust.Server.GameObjects; +using Robust.Server.GameStates; +using Robust.Shared.Scripting; +using Content.Server.UserInterface; +using Content.Shared.Sanity; +using Robust.Shared.GameObjects; + +namespace Content.Server.Alert.Click +{ + [UsedImplicitly] + [DataDefinition] + public class SanityMenu : IAlertClick + { + public void AlertClicked(ClickAlertEventArgs args) + { + if (args.Player.TryGetComponent(out MobSanityComponent? sanityComponent)) + { + EntitySystem.Get().OpenUI(sanityComponent); + } + } + } +} diff --git a/Content.Server/Sanity/MobSanityComponent.cs b/Content.Server/Sanity/MobSanityComponent.cs index 50fb9aeb1787..a99b9bd4332e 100644 --- a/Content.Server/Sanity/MobSanityComponent.cs +++ b/Content.Server/Sanity/MobSanityComponent.cs @@ -18,9 +18,11 @@ namespace Content.Server.Sanity { [RegisterComponent()] - public class MobSanityComponent : SharedMobSanityComponent + public class MobSanityComponent : Component { + public override string Name => "Sanity"; + /// /// Sanity variables /// diff --git a/Content.Server/Sanity/SanitySystem.cs b/Content.Server/Sanity/SanitySystem.cs index e76af03f02b4..081e8893f489 100644 --- a/Content.Server/Sanity/SanitySystem.cs +++ b/Content.Server/Sanity/SanitySystem.cs @@ -10,6 +10,8 @@ using Robust.Server.Player; using Content.Shared.Alert; using Content.Server.Alert; +using Content.Server.UserInterface; +using Content.Shared.Sanity; namespace Content.Server.Sanity { @@ -38,6 +40,14 @@ public void OnDelete(EntityUid uid, MobSanityComponent component, ComponentRemov SanityCompsToTick.Remove(component); } + public void OpenUI(MobSanityComponent component) + { + if(component.Owner.TryGetComponent(out ActorComponent? actorComponent)) + { + component.Owner.GetUIOrNull(SanityMenuUiKey.Key)?.Open(actorComponent.PlayerSession); + } + } + public override void Update(float frameTime) { diff --git a/Content.Shared/Sanity/SharedMobSanityComponent.cs b/Content.Shared/Sanity/SharedMobSanityComponent.cs index ced04d4580d3..b2b509c1fffa 100644 --- a/Content.Shared/Sanity/SharedMobSanityComponent.cs +++ b/Content.Shared/Sanity/SharedMobSanityComponent.cs @@ -6,29 +6,28 @@ namespace Content.Shared.Sanity { - public class SharedMobSanityComponent : Component + + [Serializable, NetSerializable] + public enum SanityMenuUiKey { - public override string Name => "Sanity"; + Key, + } - [Serializable, NetSerializable] - public enum SanityUiKey - { - Key, - } - [Serializable, NetSerializable] - public class SanityBoundUserInterfaceState : BoundUserInterfaceMessage + [Serializable, NetSerializable] + public class SanityBoundUserInterfaceState : BoundUserInterfaceState + { + + public int Insight { get; } + public int Sanity { get; } + public int Rest { get; } + public SanityBoundUserInterfaceState(int insight, int sanity, int rest) { - public int Insight { get; } - public int Sanity { get; } - public int Rest { get; } - public SanityBoundUserInterfaceState(int insight, int sanity, int rest) - { - Insight = insight; - Sanity = sanity; - Rest = rest; - } + Insight = insight; + Sanity = sanity; + Rest = rest; } } } - + + diff --git a/Resources/Locale/en-US/sanity/sanity_UI.ftl b/Resources/Locale/en-US/sanity/sanity_UI.ftl index 01dd0ee9835c..aafe101d694f 100644 --- a/Resources/Locale/en-US/sanity/sanity_UI.ftl +++ b/Resources/Locale/en-US/sanity/sanity_UI.ftl @@ -1 +1 @@ -sanity-current-amount = Sanity \ No newline at end of file +sanity-current-amount = Sanity diff --git a/Resources/Prototypes/Alerts/alerts.yml b/Resources/Prototypes/Alerts/alerts.yml index 42d41a52b846..bfb8427bb3bd 100644 --- a/Resources/Prototypes/Alerts/alerts.yml +++ b/Resources/Prototypes/Alerts/alerts.yml @@ -235,6 +235,7 @@ - type: alert alertType: MobSanity category: Sanity + onClick: !type:SanityMenu { } icon: sprite: /Textures/Interface/Alerts/sanity.rsi state: sanity From a4fcd47ba83a794484e39e4b499761f22318394d Mon Sep 17 00:00:00 2001 From: MLGTASTICa Date: Mon, 25 Oct 2021 23:26:38 +0300 Subject: [PATCH 09/24] Part 7 --- .../Sanity/ClientMobSanityComponent.cs | 16 ++++++++ Content.Client/Sanity/ClientSanitySystem.cs | 38 +++++++++++++++++++ Content.Client/Sanity/UI/SanityInterface.cs | 6 +-- .../UI/{SanityUI.cs => SanityWindow.xaml.cs} | 19 ++++++---- Content.Server/Alert/Click/SanityMenu.cs | 6 --- Content.Server/Sanity/MobSanityComponent.cs | 4 +- Content.Server/Sanity/SanitySystem.cs | 12 ++---- .../Sanity/SharedMobSanityComponent.cs | 31 +++++++++++---- Content.Shared/Sanity/SharedSanitySystem.cs | 8 ++++ 9 files changed, 104 insertions(+), 36 deletions(-) create mode 100644 Content.Client/Sanity/ClientMobSanityComponent.cs create mode 100644 Content.Client/Sanity/ClientSanitySystem.cs rename Content.Client/Sanity/UI/{SanityUI.cs => SanityWindow.xaml.cs} (64%) create mode 100644 Content.Shared/Sanity/SharedSanitySystem.cs diff --git a/Content.Client/Sanity/ClientMobSanityComponent.cs b/Content.Client/Sanity/ClientMobSanityComponent.cs new file mode 100644 index 000000000000..ba44ea113202 --- /dev/null +++ b/Content.Client/Sanity/ClientMobSanityComponent.cs @@ -0,0 +1,16 @@ +using System; +using Robust.Shared.GameObjects; +using Robust.Shared.GameStates; +using Robust.Shared.Serialization; +using Content.Shared.Sanity; +using Content.Client.Sanity.UI; + +namespace Content.Client.Sanity +{ + public class ClientMobSanityComponent : SharedMobSanityComponent + { + + public SanityWindow? SanityMenu; + + } +} diff --git a/Content.Client/Sanity/ClientSanitySystem.cs b/Content.Client/Sanity/ClientSanitySystem.cs new file mode 100644 index 000000000000..d09a777acd3e --- /dev/null +++ b/Content.Client/Sanity/ClientSanitySystem.cs @@ -0,0 +1,38 @@ +using Content.Shared.Sanity; +using Robust.Shared.GameObjects; +using Robust.Shared.GameStates; +using System; +using System.Collections.Generic; +using Content.Client.Sanity.UI; + +namespace Content.Client.Sanity +{ + public sealed class ClientSanitySystem : SharedSanitySystem + { + private SanityWindow? _window = null; + + public override void Initialize() + { + base.Initialize(); + _window = new(); + SubscribeNetworkEvent(OpenUI); + SubscribeNetworkEvent(UpdateData); + SubscribeLocalEvent(CloseUI); + } + + public void UpdateData(SanityUpdateData msg) + { + _window?.UpdateData(msg.Sanity); + } + + public void OpenUI(SanityOpenUI msg) + { + _window?.UpdateData(msg.Sanity); + _window?.Open(); + } + public override void Update(float frameTime) + { + + } + } +} diff --git a/Content.Client/Sanity/UI/SanityInterface.cs b/Content.Client/Sanity/UI/SanityInterface.cs index 9334d7ae88c6..e02ec6fb28d9 100644 --- a/Content.Client/Sanity/UI/SanityInterface.cs +++ b/Content.Client/Sanity/UI/SanityInterface.cs @@ -8,6 +8,7 @@ namespace Content.Client.Sanity.UI { /// /// + /// public class SanityBoundUserInterface : BoundUserInterface { private SanityWindow? _window; @@ -37,11 +38,6 @@ protected override void UpdateState(BoundUserInterfaceState state) { base.UpdateState(state); - if (_window == null || state is not SanityBoundUserInterfaceState cast) - return; - - _window.UpdateData(cast.Sanity); - } protected override void Dispose(bool disposing) diff --git a/Content.Client/Sanity/UI/SanityUI.cs b/Content.Client/Sanity/UI/SanityWindow.xaml.cs similarity index 64% rename from Content.Client/Sanity/UI/SanityUI.cs rename to Content.Client/Sanity/UI/SanityWindow.xaml.cs index bc3c973a91da..7dfed2e5e047 100644 --- a/Content.Client/Sanity/UI/SanityUI.cs +++ b/Content.Client/Sanity/UI/SanityWindow.xaml.cs @@ -1,9 +1,12 @@ -using System; -using Content.Shared.Sanity; using Robust.Client.UserInterface.CustomControls; using Robust.Client.AutoGenerated; -using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.XAML; +using Robust.Client.GameObjects; +using Robust.Client.GameStates; +using Robust.Shared.GameObjects; +using Robust.Shared.GameStates; +using Robust.Client.Utility; + namespace Content.Client.Sanity.UI @@ -20,9 +23,11 @@ public void UpdateData(int sanity) { SanityLineEdit.Text = sanity.ToString(); } - } - - - + public override void Close() + { + base.Close(); + Raise + } + } } diff --git a/Content.Server/Alert/Click/SanityMenu.cs b/Content.Server/Alert/Click/SanityMenu.cs index 2ce825d2ef24..e0ec90738bb5 100644 --- a/Content.Server/Alert/Click/SanityMenu.cs +++ b/Content.Server/Alert/Click/SanityMenu.cs @@ -1,13 +1,7 @@ -using Content.Server.Cuffs.Components; using Content.Shared.Alert; using JetBrains.Annotations; using Robust.Shared.Serialization.Manager.Attributes; using Content.Server.Sanity; -using Robust.Server.GameObjects; -using Robust.Server.GameStates; -using Robust.Shared.Scripting; -using Content.Server.UserInterface; -using Content.Shared.Sanity; using Robust.Shared.GameObjects; namespace Content.Server.Alert.Click diff --git a/Content.Server/Sanity/MobSanityComponent.cs b/Content.Server/Sanity/MobSanityComponent.cs index a99b9bd4332e..50fb9aeb1787 100644 --- a/Content.Server/Sanity/MobSanityComponent.cs +++ b/Content.Server/Sanity/MobSanityComponent.cs @@ -18,11 +18,9 @@ namespace Content.Server.Sanity { [RegisterComponent()] - public class MobSanityComponent : Component + public class MobSanityComponent : SharedMobSanityComponent { - public override string Name => "Sanity"; - /// /// Sanity variables /// diff --git a/Content.Server/Sanity/SanitySystem.cs b/Content.Server/Sanity/SanitySystem.cs index 081e8893f489..61b326c32518 100644 --- a/Content.Server/Sanity/SanitySystem.cs +++ b/Content.Server/Sanity/SanitySystem.cs @@ -12,15 +12,15 @@ using Content.Server.Alert; using Content.Server.UserInterface; using Content.Shared.Sanity; +using Content.Shared.Eui; namespace Content.Server.Sanity { - public class SanitySystem : EntitySystem + public sealed class SanitySystem : SharedSanitySystem { - + public HashSet SanityCompsToTick = new(); public float TimeAccumulator = 0.0f; public float TimeBetweenTicks = 15.0f; - public HashSet SanityCompsToTick = new(); public override void Initialize() @@ -42,10 +42,7 @@ public void OnDelete(EntityUid uid, MobSanityComponent component, ComponentRemov public void OpenUI(MobSanityComponent component) { - if(component.Owner.TryGetComponent(out ActorComponent? actorComponent)) - { - component.Owner.GetUIOrNull(SanityMenuUiKey.Key)?.Open(actorComponent.PlayerSession); - } + RaiseNetworkEvent(new SanityOpenUI(component.Insight, component.Sanity, component.Rest)); } @@ -59,7 +56,6 @@ public override void Update(float frameTime) } TimeAccumulator = 0.0f; - foreach (MobSanityComponent component in SanityCompsToTick) { component.Sanity += Math.Max((int)(component.SanityGainPerSecond * TimeBetweenTicks), 0); diff --git a/Content.Shared/Sanity/SharedMobSanityComponent.cs b/Content.Shared/Sanity/SharedMobSanityComponent.cs index b2b509c1fffa..aff4e0250441 100644 --- a/Content.Shared/Sanity/SharedMobSanityComponent.cs +++ b/Content.Shared/Sanity/SharedMobSanityComponent.cs @@ -3,31 +3,48 @@ using Robust.Shared.GameStates; using Robust.Shared.Serialization; - namespace Content.Shared.Sanity { - - [Serializable, NetSerializable] - public enum SanityMenuUiKey + public class SharedMobSanityComponent : Component { - Key, + public override string Name => "Sanity"; } + [Serializable, NetSerializable] - public class SanityBoundUserInterfaceState : BoundUserInterfaceState + public class SanityUpdateData : EntityEventArgs { public int Insight { get; } public int Sanity { get; } public int Rest { get; } - public SanityBoundUserInterfaceState(int insight, int sanity, int rest) + public SanityUpdateData(int insight, int sanity, int rest) + { + Insight = insight; + Sanity = sanity; + Rest = rest; + } + } + + [Serializable, NetSerializable] + public class SanityOpenUI : EntityEventArgs + { + public int Insight { get; } + public int Sanity { get; } + public int Rest { get; } + public SanityOpenUI(int insight, int sanity, int rest) { Insight = insight; Sanity = sanity; Rest = rest; } } + + [Serializable, NetSerializable] + public class SanityCloseUI : EntityEventArgs + { + } } diff --git a/Content.Shared/Sanity/SharedSanitySystem.cs b/Content.Shared/Sanity/SharedSanitySystem.cs new file mode 100644 index 000000000000..16cf138fde96 --- /dev/null +++ b/Content.Shared/Sanity/SharedSanitySystem.cs @@ -0,0 +1,8 @@ +using Robust.Shared.GameObjects; + +namespace Content.Shared.Sanity +{ + public abstract class SharedSanitySystem : EntitySystem + { + } +} From aaccf97c84700e97a59b0ef8a975e67ee4f8f72c Mon Sep 17 00:00:00 2001 From: MLGTASTICa Date: Mon, 25 Oct 2021 23:34:03 +0300 Subject: [PATCH 10/24] Update IgnoredComponents.cs --- Content.Client/Entry/IgnoredComponents.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Content.Client/Entry/IgnoredComponents.cs b/Content.Client/Entry/IgnoredComponents.cs index f01c8d773454..4d710806f9c7 100644 --- a/Content.Client/Entry/IgnoredComponents.cs +++ b/Content.Client/Entry/IgnoredComponents.cs @@ -284,8 +284,7 @@ public static class IgnoredComponents "ToggleDoorOnTrigger", "DeviceNetworkConnection", "WiredNetworkConnection", - "WirelessNetworkConnection", - "Sanity" + "WirelessNetworkConnection" }; } } From 0cc1045f3e1ff922a65312d688adc83d7da24fb7 Mon Sep 17 00:00:00 2001 From: MLGTASTICa Date: Tue, 26 Oct 2021 14:27:13 +0300 Subject: [PATCH 11/24] part 9 --- Content.Client/Sanity/ClientSanitySystem.cs | 5 ++++- Content.Client/Sanity/UI/SanityWindow.xaml.cs | 2 +- Content.Server/Sanity/MobSanityComponent.cs | 3 --- Content.Shared/Sanity/SharedMobSanityComponent.cs | 1 + 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Content.Client/Sanity/ClientSanitySystem.cs b/Content.Client/Sanity/ClientSanitySystem.cs index d09a777acd3e..54d33e0be9dc 100644 --- a/Content.Client/Sanity/ClientSanitySystem.cs +++ b/Content.Client/Sanity/ClientSanitySystem.cs @@ -17,7 +17,6 @@ public override void Initialize() _window = new(); SubscribeNetworkEvent(OpenUI); SubscribeNetworkEvent(UpdateData); - SubscribeLocalEvent(CloseUI); } public void UpdateData(SanityUpdateData msg) @@ -25,6 +24,10 @@ public void UpdateData(SanityUpdateData msg) _window?.UpdateData(msg.Sanity); } + public void CloseUI() + { + RaiseNetworkEvent(new SanityCloseUI()); + } public void OpenUI(SanityOpenUI msg) { _window?.UpdateData(msg.Sanity); diff --git a/Content.Client/Sanity/UI/SanityWindow.xaml.cs b/Content.Client/Sanity/UI/SanityWindow.xaml.cs index 7dfed2e5e047..a43604b7381c 100644 --- a/Content.Client/Sanity/UI/SanityWindow.xaml.cs +++ b/Content.Client/Sanity/UI/SanityWindow.xaml.cs @@ -27,7 +27,7 @@ public void UpdateData(int sanity) public override void Close() { base.Close(); - Raise + EntitySystem.Get().CloseUI(); } } } diff --git a/Content.Server/Sanity/MobSanityComponent.cs b/Content.Server/Sanity/MobSanityComponent.cs index 50fb9aeb1787..9177d7ab2803 100644 --- a/Content.Server/Sanity/MobSanityComponent.cs +++ b/Content.Server/Sanity/MobSanityComponent.cs @@ -17,7 +17,6 @@ namespace Content.Server.Sanity { - [RegisterComponent()] public class MobSanityComponent : SharedMobSanityComponent { @@ -140,7 +139,5 @@ public int Rest [ViewVariables(VVAccess.ReadWrite)] public float RestGainPerSecond = 0.75f; - - } } diff --git a/Content.Shared/Sanity/SharedMobSanityComponent.cs b/Content.Shared/Sanity/SharedMobSanityComponent.cs index aff4e0250441..8044d9882da0 100644 --- a/Content.Shared/Sanity/SharedMobSanityComponent.cs +++ b/Content.Shared/Sanity/SharedMobSanityComponent.cs @@ -5,6 +5,7 @@ namespace Content.Shared.Sanity { + [RegisterComponent()] public class SharedMobSanityComponent : Component { public override string Name => "Sanity"; From 61f7d18aba26ce0762104c2572b292f4c2e592ef Mon Sep 17 00:00:00 2001 From: MLGTASTICa Date: Tue, 26 Oct 2021 20:52:25 +0300 Subject: [PATCH 12/24] Part 11 --- .../Sanity/ClientMobSanityComponent.cs | 13 +++++++++ Content.Client/Sanity/ClientSanitySystem.cs | 12 ++------- Content.Server/Alert/Click/SanityMenu.cs | 4 ++- Content.Server/Sanity/MobSanityComponent.cs | 7 +++++ Content.Server/Sanity/SanitySystem.cs | 8 ++++-- .../Sanity/SharedMobSanityComponent.cs | 27 +++++++++---------- 6 files changed, 44 insertions(+), 27 deletions(-) diff --git a/Content.Client/Sanity/ClientMobSanityComponent.cs b/Content.Client/Sanity/ClientMobSanityComponent.cs index ba44ea113202..61552773f563 100644 --- a/Content.Client/Sanity/ClientMobSanityComponent.cs +++ b/Content.Client/Sanity/ClientMobSanityComponent.cs @@ -12,5 +12,18 @@ public class ClientMobSanityComponent : SharedMobSanityComponent public SanityWindow? SanityMenu; + public int Sanity = 0; + public int Insight = 0; + public int Rest = 0; + + public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) + { + if (curState is not SanityComponentState actualState) + return; + + Sanity = actualState.Sanity; + Insight = actualState.Insight; + Rest = actualState.Rest; + } } } diff --git a/Content.Client/Sanity/ClientSanitySystem.cs b/Content.Client/Sanity/ClientSanitySystem.cs index 54d33e0be9dc..71e607f03225 100644 --- a/Content.Client/Sanity/ClientSanitySystem.cs +++ b/Content.Client/Sanity/ClientSanitySystem.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using Content.Client.Sanity.UI; +using Robust.Shared.Players; namespace Content.Client.Sanity { @@ -16,12 +17,6 @@ public override void Initialize() base.Initialize(); _window = new(); SubscribeNetworkEvent(OpenUI); - SubscribeNetworkEvent(UpdateData); - } - - public void UpdateData(SanityUpdateData msg) - { - _window?.UpdateData(msg.Sanity); } public void CloseUI() @@ -33,9 +28,6 @@ public void OpenUI(SanityOpenUI msg) _window?.UpdateData(msg.Sanity); _window?.Open(); } - public override void Update(float frameTime) - { - - } + } } diff --git a/Content.Server/Alert/Click/SanityMenu.cs b/Content.Server/Alert/Click/SanityMenu.cs index e0ec90738bb5..4eccb5b5a8b7 100644 --- a/Content.Server/Alert/Click/SanityMenu.cs +++ b/Content.Server/Alert/Click/SanityMenu.cs @@ -3,6 +3,7 @@ using Robust.Shared.Serialization.Manager.Attributes; using Content.Server.Sanity; using Robust.Shared.GameObjects; +using Robust.Shared.Network; namespace Content.Server.Alert.Click { @@ -12,9 +13,10 @@ public class SanityMenu : IAlertClick { public void AlertClicked(ClickAlertEventArgs args) { + INetChannel channel = args.Player. if (args.Player.TryGetComponent(out MobSanityComponent? sanityComponent)) { - EntitySystem.Get().OpenUI(sanityComponent); + EntitySystem.Get().OpenUI(sanityComponent, channel); } } } diff --git a/Content.Server/Sanity/MobSanityComponent.cs b/Content.Server/Sanity/MobSanityComponent.cs index 9177d7ab2803..71010bfc9906 100644 --- a/Content.Server/Sanity/MobSanityComponent.cs +++ b/Content.Server/Sanity/MobSanityComponent.cs @@ -14,9 +14,11 @@ using Robust.Shared.Map; using Robust.Shared.ViewVariables; using Content.Shared.Sanity; +using Robust.Shared.Players; namespace Content.Server.Sanity { + [ComponentReference(typeof(SharedMobSanityComponent))] public class MobSanityComponent : SharedMobSanityComponent { @@ -139,5 +141,10 @@ public int Rest [ViewVariables(VVAccess.ReadWrite)] public float RestGainPerSecond = 0.75f; + public override ComponentState GetComponentState(ICommonSession player) + { + return new SanityComponentState(Insight,Sanity,Rest); + } + } } diff --git a/Content.Server/Sanity/SanitySystem.cs b/Content.Server/Sanity/SanitySystem.cs index 61b326c32518..09e54c5c509b 100644 --- a/Content.Server/Sanity/SanitySystem.cs +++ b/Content.Server/Sanity/SanitySystem.cs @@ -13,6 +13,9 @@ using Content.Server.UserInterface; using Content.Shared.Sanity; using Content.Shared.Eui; +using Robust.Shared.Players; +using System.Net; +using Robust.Shared.Network; namespace Content.Server.Sanity { @@ -40,9 +43,9 @@ public void OnDelete(EntityUid uid, MobSanityComponent component, ComponentRemov SanityCompsToTick.Remove(component); } - public void OpenUI(MobSanityComponent component) + public void OpenUI(MobSanityComponent component, INetChannel channel) { - RaiseNetworkEvent(new SanityOpenUI(component.Insight, component.Sanity, component.Rest)); + RaiseNetworkEvent(new SanityOpenUI(component.Insight, component.Sanity, component.Rest), channel); } @@ -64,6 +67,7 @@ public override void Update(float frameTime) continue; } alerts.ShowAlert(AlertType.MobSanity, (short)(component.Sanity/component.SanitySteps)); + component.Dirty(); } } diff --git a/Content.Shared/Sanity/SharedMobSanityComponent.cs b/Content.Shared/Sanity/SharedMobSanityComponent.cs index 8044d9882da0..82ff12a48e2b 100644 --- a/Content.Shared/Sanity/SharedMobSanityComponent.cs +++ b/Content.Shared/Sanity/SharedMobSanityComponent.cs @@ -2,6 +2,7 @@ using Robust.Shared.GameObjects; using Robust.Shared.GameStates; using Robust.Shared.Serialization; +using Robust.Shared.Players; namespace Content.Shared.Sanity { @@ -9,22 +10,20 @@ namespace Content.Shared.Sanity public class SharedMobSanityComponent : Component { public override string Name => "Sanity"; - } - - - - [Serializable, NetSerializable] - public class SanityUpdateData : EntityEventArgs - { - public int Insight { get; } - public int Sanity { get; } - public int Rest { get; } - public SanityUpdateData(int insight, int sanity, int rest) + [Serializable, NetSerializable] + protected class SanityComponentState : ComponentState { - Insight = insight; - Sanity = sanity; - Rest = rest; + public int Insight { get; } + public int Sanity { get; } + public int Rest { get; } + + public SanityComponentState(int insight, int sanity, int rest) + { + Insight = insight; + Sanity = sanity; + Rest = rest; + } } } From 7193090f7f5996ebbfa981b32905497d158e7185 Mon Sep 17 00:00:00 2001 From: MLGTASTICa Date: Tue, 26 Oct 2021 22:33:00 +0300 Subject: [PATCH 13/24] part 12 : it just doens't work --- .../Sanity/ClientMobSanityComponent.cs | 9 ---- Content.Client/Sanity/ClientSanitySystem.cs | 19 ++++++++- Content.Server/Alert/Click/SanityMenu.cs | 5 ++- Content.Server/Sanity/MobSanityComponent.cs | 8 +--- Content.Server/Sanity/SanitySystem.cs | 31 +++++++++++++- .../Sanity/SharedMobSanityComponent.cs | 41 +++++++++++-------- 6 files changed, 77 insertions(+), 36 deletions(-) diff --git a/Content.Client/Sanity/ClientMobSanityComponent.cs b/Content.Client/Sanity/ClientMobSanityComponent.cs index 61552773f563..a966d0ff9019 100644 --- a/Content.Client/Sanity/ClientMobSanityComponent.cs +++ b/Content.Client/Sanity/ClientMobSanityComponent.cs @@ -16,14 +16,5 @@ public class ClientMobSanityComponent : SharedMobSanityComponent public int Insight = 0; public int Rest = 0; - public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) - { - if (curState is not SanityComponentState actualState) - return; - - Sanity = actualState.Sanity; - Insight = actualState.Insight; - Rest = actualState.Rest; - } } } diff --git a/Content.Client/Sanity/ClientSanitySystem.cs b/Content.Client/Sanity/ClientSanitySystem.cs index 71e607f03225..3aba6c9d2551 100644 --- a/Content.Client/Sanity/ClientSanitySystem.cs +++ b/Content.Client/Sanity/ClientSanitySystem.cs @@ -4,27 +4,44 @@ using System; using System.Collections.Generic; using Content.Client.Sanity.UI; +using Robust.Shared.Network; using Robust.Shared.Players; +using Robust.Client.Player; namespace Content.Client.Sanity { public sealed class ClientSanitySystem : SharedSanitySystem { private SanityWindow? _window = null; + /// + /// We don't know our damn channel until we get told by the server + /// + private INetChannel? _channel = null; public override void Initialize() { base.Initialize(); _window = new(); SubscribeNetworkEvent(OpenUI); + SubscribeNetworkEvent(UpdateData); + } + + public void UpdateData(SanityUpdateUI msg) + { + _window?.UpdateData(msg.Sanity); } public void CloseUI() { - RaiseNetworkEvent(new SanityCloseUI()); + if (_channel is not null) + { + RaiseNetworkEvent(new SanityCloseUI(_channel)); + _channel = null; + } } public void OpenUI(SanityOpenUI msg) { + _channel = msg.Channel; _window?.UpdateData(msg.Sanity); _window?.Open(); } diff --git a/Content.Server/Alert/Click/SanityMenu.cs b/Content.Server/Alert/Click/SanityMenu.cs index 4eccb5b5a8b7..9a264bbfa599 100644 --- a/Content.Server/Alert/Click/SanityMenu.cs +++ b/Content.Server/Alert/Click/SanityMenu.cs @@ -4,6 +4,7 @@ using Content.Server.Sanity; using Robust.Shared.GameObjects; using Robust.Shared.Network; +using Robust.Server.Player; namespace Content.Server.Alert.Click { @@ -13,8 +14,8 @@ public class SanityMenu : IAlertClick { public void AlertClicked(ClickAlertEventArgs args) { - INetChannel channel = args.Player. - if (args.Player.TryGetComponent(out MobSanityComponent? sanityComponent)) + INetChannel? channel = args.Player.PlayerSession()?.ConnectedClient; + if (args.Player.TryGetComponent(out MobSanityComponent? sanityComponent) && channel is not null) { EntitySystem.Get().OpenUI(sanityComponent, channel); } diff --git a/Content.Server/Sanity/MobSanityComponent.cs b/Content.Server/Sanity/MobSanityComponent.cs index 71010bfc9906..b27fa3057bb5 100644 --- a/Content.Server/Sanity/MobSanityComponent.cs +++ b/Content.Server/Sanity/MobSanityComponent.cs @@ -18,7 +18,7 @@ namespace Content.Server.Sanity { - [ComponentReference(typeof(SharedMobSanityComponent))] + [RegisterComponent()] public class MobSanityComponent : SharedMobSanityComponent { @@ -141,10 +141,6 @@ public int Rest [ViewVariables(VVAccess.ReadWrite)] public float RestGainPerSecond = 0.75f; - public override ComponentState GetComponentState(ICommonSession player) - { - return new SanityComponentState(Insight,Sanity,Rest); - } - + } } diff --git a/Content.Server/Sanity/SanitySystem.cs b/Content.Server/Sanity/SanitySystem.cs index 09e54c5c509b..ecfae7c92373 100644 --- a/Content.Server/Sanity/SanitySystem.cs +++ b/Content.Server/Sanity/SanitySystem.cs @@ -22,6 +22,7 @@ namespace Content.Server.Sanity public sealed class SanitySystem : SharedSanitySystem { public HashSet SanityCompsToTick = new(); + public HashSet SanityCompsToUpdate = new(); public float TimeAccumulator = 0.0f; public float TimeBetweenTicks = 15.0f; @@ -31,6 +32,7 @@ public override void Initialize() base.Initialize(); SubscribeLocalEvent(OnInit); SubscribeLocalEvent(OnDelete); + SubscribeNetworkEvent(CloseUI); } public void OnInit(EntityUid uid, MobSanityComponent component, ComponentInit args) @@ -43,9 +45,23 @@ public void OnDelete(EntityUid uid, MobSanityComponent component, ComponentRemov SanityCompsToTick.Remove(component); } + public void CloseUI(SanityCloseUI msg) + { + foreach(MobSanityComponent component in SanityCompsToUpdate) + { + if(component.UpdateChannel == msg.Channel) + { + component.UpdateChannel = null; + SanityCompsToUpdate.Remove(component); + break; + } + } + } public void OpenUI(MobSanityComponent component, INetChannel channel) { - RaiseNetworkEvent(new SanityOpenUI(component.Insight, component.Sanity, component.Rest), channel); + component.UpdateChannel = channel; + SanityCompsToUpdate.Add(component); + RaiseNetworkEvent(new SanityOpenUI(component.Insight, component.Sanity, component.Rest, channel), channel); } @@ -67,7 +83,18 @@ public override void Update(float frameTime) continue; } alerts.ShowAlert(AlertType.MobSanity, (short)(component.Sanity/component.SanitySteps)); - component.Dirty(); + } + + foreach(MobSanityComponent component in SanityCompsToUpdate) + { + if (component.UpdateChannel is not null) + { + RaiseNetworkEvent(new SanityUpdateUI(component.Insight, component.Sanity, component.Rest), component.UpdateChannel); + } + else + { + SanityCompsToUpdate.Remove(component); + } } } diff --git a/Content.Shared/Sanity/SharedMobSanityComponent.cs b/Content.Shared/Sanity/SharedMobSanityComponent.cs index 82ff12a48e2b..19dd54888490 100644 --- a/Content.Shared/Sanity/SharedMobSanityComponent.cs +++ b/Content.Shared/Sanity/SharedMobSanityComponent.cs @@ -3,28 +3,15 @@ using Robust.Shared.GameStates; using Robust.Shared.Serialization; using Robust.Shared.Players; +using Robust.Shared.Network; namespace Content.Shared.Sanity { - [RegisterComponent()] public class SharedMobSanityComponent : Component { public override string Name => "Sanity"; - [Serializable, NetSerializable] - protected class SanityComponentState : ComponentState - { - public int Insight { get; } - public int Sanity { get; } - public int Rest { get; } - - public SanityComponentState(int insight, int sanity, int rest) - { - Insight = insight; - Sanity = sanity; - Rest = rest; - } - } + public INetChannel? UpdateChannel = null; } [Serializable, NetSerializable] @@ -33,7 +20,23 @@ public class SanityOpenUI : EntityEventArgs public int Insight { get; } public int Sanity { get; } public int Rest { get; } - public SanityOpenUI(int insight, int sanity, int rest) + + public INetChannel Channel { get; } + public SanityOpenUI(int insight, int sanity, int rest, INetChannel channel) + { + Insight = insight; + Sanity = sanity; + Rest = rest; + Channel = channel; + } + } + + public class SanityUpdateUI : EntityEventArgs + { + public int Insight { get; } + public int Sanity { get; } + public int Rest { get; } + public SanityUpdateUI(int insight, int sanity, int rest) { Insight = insight; Sanity = sanity; @@ -44,6 +47,12 @@ public SanityOpenUI(int insight, int sanity, int rest) [Serializable, NetSerializable] public class SanityCloseUI : EntityEventArgs { + public INetChannel Channel { get; } + + public SanityCloseUI(INetChannel channel) + { + Channel = channel; + } } } From 88afa1445b027e79827a46f784f6e0573bbebbe8 Mon Sep 17 00:00:00 2001 From: MLGTASTICa Date: Wed, 27 Oct 2021 07:17:03 +0300 Subject: [PATCH 14/24] Part 13 , Working networking --- Content.Client/Entry/IgnoredComponents.cs | 1 + Content.Client/Sanity/ClientSanitySystem.cs | 12 +++---- Content.Client/Sanity/UI/SanityInterface.cs | 9 ----- Content.Server/Alert/Click/SanityMenu.cs | 7 ++-- Content.Server/Sanity/MobSanityComponent.cs | 4 ++- Content.Server/Sanity/SanitySystem.cs | 36 +++++++------------ .../Sanity/SharedMobSanityComponent.cs | 18 +++++----- 7 files changed, 34 insertions(+), 53 deletions(-) diff --git a/Content.Client/Entry/IgnoredComponents.cs b/Content.Client/Entry/IgnoredComponents.cs index 4d710806f9c7..0afe3fd26a3d 100644 --- a/Content.Client/Entry/IgnoredComponents.cs +++ b/Content.Client/Entry/IgnoredComponents.cs @@ -164,6 +164,7 @@ public static class IgnoredComponents "PressureSiphon", "PipeHeater", "AtmosDevice", + "Sanity", "SignalReceiver", "SignalSwitch", "SignalTransmitter", diff --git a/Content.Client/Sanity/ClientSanitySystem.cs b/Content.Client/Sanity/ClientSanitySystem.cs index 3aba6c9d2551..853272e59e8d 100644 --- a/Content.Client/Sanity/ClientSanitySystem.cs +++ b/Content.Client/Sanity/ClientSanitySystem.cs @@ -13,11 +13,8 @@ namespace Content.Client.Sanity public sealed class ClientSanitySystem : SharedSanitySystem { private SanityWindow? _window = null; - /// - /// We don't know our damn channel until we get told by the server - /// - private INetChannel? _channel = null; + private EntityUid? _playerUID = null; public override void Initialize() { base.Initialize(); @@ -33,15 +30,14 @@ public void UpdateData(SanityUpdateUI msg) public void CloseUI() { - if (_channel is not null) + if (_playerUID is not null) { - RaiseNetworkEvent(new SanityCloseUI(_channel)); - _channel = null; + RaiseNetworkEvent(new SanityCloseUI((EntityUid)_playerUID)); } } public void OpenUI(SanityOpenUI msg) { - _channel = msg.Channel; + _playerUID = msg.PlayerUID; _window?.UpdateData(msg.Sanity); _window?.Open(); } diff --git a/Content.Client/Sanity/UI/SanityInterface.cs b/Content.Client/Sanity/UI/SanityInterface.cs index e02ec6fb28d9..9c4b8dfdb959 100644 --- a/Content.Client/Sanity/UI/SanityInterface.cs +++ b/Content.Client/Sanity/UI/SanityInterface.cs @@ -31,15 +31,6 @@ protected override void Open() } - /// - /// Update the UI state based on server-sent info - /// - protected override void UpdateState(BoundUserInterfaceState state) - { - base.UpdateState(state); - - } - protected override void Dispose(bool disposing) { base.Dispose(disposing); diff --git a/Content.Server/Alert/Click/SanityMenu.cs b/Content.Server/Alert/Click/SanityMenu.cs index 9a264bbfa599..a964f08a35a4 100644 --- a/Content.Server/Alert/Click/SanityMenu.cs +++ b/Content.Server/Alert/Click/SanityMenu.cs @@ -5,6 +5,7 @@ using Robust.Shared.GameObjects; using Robust.Shared.Network; using Robust.Server.Player; +using Robust.Server.GameObjects; namespace Content.Server.Alert.Click { @@ -14,10 +15,10 @@ public class SanityMenu : IAlertClick { public void AlertClicked(ClickAlertEventArgs args) { - INetChannel? channel = args.Player.PlayerSession()?.ConnectedClient; - if (args.Player.TryGetComponent(out MobSanityComponent? sanityComponent) && channel is not null) + + if (args.Player.TryGetComponent(out MobSanityComponent? sanityComponent) && args.Player.TryGetComponent(out ActorComponent? actorComponent)) { - EntitySystem.Get().OpenUI(sanityComponent, channel); + EntitySystem.Get().OpenUI(sanityComponent, actorComponent.PlayerSession.ConnectedClient); } } } diff --git a/Content.Server/Sanity/MobSanityComponent.cs b/Content.Server/Sanity/MobSanityComponent.cs index b27fa3057bb5..136352019f76 100644 --- a/Content.Server/Sanity/MobSanityComponent.cs +++ b/Content.Server/Sanity/MobSanityComponent.cs @@ -18,13 +18,15 @@ namespace Content.Server.Sanity { - [RegisterComponent()] + [RegisterComponent] public class MobSanityComponent : SharedMobSanityComponent { /// /// Sanity variables /// + [ViewVariables(VVAccess.ReadWrite)] + public bool Updating = false; public int Sanity { diff --git a/Content.Server/Sanity/SanitySystem.cs b/Content.Server/Sanity/SanitySystem.cs index ecfae7c92373..a6fadb71dde5 100644 --- a/Content.Server/Sanity/SanitySystem.cs +++ b/Content.Server/Sanity/SanitySystem.cs @@ -22,7 +22,6 @@ namespace Content.Server.Sanity public sealed class SanitySystem : SharedSanitySystem { public HashSet SanityCompsToTick = new(); - public HashSet SanityCompsToUpdate = new(); public float TimeAccumulator = 0.0f; public float TimeBetweenTicks = 15.0f; @@ -39,7 +38,6 @@ public void OnInit(EntityUid uid, MobSanityComponent component, ComponentInit ar { SanityCompsToTick.Add(component); } - public void OnDelete(EntityUid uid, MobSanityComponent component, ComponentRemove args) { SanityCompsToTick.Remove(component); @@ -47,21 +45,18 @@ public void OnDelete(EntityUid uid, MobSanityComponent component, ComponentRemov public void CloseUI(SanityCloseUI msg) { - foreach(MobSanityComponent component in SanityCompsToUpdate) + MobSanityComponent? component = null; + if(!Resolve(msg.PlayerUID, ref component)) { - if(component.UpdateChannel == msg.Channel) - { - component.UpdateChannel = null; - SanityCompsToUpdate.Remove(component); - break; - } + return; } + + component.Updating = false; } public void OpenUI(MobSanityComponent component, INetChannel channel) { - component.UpdateChannel = channel; - SanityCompsToUpdate.Add(component); - RaiseNetworkEvent(new SanityOpenUI(component.Insight, component.Sanity, component.Rest, channel), channel); + component.Updating = true; + RaiseNetworkEvent(new SanityOpenUI(component.Insight, component.Sanity, component.Rest, component.Owner.Uid), channel); } @@ -83,20 +78,15 @@ public override void Update(float frameTime) continue; } alerts.ShowAlert(AlertType.MobSanity, (short)(component.Sanity/component.SanitySteps)); - } - - foreach(MobSanityComponent component in SanityCompsToUpdate) - { - if (component.UpdateChannel is not null) - { - RaiseNetworkEvent(new SanityUpdateUI(component.Insight, component.Sanity, component.Rest), component.UpdateChannel); - } - else + if(component.Updating) { - SanityCompsToUpdate.Remove(component); + INetChannel? channel = component.Owner.PlayerSession()?.ConnectedClient; + if (channel is not null) + { + RaiseNetworkEvent(new SanityUpdateUI(component.Insight, component.Sanity, component.Rest), channel); + } } } - } } } diff --git a/Content.Shared/Sanity/SharedMobSanityComponent.cs b/Content.Shared/Sanity/SharedMobSanityComponent.cs index 19dd54888490..aa4f98e22dfc 100644 --- a/Content.Shared/Sanity/SharedMobSanityComponent.cs +++ b/Content.Shared/Sanity/SharedMobSanityComponent.cs @@ -10,10 +10,10 @@ namespace Content.Shared.Sanity public class SharedMobSanityComponent : Component { public override string Name => "Sanity"; - - public INetChannel? UpdateChannel = null; } + + [Serializable, NetSerializable] public class SanityOpenUI : EntityEventArgs { @@ -21,16 +21,16 @@ public class SanityOpenUI : EntityEventArgs public int Sanity { get; } public int Rest { get; } - public INetChannel Channel { get; } - public SanityOpenUI(int insight, int sanity, int rest, INetChannel channel) + public EntityUid PlayerUID { get; } + public SanityOpenUI(int insight, int sanity, int rest, EntityUid playerUID) { Insight = insight; Sanity = sanity; Rest = rest; - Channel = channel; + PlayerUID = playerUID; } } - + [Serializable, NetSerializable] public class SanityUpdateUI : EntityEventArgs { public int Insight { get; } @@ -47,11 +47,11 @@ public SanityUpdateUI(int insight, int sanity, int rest) [Serializable, NetSerializable] public class SanityCloseUI : EntityEventArgs { - public INetChannel Channel { get; } + public EntityUid PlayerUID { get; } - public SanityCloseUI(INetChannel channel) + public SanityCloseUI(EntityUid playerUID) { - Channel = channel; + PlayerUID = playerUID; } } } From 6159f7efe715c5729f224a05600e3281b7e15bef Mon Sep 17 00:00:00 2001 From: MLGTASTICa Date: Wed, 27 Oct 2021 17:47:31 +0300 Subject: [PATCH 15/24] Part 15 : The rework. --- Content.Client/Sanity/ClientSanitySystem.cs | 26 +++++----------- Content.Client/Sanity/UI/SanityInterface.cs | 17 +++++++++++ Content.Client/Sanity/UI/SanityWindow.xaml.cs | 6 ---- Content.Server/Alert/Click/SanityMenu.cs | 2 +- Content.Server/Sanity/MobSanityComponent.cs | 30 +++++++++++-------- Content.Server/Sanity/SanitySystem.cs | 24 +++++++++------ .../Sanity/SharedMobSanityComponent.cs | 10 +++++-- .../Entities/Mobs/Species/human.yml | 2 ++ 8 files changed, 66 insertions(+), 51 deletions(-) diff --git a/Content.Client/Sanity/ClientSanitySystem.cs b/Content.Client/Sanity/ClientSanitySystem.cs index 853272e59e8d..0140a717e039 100644 --- a/Content.Client/Sanity/ClientSanitySystem.cs +++ b/Content.Client/Sanity/ClientSanitySystem.cs @@ -7,40 +7,28 @@ using Robust.Shared.Network; using Robust.Shared.Players; using Robust.Client.Player; +using Robust.Shared.IoC; namespace Content.Client.Sanity { public sealed class ClientSanitySystem : SharedSanitySystem { - private SanityWindow? _window = null; - - private EntityUid? _playerUID = null; + [Dependency] IPlayerManager _playerManager = default!; + public override void Initialize() { base.Initialize(); - _window = new(); - SubscribeNetworkEvent(OpenUI); - SubscribeNetworkEvent(UpdateData); } - public void UpdateData(SanityUpdateUI msg) - { - _window?.UpdateData(msg.Sanity); - } - public void CloseUI() + public void NotifyUI() { - if (_playerUID is not null) + EntityUid? playerUID = _playerManager?.LocalPlayer?.ControlledEntity?.Uid; + if (playerUID is not null) { - RaiseNetworkEvent(new SanityCloseUI((EntityUid)_playerUID)); + RaiseNetworkEvent(new SanityCloseUI((EntityUid)playerUID)); } } - public void OpenUI(SanityOpenUI msg) - { - _playerUID = msg.PlayerUID; - _window?.UpdateData(msg.Sanity); - _window?.Open(); - } } } diff --git a/Content.Client/Sanity/UI/SanityInterface.cs b/Content.Client/Sanity/UI/SanityInterface.cs index 9c4b8dfdb959..86bfc18d69dc 100644 --- a/Content.Client/Sanity/UI/SanityInterface.cs +++ b/Content.Client/Sanity/UI/SanityInterface.cs @@ -28,9 +28,26 @@ protected override void Open() _window.OpenCentered(); _window.OnClose += Close; + _window.OnClose += NotifySystem; } + protected override void UpdateState(BoundUserInterfaceState state) + { + base.UpdateState(state); + if (_window == null || state is not SanityBoundUserInterfaceState cast) + return; + + _window.UpdateData(cast.Sanity); + } + + protected void NotifySystem() + { + EntitySystem.Get().NotifyUI(); + } + + + protected override void Dispose(bool disposing) { base.Dispose(disposing); diff --git a/Content.Client/Sanity/UI/SanityWindow.xaml.cs b/Content.Client/Sanity/UI/SanityWindow.xaml.cs index a43604b7381c..8f322e448c19 100644 --- a/Content.Client/Sanity/UI/SanityWindow.xaml.cs +++ b/Content.Client/Sanity/UI/SanityWindow.xaml.cs @@ -23,11 +23,5 @@ public void UpdateData(int sanity) { SanityLineEdit.Text = sanity.ToString(); } - - public override void Close() - { - base.Close(); - EntitySystem.Get().CloseUI(); - } } } diff --git a/Content.Server/Alert/Click/SanityMenu.cs b/Content.Server/Alert/Click/SanityMenu.cs index a964f08a35a4..7a032925c0b7 100644 --- a/Content.Server/Alert/Click/SanityMenu.cs +++ b/Content.Server/Alert/Click/SanityMenu.cs @@ -18,7 +18,7 @@ public void AlertClicked(ClickAlertEventArgs args) if (args.Player.TryGetComponent(out MobSanityComponent? sanityComponent) && args.Player.TryGetComponent(out ActorComponent? actorComponent)) { - EntitySystem.Get().OpenUI(sanityComponent, actorComponent.PlayerSession.ConnectedClient); + EntitySystem.Get().OpenUI(sanityComponent, actorComponent.PlayerSession); } } } diff --git a/Content.Server/Sanity/MobSanityComponent.cs b/Content.Server/Sanity/MobSanityComponent.cs index 136352019f76..965522faf0e9 100644 --- a/Content.Server/Sanity/MobSanityComponent.cs +++ b/Content.Server/Sanity/MobSanityComponent.cs @@ -33,18 +33,20 @@ public int Sanity get => _sanity; set { - if (_sanity + value > MaxSanity) + if(_sanity + value > MaxSanity) { _sanity = MaxSanity; + return; } - else - _sanity += value; - + if(_sanity + value < 1) + { + _sanity = 0; + return; + } + _sanity = value; } } - /// - /// Internal variable for handling sanity set and get. - /// + private int _sanity = 0; /// /// How much sanity points are given per second, this rounds itself , but losses are aceptable. @@ -91,16 +93,18 @@ public int Insight get => _insight; set { - if (_insight + value > RequiredInsight) + if(_insight + value > RequiredInsight) { InsightPoints += (_insight + value) / RequiredInsight; _insight = (_insight + value) % RequiredInsight; + return; } - else - _insight += value; + _insight = value; } + } + private int _insight = 0; [ViewVariables(VVAccess.ReadWrite)] @@ -121,13 +125,13 @@ public int Rest get => _rest; set { - if (_rest + value > RestRequired) + if(_rest + value > RestRequired) { RestPoints += (_rest + value) / RestRequired; _rest = (_rest + value) % RestRequired; + return; } - else - _rest += value; + _rest = value; } } diff --git a/Content.Server/Sanity/SanitySystem.cs b/Content.Server/Sanity/SanitySystem.cs index a6fadb71dde5..9b7f3c225aa4 100644 --- a/Content.Server/Sanity/SanitySystem.cs +++ b/Content.Server/Sanity/SanitySystem.cs @@ -16,11 +16,18 @@ using Robust.Shared.Players; using System.Net; using Robust.Shared.Network; +using JetBrains.Annotations; +using Content.Shared.Popups; +using Content.Shared.ActionBlocker; +using Content.Shared.Interaction; +using Robust.Shared.IoC; +using Robust.Shared.Localization; namespace Content.Server.Sanity { public sealed class SanitySystem : SharedSanitySystem { + [Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!; public HashSet SanityCompsToTick = new(); public float TimeAccumulator = 0.0f; public float TimeBetweenTicks = 15.0f; @@ -50,16 +57,16 @@ public void CloseUI(SanityCloseUI msg) { return; } - component.Updating = false; } - public void OpenUI(MobSanityComponent component, INetChannel channel) + public void OpenUI(MobSanityComponent component, IPlayerSession player) { component.Updating = true; - RaiseNetworkEvent(new SanityOpenUI(component.Insight, component.Sanity, component.Rest, component.Owner.Uid), channel); + component.Owner.GetUIOrNull(SanityUiKey.Key)?.Open(player); + _userInterfaceSystem.TrySetUiState(component.Owner.Uid, SanityUiKey.Key, new SanityBoundUserInterfaceState( + component.Insight, component.Sanity, component.Rest)); } - public override void Update(float frameTime) { TimeAccumulator += frameTime; @@ -78,14 +85,13 @@ public override void Update(float frameTime) continue; } alerts.ShowAlert(AlertType.MobSanity, (short)(component.Sanity/component.SanitySteps)); + if(component.Updating) { - INetChannel? channel = component.Owner.PlayerSession()?.ConnectedClient; - if (channel is not null) - { - RaiseNetworkEvent(new SanityUpdateUI(component.Insight, component.Sanity, component.Rest), channel); - } + _userInterfaceSystem.TrySetUiState(component.Owner.Uid, SanityUiKey.Key, new SanityBoundUserInterfaceState( + component.Insight, component.Sanity, component.Rest)); } + } } } diff --git a/Content.Shared/Sanity/SharedMobSanityComponent.cs b/Content.Shared/Sanity/SharedMobSanityComponent.cs index aa4f98e22dfc..b3439e4fa982 100644 --- a/Content.Shared/Sanity/SharedMobSanityComponent.cs +++ b/Content.Shared/Sanity/SharedMobSanityComponent.cs @@ -12,7 +12,11 @@ public class SharedMobSanityComponent : Component public override string Name => "Sanity"; } - + [Serializable, NetSerializable] + public enum SanityUiKey + { + Key, + } [Serializable, NetSerializable] public class SanityOpenUI : EntityEventArgs @@ -31,12 +35,12 @@ public SanityOpenUI(int insight, int sanity, int rest, EntityUid playerUID) } } [Serializable, NetSerializable] - public class SanityUpdateUI : EntityEventArgs + public class SanityBoundUserInterfaceState : BoundUserInterfaceState { public int Insight { get; } public int Sanity { get; } public int Rest { get; } - public SanityUpdateUI(int insight, int sanity, int rest) + public SanityBoundUserInterfaceState(int insight, int sanity, int rest) { Insight = insight; Sanity = sanity; diff --git a/Resources/Prototypes/Entities/Mobs/Species/human.yml b/Resources/Prototypes/Entities/Mobs/Species/human.yml index b7b4e66d8a74..97db1d5bfe72 100644 --- a/Resources/Prototypes/Entities/Mobs/Species/human.yml +++ b/Resources/Prototypes/Entities/Mobs/Species/human.yml @@ -262,6 +262,8 @@ interfaces: - key: enum.StrippingUiKey.Key type: StrippableBoundUserInterface + - key: enum.SanityUiKey.Key + type: SanityBoundUserInterface - type: Puller - type: Butcherable meat: FoodMeat From bb7ce1a7f6dd82d5fd688c787d455c5bacf0168a Mon Sep 17 00:00:00 2001 From: MLGTASTICa Date: Wed, 27 Oct 2021 17:55:55 +0300 Subject: [PATCH 16/24] Update ClientMobSanityComponent.cs --- Content.Client/Sanity/ClientMobSanityComponent.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Content.Client/Sanity/ClientMobSanityComponent.cs b/Content.Client/Sanity/ClientMobSanityComponent.cs index a966d0ff9019..1f913de2756e 100644 --- a/Content.Client/Sanity/ClientMobSanityComponent.cs +++ b/Content.Client/Sanity/ClientMobSanityComponent.cs @@ -9,12 +9,5 @@ namespace Content.Client.Sanity { public class ClientMobSanityComponent : SharedMobSanityComponent { - - public SanityWindow? SanityMenu; - - public int Sanity = 0; - public int Insight = 0; - public int Rest = 0; - } } From 525c6c435aec7f5d2a1f4cf0347234f3d8d2aabc Mon Sep 17 00:00:00 2001 From: MLGTASTICa Date: Wed, 27 Oct 2021 18:17:00 +0300 Subject: [PATCH 17/24] Fix the order --- Resources/Prototypes/Alerts/alerts.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/Resources/Prototypes/Alerts/alerts.yml b/Resources/Prototypes/Alerts/alerts.yml index bfb8427bb3bd..e0fdf8625498 100644 --- a/Resources/Prototypes/Alerts/alerts.yml +++ b/Resources/Prototypes/Alerts/alerts.yml @@ -5,6 +5,7 @@ id: BaseAlertOrder order: - category: Health + - category: Sanity - alertType: Fire - alertType: Handcuffed - category: Buckled From cec4cab99a0b16fa4da029b329904ecfec4b35d9 Mon Sep 17 00:00:00 2001 From: MLGTASTICa Date: Thu, 28 Oct 2021 17:21:55 +0300 Subject: [PATCH 18/24] Update SharedMobSanityComponent.cs --- .../Sanity/SharedMobSanityComponent.cs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Content.Shared/Sanity/SharedMobSanityComponent.cs b/Content.Shared/Sanity/SharedMobSanityComponent.cs index b3439e4fa982..e0bfd262103d 100644 --- a/Content.Shared/Sanity/SharedMobSanityComponent.cs +++ b/Content.Shared/Sanity/SharedMobSanityComponent.cs @@ -4,6 +4,12 @@ using Robust.Shared.Serialization; using Robust.Shared.Players; using Robust.Shared.Network; +using Robust.Shared.Prototypes; +using Robust.Shared.ViewVariables; +using System.Collections.Generic; +using Content.Shared.Construction.Conditions; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.Utility; namespace Content.Shared.Sanity { @@ -13,7 +19,19 @@ public class SharedMobSanityComponent : Component } [Serializable, NetSerializable] - public enum SanityUiKey + + [Prototype("SanityBreakdown")] + public class SanityBreakdownPrototype : IPrototype + { + [DataField("name")] + public string Name { get; } = string.Empty; + + [DataField("id", required: true)] + public string ID { get; } = default!; + + [DataField("duration")] + public float Duration { get; } = 120.0f; + public enum SanityUiKey { Key, } From a89d28b4e6c5320c457cf3f08bd23a8602f9a591 Mon Sep 17 00:00:00 2001 From: MLGTASTICa Date: Thu, 28 Oct 2021 20:40:28 +0300 Subject: [PATCH 19/24] Update SharedMobSanityComponent.cs --- Content.Shared/Sanity/SharedMobSanityComponent.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Content.Shared/Sanity/SharedMobSanityComponent.cs b/Content.Shared/Sanity/SharedMobSanityComponent.cs index e0bfd262103d..11d6abab751f 100644 --- a/Content.Shared/Sanity/SharedMobSanityComponent.cs +++ b/Content.Shared/Sanity/SharedMobSanityComponent.cs @@ -31,7 +31,11 @@ public class SanityBreakdownPrototype : IPrototype [DataField("duration")] public float Duration { get; } = 120.0f; - public enum SanityUiKey + } + + + + public enum SanityUiKey { Key, } From 226a056ee8db0a16fe9277f2fe46ed12f40e9daa Mon Sep 17 00:00:00 2001 From: MLGTASTICa Date: Fri, 29 Oct 2021 07:57:48 +0300 Subject: [PATCH 20/24] the prototpyes. --- Content.Shared/Sanity/SanityPrototypes.cs | 43 +++++++++++++++++++ .../Sanity/SharedMobSanityComponent.cs | 25 +++++------ 2 files changed, 54 insertions(+), 14 deletions(-) create mode 100644 Content.Shared/Sanity/SanityPrototypes.cs diff --git a/Content.Shared/Sanity/SanityPrototypes.cs b/Content.Shared/Sanity/SanityPrototypes.cs new file mode 100644 index 000000000000..b8eec3b039bc --- /dev/null +++ b/Content.Shared/Sanity/SanityPrototypes.cs @@ -0,0 +1,43 @@ +using System; +using Robust.Shared.GameObjects; +using Robust.Shared.GameStates; +using Robust.Shared.Serialization; +using Robust.Shared.Players; +using Robust.Shared.Network; +using Robust.Shared.Prototypes; +using Robust.Shared.ViewVariables; +using System.Collections.Generic; +using Content.Shared.Construction.Conditions; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.Utility; + +namespace Content.Shared.Sanity.Prototypes +{ + [Serializable, NetSerializable] + + [Prototype("sanitybreakdown")] + public class SanityBreakdownPrototype : IPrototype + { + [DataField("name")] + public string Name { get; } = string.Empty; + + [DataField("id", required: true)] + public string ID { get; } = default!; + + [DataField("duration")] + public float Duration { get; } = 120.0f; + + } + + public interface IBreakdown + { + void Start(SanityBreakdownEventArgs args) + { + } + + void End(SanityBreakdownEventArgs args) + { + + } + } +} diff --git a/Content.Shared/Sanity/SharedMobSanityComponent.cs b/Content.Shared/Sanity/SharedMobSanityComponent.cs index 11d6abab751f..48151290160e 100644 --- a/Content.Shared/Sanity/SharedMobSanityComponent.cs +++ b/Content.Shared/Sanity/SharedMobSanityComponent.cs @@ -18,24 +18,21 @@ public class SharedMobSanityComponent : Component public override string Name => "Sanity"; } - [Serializable, NetSerializable] - - [Prototype("SanityBreakdown")] - public class SanityBreakdownPrototype : IPrototype + public class SanityBreakdownEventArgs : EventArgs { - [DataField("name")] - public string Name { get; } = string.Empty; + /// + /// Player that the breakdown is acting upon + /// + public readonly IEntity Player; - [DataField("id", required: true)] - public string ID { get; } = default!; - - [DataField("duration")] - public float Duration { get; } = 120.0f; + public SanityBreakdownEventArgs(IEntity player) + { + Player = player; + } } +} - - - public enum SanityUiKey +public enum SanityUiKey { Key, } From 53979c8438bd42a184e76959eb9043f38208851b Mon Sep 17 00:00:00 2001 From: MLGTASTICa Date: Fri, 29 Oct 2021 10:04:40 +0300 Subject: [PATCH 21/24] ' --- Content.Shared/Alert/IAlertClick.cs | 2 +- Content.Shared/Sanity/SanityPrototypes.cs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Content.Shared/Alert/IAlertClick.cs b/Content.Shared/Alert/IAlertClick.cs index 614c9ee6a03c..cafa82c1e139 100644 --- a/Content.Shared/Alert/IAlertClick.cs +++ b/Content.Shared/Alert/IAlertClick.cs @@ -1,4 +1,4 @@ -using System; +using System; using Robust.Shared.GameObjects; namespace Content.Shared.Alert diff --git a/Content.Shared/Sanity/SanityPrototypes.cs b/Content.Shared/Sanity/SanityPrototypes.cs index b8eec3b039bc..132b0c8ff58b 100644 --- a/Content.Shared/Sanity/SanityPrototypes.cs +++ b/Content.Shared/Sanity/SanityPrototypes.cs @@ -37,7 +37,6 @@ void Start(SanityBreakdownEventArgs args) void End(SanityBreakdownEventArgs args) { - } } } From e81a6573fda92bd00c6d2175aa1569cc2deb5e80 Mon Sep 17 00:00:00 2001 From: MLGTASTICa Date: Mon, 1 Nov 2021 19:49:50 +0200 Subject: [PATCH 22/24] Part 18 ? : Breakdown prototypes --- Content.Shared/Sanity/SanityPrototypes.cs | 48 +++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/Content.Shared/Sanity/SanityPrototypes.cs b/Content.Shared/Sanity/SanityPrototypes.cs index 132b0c8ff58b..0f68f47d855f 100644 --- a/Content.Shared/Sanity/SanityPrototypes.cs +++ b/Content.Shared/Sanity/SanityPrototypes.cs @@ -19,17 +19,46 @@ namespace Content.Shared.Sanity.Prototypes public class SanityBreakdownPrototype : IPrototype { [DataField("name")] - public string Name { get; } = string.Empty; + public ISanityBreakdown Name { get; } = default!; - [DataField("id", required: true)] + [DataField("ID", required: true)] public string ID { get; } = default!; [DataField("duration")] public float Duration { get; } = 120.0f; + [DataField("canoccurat")] + + public int CanOccurAt { get; } = 30; + + [DataField("imposeddelay")] + + public float ImposedDelay { get; } = 300.0f; + + [DataField("beginstring")] + public string BeginString { get; } = string.Empty; + + [DataField("endingstring")] + + public string EndingString { get; } = string.Empty; + + [DataField("reoccuring")] + + public bool Reoccuring { get; } = false; + + [DataField("reoccuringmessage")] + + public float ReoccuringInterval { get; } = 10.0f; + + [DataField("reoccuringeffects")] + + public ISanityReoccuring ReoccuringEffects { get; } = default!; + + + } - public interface IBreakdown + public interface ISanityBreakdown { void Start(SanityBreakdownEventArgs args) { @@ -39,4 +68,17 @@ void End(SanityBreakdownEventArgs args) { } } + + public interface ISanityReoccuring + { + void ApplyEffects(SanityBreakdownEventArgs args) + { + + } + + void EndEffects(SanityBreakdownEventArgs args) + { + + } + } } From 097ab9992f18d0e1f42cb9d28a93c8cbc3beba61 Mon Sep 17 00:00:00 2001 From: MLGTASTICa Date: Mon, 1 Nov 2021 19:53:20 +0200 Subject: [PATCH 23/24] Update Content.Shared.csproj --- Content.Shared/Content.Shared.csproj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Content.Shared/Content.Shared.csproj b/Content.Shared/Content.Shared.csproj index 86e05845c9fa..54e2fd1524ee 100644 --- a/Content.Shared/Content.Shared.csproj +++ b/Content.Shared/Content.Shared.csproj @@ -29,6 +29,9 @@ + + + From b405e498b035c6a2098306048f708be4b301fa7b Mon Sep 17 00:00:00 2001 From: MLGTASTICa Date: Wed, 3 Nov 2021 05:27:13 +0200 Subject: [PATCH 24/24] First breakdown : crying --- .../SanityBreakdowns/BreakdownCrying.cs | 37 +++++++++++++++++++ Content.Shared/Sanity/SanityPrototypes.cs | 22 +---------- .../Sanity/Breakdowns/BreakdownCrying.yaml | 8 ++++ 3 files changed, 47 insertions(+), 20 deletions(-) create mode 100644 Content.Shared/Sanity/SanityBreakdowns/BreakdownCrying.cs create mode 100644 Resources/Prototypes/Sanity/Breakdowns/BreakdownCrying.yaml diff --git a/Content.Shared/Sanity/SanityBreakdowns/BreakdownCrying.cs b/Content.Shared/Sanity/SanityBreakdowns/BreakdownCrying.cs new file mode 100644 index 000000000000..fd536260e99a --- /dev/null +++ b/Content.Shared/Sanity/SanityBreakdowns/BreakdownCrying.cs @@ -0,0 +1,37 @@ +using System; +using Robust.Shared.GameObjects; +using Robust.Shared.GameStates; +using Robust.Shared.Serialization; +using Robust.Shared.Players; +using Robust.Shared.Network; +using Robust.Shared.Prototypes; +using Robust.Shared.ViewVariables; +using System.Collections.Generic; +using Content.Shared.Construction.Conditions; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.Utility; +using Content.Shared.Sanity.Prototypes; +using Content.Shared.Popups; + + + +namespace Content.Shared.Sanity.Breakdown.Crying +{ + public class BreakdownCrying : ISanityBreakdown + { + public void Start(SanityBreakdownEventArgs args) + { + args.Player.PopupMessage(args.Player, "You can't take it anymore , you burst into tears"); + } + + public void End(SanityBreakdownEventArgs args) + { + args.Player.PopupMessage(args.Player, "You feel the crying stop. You accept things as they are now."); + } + + public void ApplyEffects(SanityBreakdownEventArgs args) + { + args.Player.PopupMessage(args.Player, "Cries"); + } + } +} diff --git a/Content.Shared/Sanity/SanityPrototypes.cs b/Content.Shared/Sanity/SanityPrototypes.cs index 0f68f47d855f..fd86d368456a 100644 --- a/Content.Shared/Sanity/SanityPrototypes.cs +++ b/Content.Shared/Sanity/SanityPrototypes.cs @@ -35,25 +35,14 @@ public class SanityBreakdownPrototype : IPrototype public float ImposedDelay { get; } = 300.0f; - [DataField("beginstring")] - public string BeginString { get; } = string.Empty; - - [DataField("endingstring")] - - public string EndingString { get; } = string.Empty; - [DataField("reoccuring")] public bool Reoccuring { get; } = false; - [DataField("reoccuringmessage")] + [DataField("reoccuringdelay")] public float ReoccuringInterval { get; } = 10.0f; - [DataField("reoccuringeffects")] - - public ISanityReoccuring ReoccuringEffects { get; } = default!; - } @@ -67,18 +56,11 @@ void Start(SanityBreakdownEventArgs args) void End(SanityBreakdownEventArgs args) { } - } - public interface ISanityReoccuring - { void ApplyEffects(SanityBreakdownEventArgs args) { } - - void EndEffects(SanityBreakdownEventArgs args) - { - - } } + } diff --git a/Resources/Prototypes/Sanity/Breakdowns/BreakdownCrying.yaml b/Resources/Prototypes/Sanity/Breakdowns/BreakdownCrying.yaml new file mode 100644 index 000000000000..f587ccafaa76 --- /dev/null +++ b/Resources/Prototypes/Sanity/Breakdowns/BreakdownCrying.yaml @@ -0,0 +1,8 @@ + +- type: sanitybreakdown + name: !type BreakdownCrying + duration: 200f + canoccurat: 40 + imposeddelay: 0 + reoccuring: true + reoccuringinterval: 10f