From 4272976e02984fef2b44e570ff58249812634fcf Mon Sep 17 00:00:00 2001 From: Spatison <137375981+Spatison@users.noreply.github.com> Date: Thu, 19 Sep 2024 21:15:39 +0300 Subject: [PATCH 1/2] tweak: _White melee --- .../Melee}/BackStab/BackStabComponent.cs | 2 +- .../_White/Melee}/BackStab/BackStabSystem.cs | 12 ++--- .../_White/Melee/Crit/CritComponent.cs | 13 +++++ .../_White/Melee/Crit/CritSystem.cs | 53 +++++++++++++++++++ .../Locale/en-US/_white/backstab/backstab.ftl | 1 - .../Locale/en-US/_white/melee/backstab.ftl | 1 + Resources/Locale/en-US/_white/melee/crit.ftl | 1 + .../Locale/ru-RU/_white/backstab/backstab.ftl | 1 - .../Locale/ru-RU/_white/melee/backstab.ftl | 1 + Resources/Locale/ru-RU/_white/melee/crit.ftl | 1 + 10 files changed, 75 insertions(+), 11 deletions(-) rename {Content.Shared/_White => Content.Server/_White/Melee}/BackStab/BackStabComponent.cs (85%) rename {Content.Shared/_White => Content.Server/_White/Melee}/BackStab/BackStabSystem.cs (82%) create mode 100644 Content.Server/_White/Melee/Crit/CritComponent.cs create mode 100644 Content.Server/_White/Melee/Crit/CritSystem.cs delete mode 100644 Resources/Locale/en-US/_white/backstab/backstab.ftl create mode 100644 Resources/Locale/en-US/_white/melee/backstab.ftl create mode 100644 Resources/Locale/en-US/_white/melee/crit.ftl delete mode 100644 Resources/Locale/ru-RU/_white/backstab/backstab.ftl create mode 100644 Resources/Locale/ru-RU/_white/melee/backstab.ftl create mode 100644 Resources/Locale/ru-RU/_white/melee/crit.ftl diff --git a/Content.Shared/_White/BackStab/BackStabComponent.cs b/Content.Server/_White/Melee/BackStab/BackStabComponent.cs similarity index 85% rename from Content.Shared/_White/BackStab/BackStabComponent.cs rename to Content.Server/_White/Melee/BackStab/BackStabComponent.cs index 8d45386df0..f6ddf07ad5 100644 --- a/Content.Shared/_White/BackStab/BackStabComponent.cs +++ b/Content.Server/_White/Melee/BackStab/BackStabComponent.cs @@ -1,4 +1,4 @@ -namespace Content.Shared._White.BackStab; +namespace Content.Server._White.Melee.BackStab; [RegisterComponent] public sealed partial class BackStabComponent : Component diff --git a/Content.Shared/_White/BackStab/BackStabSystem.cs b/Content.Server/_White/Melee/BackStab/BackStabSystem.cs similarity index 82% rename from Content.Shared/_White/BackStab/BackStabSystem.cs rename to Content.Server/_White/Melee/BackStab/BackStabSystem.cs index f4663fa7de..bc929cd787 100644 --- a/Content.Shared/_White/BackStab/BackStabSystem.cs +++ b/Content.Server/_White/Melee/BackStab/BackStabSystem.cs @@ -1,19 +1,18 @@ +using Content.Server.Popups; using Content.Shared.Damage; using Content.Shared.Damage.Prototypes; using Content.Shared.Mobs.Components; using Content.Shared.Popups; using Content.Shared.Weapons.Melee.Events; -using Robust.Shared.Network; using Robust.Shared.Prototypes; -namespace Content.Shared._White.BackStab; +namespace Content.Server._White.Melee.BackStab; public sealed class BackStabSystem : EntitySystem { [Dependency] private readonly IPrototypeManager _prototypeManager = default!; - [Dependency] private readonly INetManager _net = default!; [Dependency] private readonly SharedTransformSystem _transform = default!; - [Dependency] private readonly SharedPopupSystem _popup = default!; + [Dependency] private readonly PopupSystem _popup = default!; public override void Initialize() { @@ -49,10 +48,7 @@ private void HandleHit(Entity ent, ref MeleeHitEvent args) args.BonusDamage = new DamageSpecifier(_prototypeManager.Index("Slash"), damage - args.BaseDamage.GetTotal()); - if (!_net.IsServer) - return; - - var message = Loc.GetString("backstab-damage-betrayal-dagger", ("damage", damage)); + var message = Loc.GetString("melee-backstab-damage", ("damage", damage)); _popup.PopupEntity(message, args.User, args.User, PopupType.MediumCaution); } } diff --git a/Content.Server/_White/Melee/Crit/CritComponent.cs b/Content.Server/_White/Melee/Crit/CritComponent.cs new file mode 100644 index 0000000000..d48aa16caa --- /dev/null +++ b/Content.Server/_White/Melee/Crit/CritComponent.cs @@ -0,0 +1,13 @@ +namespace Content.Server._White.Melee.Crit; + +[RegisterComponent] +public sealed partial class CritComponent : Component +{ + [DataField, ViewVariables(VVAccess.ReadWrite)] + public float CritChance = 0.2f; + + [DataField, ViewVariables(VVAccess.ReadWrite)] + public float CritMultiplier = 2f; + + public float? RealChance; +} diff --git a/Content.Server/_White/Melee/Crit/CritSystem.cs b/Content.Server/_White/Melee/Crit/CritSystem.cs new file mode 100644 index 0000000000..6bb530e45c --- /dev/null +++ b/Content.Server/_White/Melee/Crit/CritSystem.cs @@ -0,0 +1,53 @@ +using Content.Server.Popups; +using Content.Shared._White.Blocking; +using Content.Shared.Damage; +using Content.Shared.Damage.Prototypes; +using Content.Shared.Popups; +using Content.Shared.Weapons.Melee.Events; +using Robust.Shared.Prototypes; +using Robust.Shared.Random; + +namespace Content.Server._White.Melee.Crit; + +public sealed class CritSystem : EntitySystem +{ + [Dependency] private readonly IRobustRandom _random = default!; + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + [Dependency] private readonly PopupSystem _popup = default!; + + public override void Initialize() + { + SubscribeLocalEvent(HandleHit, before: new [] {typeof(MeleeBlockSystem)}); + } + + private void HandleHit(EntityUid uid, CritComponent component, MeleeHitEvent args) + { + if (args.HitEntities.Count == 0 + || !IsCriticalHit(component)) + { + return; + } + + var damage = args.BaseDamage.GetTotal() * component.CritMultiplier; + + args.BonusDamage = new DamageSpecifier(_prototypeManager.Index("Slash"), + damage - args.BaseDamage.GetTotal()); + + var message = Loc.GetString("melee-crit-damage", ("damage", damage)); + _popup.PopupEntity(message, args.User, args.User, PopupType.MediumCaution); + } + + private bool IsCriticalHit(CritComponent component) + { + component.RealChance ??= component.CritChance; + + var isCritical = _random.NextFloat() <= component.RealChance; + + if (isCritical) + component.RealChance = component.CritChance; + else + component.RealChance++; + + return isCritical; + } +} diff --git a/Resources/Locale/en-US/_white/backstab/backstab.ftl b/Resources/Locale/en-US/_white/backstab/backstab.ftl deleted file mode 100644 index cead93b330..0000000000 --- a/Resources/Locale/en-US/_white/backstab/backstab.ftl +++ /dev/null @@ -1 +0,0 @@ -backstab-damage-betrayal-dagger = A stab in the back: {$damage}! \ No newline at end of file diff --git a/Resources/Locale/en-US/_white/melee/backstab.ftl b/Resources/Locale/en-US/_white/melee/backstab.ftl new file mode 100644 index 0000000000..c65a78e707 --- /dev/null +++ b/Resources/Locale/en-US/_white/melee/backstab.ftl @@ -0,0 +1 @@ +melee-backstab-damage = A stab in the back: {$damage}! \ No newline at end of file diff --git a/Resources/Locale/en-US/_white/melee/crit.ftl b/Resources/Locale/en-US/_white/melee/crit.ftl new file mode 100644 index 0000000000..05eeea28f0 --- /dev/null +++ b/Resources/Locale/en-US/_white/melee/crit.ftl @@ -0,0 +1 @@ +melee-crit-damage = Critical hit: {$damage}! \ No newline at end of file diff --git a/Resources/Locale/ru-RU/_white/backstab/backstab.ftl b/Resources/Locale/ru-RU/_white/backstab/backstab.ftl deleted file mode 100644 index eb69776cb3..0000000000 --- a/Resources/Locale/ru-RU/_white/backstab/backstab.ftl +++ /dev/null @@ -1 +0,0 @@ -backstab-damage-betrayal-dagger = Удар в спину: {$damage}! \ No newline at end of file diff --git a/Resources/Locale/ru-RU/_white/melee/backstab.ftl b/Resources/Locale/ru-RU/_white/melee/backstab.ftl new file mode 100644 index 0000000000..24f9d4aa55 --- /dev/null +++ b/Resources/Locale/ru-RU/_white/melee/backstab.ftl @@ -0,0 +1 @@ +melee-backstab-damage = Удар в спину: {$damage}! \ No newline at end of file diff --git a/Resources/Locale/ru-RU/_white/melee/crit.ftl b/Resources/Locale/ru-RU/_white/melee/crit.ftl new file mode 100644 index 0000000000..c2feb43adb --- /dev/null +++ b/Resources/Locale/ru-RU/_white/melee/crit.ftl @@ -0,0 +1 @@ +melee-crit-damage = Критическое попадание: {$damage}! \ No newline at end of file From dcfd816d695ea23ccbaa5869acbd305a8357ea67 Mon Sep 17 00:00:00 2001 From: Spatison <137375981+Spatison@users.noreply.github.com> Date: Mon, 23 Sep 2024 07:50:50 +0300 Subject: [PATCH 2/2] fix --- Content.Server/_White/Melee/Crit/CritComponent.cs | 4 ++-- Content.Server/_White/Melee/Crit/CritSystem.cs | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Content.Server/_White/Melee/Crit/CritComponent.cs b/Content.Server/_White/Melee/Crit/CritComponent.cs index d48aa16caa..6ec3be02ca 100644 --- a/Content.Server/_White/Melee/Crit/CritComponent.cs +++ b/Content.Server/_White/Melee/Crit/CritComponent.cs @@ -3,10 +3,10 @@ namespace Content.Server._White.Melee.Crit; [RegisterComponent] public sealed partial class CritComponent : Component { - [DataField, ViewVariables(VVAccess.ReadWrite)] + [DataField] public float CritChance = 0.2f; - [DataField, ViewVariables(VVAccess.ReadWrite)] + [DataField] public float CritMultiplier = 2f; public float? RealChance; diff --git a/Content.Server/_White/Melee/Crit/CritSystem.cs b/Content.Server/_White/Melee/Crit/CritSystem.cs index 6bb530e45c..3ed0440d0f 100644 --- a/Content.Server/_White/Melee/Crit/CritSystem.cs +++ b/Content.Server/_White/Melee/Crit/CritSystem.cs @@ -22,11 +22,8 @@ public override void Initialize() private void HandleHit(EntityUid uid, CritComponent component, MeleeHitEvent args) { - if (args.HitEntities.Count == 0 - || !IsCriticalHit(component)) - { + if (args.HitEntities.Count == 0 || !IsCriticalHit(component)) return; - } var damage = args.BaseDamage.GetTotal() * component.CritMultiplier; @@ -46,7 +43,7 @@ private bool IsCriticalHit(CritComponent component) if (isCritical) component.RealChance = component.CritChance; else - component.RealChance++; + component.RealChance += component.CritChance; return isCritical; }