From a5b1a7bcbd149c8d3cf8414314492c411e756f68 Mon Sep 17 00:00:00 2001 From: SkaldetSkaeg Date: Tue, 5 Nov 2024 12:12:12 +0700 Subject: [PATCH] Disarm comp fix (#2206) * deleted old comp and sys * new comp * rework done * 1 more tip * + comment * kirus fix * kirus fix 2 * Update DisarmOnAttackComponent.cs --------- Co-authored-by: Kirus59 <145689588+Kirus59@users.noreply.github.com> --- .../Components/DisarmOnAttackComponent.cs | 16 ++++++ .../KnockingWeaponOutOfHandsComponent.cs | 16 ------ .../Systems/KnockingWeaponOutOfHandsSystem.cs | 52 ------------------- .../Melee/Systems/DisarmOnAttackSystem.cs | 46 ++++++++++++++++ 4 files changed, 62 insertions(+), 68 deletions(-) create mode 100644 Content.Shared/SS220/Weapons/Melee/Components/DisarmOnAttackComponent.cs delete mode 100644 Content.Shared/SS220/Weapons/Melee/KnockingWeaponOutOfHands/Components/KnockingWeaponOutOfHandsComponent.cs delete mode 100644 Content.Shared/SS220/Weapons/Melee/KnockingWeaponOutOfHands/Systems/KnockingWeaponOutOfHandsSystem.cs create mode 100644 Content.Shared/SS220/Weapons/Melee/Systems/DisarmOnAttackSystem.cs diff --git a/Content.Shared/SS220/Weapons/Melee/Components/DisarmOnAttackComponent.cs b/Content.Shared/SS220/Weapons/Melee/Components/DisarmOnAttackComponent.cs new file mode 100644 index 00000000000000..00f6325ae87e55 --- /dev/null +++ b/Content.Shared/SS220/Weapons/Melee/Components/DisarmOnAttackComponent.cs @@ -0,0 +1,16 @@ +// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt + +using Robust.Shared.GameStates; + +namespace Content.Shared.SS220.Weapons.Melee.Components; + +[RegisterComponent, NetworkedComponent] +public sealed partial class DisarmOnAttackComponent : Component +{ + //Should be between 0 and 1 + [DataField(required: true)] + public float Chance = 0; + + [DataField] + public float HeavyAttackChance = 0; +} diff --git a/Content.Shared/SS220/Weapons/Melee/KnockingWeaponOutOfHands/Components/KnockingWeaponOutOfHandsComponent.cs b/Content.Shared/SS220/Weapons/Melee/KnockingWeaponOutOfHands/Components/KnockingWeaponOutOfHandsComponent.cs deleted file mode 100644 index c7ec55a7134ec5..00000000000000 --- a/Content.Shared/SS220/Weapons/Melee/KnockingWeaponOutOfHands/Components/KnockingWeaponOutOfHandsComponent.cs +++ /dev/null @@ -1,16 +0,0 @@ -// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt -namespace Content.Shared.SS220.Weapons.Melee.KnockingWeaponOutOfHands.Components; - -[RegisterComponent] - -public sealed partial class KnockingWeaponOutOfHandsComponent : Component -{ - [DataField] - public bool DropOnHeavyAtack = true; - - [DataField] - public bool DropOnLightAtack = true; - - [DataField("chance", required: true)] - public float Chance; -} diff --git a/Content.Shared/SS220/Weapons/Melee/KnockingWeaponOutOfHands/Systems/KnockingWeaponOutOfHandsSystem.cs b/Content.Shared/SS220/Weapons/Melee/KnockingWeaponOutOfHands/Systems/KnockingWeaponOutOfHandsSystem.cs deleted file mode 100644 index 508d31def7cdd0..00000000000000 --- a/Content.Shared/SS220/Weapons/Melee/KnockingWeaponOutOfHands/Systems/KnockingWeaponOutOfHandsSystem.cs +++ /dev/null @@ -1,52 +0,0 @@ -// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt -using Content.Shared.SS220.Weapons.Melee.KnockingWeaponOutOfHands.Components; -using Content.Shared.Hands.EntitySystems; -using Content.Shared.Inventory; -using Content.Shared.Weapons.Melee; -using Content.Shared.Weapons.Melee.Events; -using Content.Shared.Weapons.Ranged.Components; -using Robust.Shared.Random; - -namespace Content.Shared.SS220.Weapons.Melee.KnockingWeaponOutOfHands.Systems; - -public sealed class KnockingWeaponOutOfHandsSystem : EntitySystem -{ - [Dependency] private readonly InventorySystem _inventory = default!; - [Dependency] private readonly SharedHandsSystem _handsSystem = default!; - [Dependency] private readonly IRobustRandom _random = default!; - - - public override void Initialize() - { - base.Initialize(); - SubscribeLocalEvent(OnAttackEvent); - } - - private void OnAttackEvent(Entity entity, ref WeaponAttackEvent args) - { - switch(args.Type) - { - case AttackType.HEAVY: - if(entity.Comp.DropOnHeavyAtack) - DropOnAtack(entity, args.Target); - break; - case AttackType.LIGHT: - if(entity.Comp.DropOnLightAtack) - DropOnAtack(entity, args.Target); - break; - } - } - - private void DropOnAtack(Entity entity, EntityUid target) - { - foreach (var handOrInventoryEntity in _inventory.GetHandOrInventoryEntities(target, SlotFlags.POCKET)) - { - if (!HasComp(handOrInventoryEntity) - || !HasComp(handOrInventoryEntity)) - continue; - if (!_random.Prob(entity.Comp.Chance)) - continue; - _handsSystem.TryDrop(target, handOrInventoryEntity); - } - } -} diff --git a/Content.Shared/SS220/Weapons/Melee/Systems/DisarmOnAttackSystem.cs b/Content.Shared/SS220/Weapons/Melee/Systems/DisarmOnAttackSystem.cs new file mode 100644 index 00000000000000..ad482eb98e67b6 --- /dev/null +++ b/Content.Shared/SS220/Weapons/Melee/Systems/DisarmOnAttackSystem.cs @@ -0,0 +1,46 @@ +// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt + +using Content.Shared.SS220.Weapons.Melee.Components; +using Content.Shared.Hands.EntitySystems; +using Content.Shared.Inventory; +using Content.Shared.Weapons.Melee.Events; +using Content.Shared.CombatMode; +using Robust.Shared.Random; + +namespace Content.Shared.SS220.Weapons.Melee.Systems; + +public sealed class SharedDisarmOnAttackSystem : EntitySystem +{ + [Dependency] private readonly InventorySystem _inventory = default!; + [Dependency] private readonly SharedHandsSystem _handsSystem = default!; + [Dependency] private readonly IRobustRandom _random = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnAttackEvent); + } + + private void OnAttackEvent(Entity ent, ref WeaponAttackEvent args) + { + bool chance = false; ; + + switch (args.Type) + { + case AttackType.HEAVY: + chance = _random.Prob(ent.Comp.HeavyAttackChance); + break; + + case AttackType.LIGHT: + chance = _random.Prob(ent.Comp.Chance); + break; + } + + if (!chance) + return; + + var ev = new DisarmedEvent { Target = args.Target, Source = args.User }; + RaiseLocalEvent(args.Target, ev); + } +}