From 79acb6f9ee431b76f9a2eabeee56136ed173dc21 Mon Sep 17 00:00:00 2001 From: BIGZi0348 <118811750+BIGZi0348@users.noreply.github.com> Date: Tue, 3 Sep 2024 21:14:42 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D0=BB=D0=BE=D0=B3?= =?UTF-8?q?=D0=B8=D0=BA=D0=B8=20=D1=81=D0=B8=D1=81=D1=82=D0=B5=D0=BC=D1=8B?= =?UTF-8?q?=20=D0=BE=D1=82=D1=80=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F=20(#6?= =?UTF-8?q?82)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixed ReflectSystem + Added logic for reflective items positioning * Total oppsie fix * Born to shitcode --- .../Item/ItemToggle/SharedItemToggleSystem.cs | 2 +- .../Weapons/Reflect/ReflectComponent.cs | 24 +++++++++ .../Weapons/Reflect/ReflectSystem.cs | 51 ++++++++++++++++--- Content.Shared/Wieldable/ItemWieldedEvent.cs | 22 +++++++- Content.Shared/Wieldable/WieldableSystem.cs | 4 +- .../Entities/Clothing/OuterClothing/armor.yml | 2 + .../Entities/Objects/Weapons/Melee/sword.yml | 2 + 7 files changed, 95 insertions(+), 12 deletions(-) diff --git a/Content.Shared/Item/ItemToggle/SharedItemToggleSystem.cs b/Content.Shared/Item/ItemToggle/SharedItemToggleSystem.cs index 8f330cb27a..4ef614f298 100644 --- a/Content.Shared/Item/ItemToggle/SharedItemToggleSystem.cs +++ b/Content.Shared/Item/ItemToggle/SharedItemToggleSystem.cs @@ -216,7 +216,7 @@ public abstract class SharedItemToggleSystem : EntitySystem private void TurnOnonWielded(EntityUid uid, ItemToggleComponent itemToggle, ref ItemWieldedEvent args) { if (!itemToggle.Activated) - TryActivate(uid, itemToggle: itemToggle); + TryActivate(uid, args.User, itemToggle: itemToggle); // WD added "args.User" parameter } public bool IsActivated(EntityUid uid, ItemToggleComponent? comp = null) diff --git a/Content.Shared/Weapons/Reflect/ReflectComponent.cs b/Content.Shared/Weapons/Reflect/ReflectComponent.cs index bbe5e6ac8f..13ef5fceaf 100644 --- a/Content.Shared/Weapons/Reflect/ReflectComponent.cs +++ b/Content.Shared/Weapons/Reflect/ReflectComponent.cs @@ -39,6 +39,22 @@ public sealed partial class ReflectComponent : Component [DataField] public bool Innate = false; + // WD START + /// + /// If the item for reflection needed in inventory slots only - select Body. + /// If the item for reflection needed in hands only - select Hands. + /// Otherwise it will reflect in any inventory position. + /// + [ViewVariables(VVAccess.ReadWrite), DataField] + public Placement Placement = Placement.Hands | Placement.Body; + + /// + /// Can only reflect when placed correctly. + /// + [DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] + public bool InRightPlace = true; + // WD END + /// /// Maximum probability for a projectile to be reflected. /// @@ -71,3 +87,11 @@ public enum ReflectType : byte NonEnergy = 1 << 0, Energy = 1 << 1, } + +[Flags] +public enum Placement : byte +{ + None = 0, + Hands = 1 << 0, + Body = 1 << 1, +} diff --git a/Content.Shared/Weapons/Reflect/ReflectSystem.cs b/Content.Shared/Weapons/Reflect/ReflectSystem.cs index 053f608f80..c37cc0197a 100644 --- a/Content.Shared/Weapons/Reflect/ReflectSystem.cs +++ b/Content.Shared/Weapons/Reflect/ReflectSystem.cs @@ -103,6 +103,7 @@ public sealed class ReflectSystem : EntitySystem if ( !Resolve(reflector, ref reflect, false) || !reflect.Enabled || + !reflect.InRightPlace || // WD !TryComp(projectile, out var reflective) || (reflect.Reflects & reflective.Reflective) == 0x0 || !TryComp(projectile, out var physics) || @@ -210,6 +211,7 @@ public sealed class ReflectSystem : EntitySystem { if (!TryComp(reflector, out var reflect) || !reflect.Enabled || + !reflect.InRightPlace || // WD TryComp(reflector, out var staminaComponent) && staminaComponent.Critical || _standing.IsDown(reflector)) { @@ -246,7 +248,9 @@ public sealed class ReflectSystem : EntitySystem EnsureComp(args.Equipee); - if (component.Enabled) + component.InRightPlace = IsInRightPlace(component, Placement.Body); // WD + + if (component.Enabled && component.InRightPlace) // WD added component.InRightPlace EnableAlert(args.Equipee); } @@ -262,7 +266,9 @@ public sealed class ReflectSystem : EntitySystem EnsureComp(args.User); - if (component.Enabled) + component.InRightPlace = IsInRightPlace(component, Placement.Hands); // WD + + if (component.Enabled && component.InRightPlace) // WD added component.InRightPlace EnableAlert(args.User); } @@ -276,10 +282,18 @@ public sealed class ReflectSystem : EntitySystem comp.Enabled = args.Activated; Dirty(uid, comp); - if (comp.Enabled) - EnableAlert(uid); - else - DisableAlert(uid); + // WD edit start + // Reason for the edit: previously EnableAlert and DisableAlert were given an "EntityUid uid" which + // belongs to an item, not to the item user. Now its logic corrected and moved to "RefreshReflectUser()". + // if (comp.Enabled) + // EnableAlert(uid); + // else + // DisableAlert(uid); + if (args.User != null) + { + RefreshReflectUser((EntityUid) args.User); + } + // WD edit end } /// @@ -293,7 +307,19 @@ public sealed class ReflectSystem : EntitySystem continue; EnsureComp(user); - EnableAlert(user); + + // WD edit start + // Reason for the edit: to ensure correct display of alert. + if (!TryComp(ent, out var component)) + continue; + if (component.Enabled && component.InRightPlace) + EnableAlert(user); + else + { + DisableAlert(user); + continue; + } + // WD edit end return; } @@ -311,4 +337,15 @@ public sealed class ReflectSystem : EntitySystem { _alerts.ClearAlert(alertee, AlertType.Deflecting); } + + /// + /// Selfdescribing. + /// + private static bool IsInRightPlace(ReflectComponent component, Placement placement) // WD + { + if (component.Placement == (Placement.Hands | Placement.Body)) + return true; + else + return (component.Placement & placement) != 0x0; + } } diff --git a/Content.Shared/Wieldable/ItemWieldedEvent.cs b/Content.Shared/Wieldable/ItemWieldedEvent.cs index 15e204728a..6664941990 100644 --- a/Content.Shared/Wieldable/ItemWieldedEvent.cs +++ b/Content.Shared/Wieldable/ItemWieldedEvent.cs @@ -3,5 +3,23 @@ namespace Content.Shared.Wieldable; /// /// Raised directed on an entity when it is wielded. /// -[ByRefEvent] -public readonly record struct ItemWieldedEvent; +// WD edit start +// Reason for the edit: previously ItemWieldedEvent didn't contained "EntityUid user" parameter. +// Now it's done like ItemUnwieldedEvent with "EntityUid user" parameter for correct logic work. +// [ByRefEvent] +// public readonly record struct ItemWieldedEvent; +public sealed class ItemWieldedEvent : EntityEventArgs +{ + public EntityUid? User; + /// + /// Whether the item is being forced to be wielded, or if the player chose to wield it themselves. + /// + public bool Force; + + public ItemWieldedEvent(EntityUid? user = null, bool force = false) + { + User = user; + Force = force; + } +} +// WD edit end diff --git a/Content.Shared/Wieldable/WieldableSystem.cs b/Content.Shared/Wieldable/WieldableSystem.cs index 8a1446c613..11d70bb358 100644 --- a/Content.Shared/Wieldable/WieldableSystem.cs +++ b/Content.Shared/Wieldable/WieldableSystem.cs @@ -226,8 +226,8 @@ public sealed class WieldableSystem : EntitySystem var othersMessage = Loc.GetString("wieldable-component-successful-wield-other", ("user", user), ("item", used)); _popupSystem.PopupPredicted(selfMessage, othersMessage, user, user); - var targEv = new ItemWieldedEvent(); - RaiseLocalEvent(used, ref targEv); + var targEv = new ItemWieldedEvent(user); // WD added user + RaiseLocalEvent(used, targEv); // WD removed ref from targEv Dirty(used, component); return true; diff --git a/Resources/Prototypes/Entities/Clothing/OuterClothing/armor.yml b/Resources/Prototypes/Entities/Clothing/OuterClothing/armor.yml index 5e857cbd05..e440671139 100644 --- a/Resources/Prototypes/Entities/Clothing/OuterClothing/armor.yml +++ b/Resources/Prototypes/Entities/Clothing/OuterClothing/armor.yml @@ -108,6 +108,8 @@ - type: Reflect reflectProb: 1 innate: true # armor grants a passive shield that does not require concentration to maintain + placement: # WD + - Body reflects: - Energy diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Melee/sword.yml b/Resources/Prototypes/Entities/Objects/Weapons/Melee/sword.yml index c8872494ee..b3f4362f02 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Melee/sword.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Melee/sword.yml @@ -101,6 +101,8 @@ reflectProb: 0.3 velocityBeforeNotMaxProb: 6.0 # don't punish ninjas for being ninjas velocityBeforeMinProb: 10.0 + placement: # WD + - Hands - type: MeleeBlock delay: 6.1