diff --git a/Content.Shared/SS220/Weapons/Melee/KnockingWeaponOutOfHands/Components/KnockingWeaponOutOfHandsComponent.cs b/Content.Shared/SS220/Weapons/Melee/KnockingWeaponOutOfHands/Components/KnockingWeaponOutOfHandsComponent.cs new file mode 100644 index 00000000000000..c7ec55a7134ec5 --- /dev/null +++ b/Content.Shared/SS220/Weapons/Melee/KnockingWeaponOutOfHands/Components/KnockingWeaponOutOfHandsComponent.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 +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 new file mode 100644 index 00000000000000..508d31def7cdd0 --- /dev/null +++ b/Content.Shared/SS220/Weapons/Melee/KnockingWeaponOutOfHands/Systems/KnockingWeaponOutOfHandsSystem.cs @@ -0,0 +1,52 @@ +// © 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/Weapons/Melee/Events/AttackEvent.cs b/Content.Shared/Weapons/Melee/Events/AttackEvent.cs index 11720be2ee8cfd..d9a04a73111248 100644 --- a/Content.Shared/Weapons/Melee/Events/AttackEvent.cs +++ b/Content.Shared/Weapons/Melee/Events/AttackEvent.cs @@ -51,4 +51,47 @@ public AttackedEvent(EntityUid used, EntityUid user, EntityCoordinates clickLoca public bool Cancelled = false; // SS220 hook attack event end } + //ss220 extended weapon logic start + public enum AttackType + { + NONE = 0, + LIGHT = 1 << 0, + HEAVY = 1 << 1, + + All = ~NONE + } + + /// + /// SS220 Event raised on user for extended melee weapon logic. + /// + [Serializable] + public sealed class WeaponAttackEvent : EntityEventArgs + { + /// + /// Entity that triggered the attack. + /// + public EntityUid User { get; } + + /// + /// Entity that was attacked. + /// + public EntityUid Target { get; } + + /// + /// Type of the attack that been used. + /// + public AttackType Type { get; } + + /// + /// The original location that was clicked by the user. + /// + + public WeaponAttackEvent(EntityUid user, EntityUid target, AttackType type) + { + User = user; + Target = target; + Type = type; + } + } + //ss220 extended weapon logic end } diff --git a/Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs b/Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs index 72265038d939d5..852f63b0f9dd17 100644 --- a/Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs +++ b/Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs @@ -508,6 +508,11 @@ protected virtual void DoLightAttack(EntityUid user, LightAttackEvent ev, Entity var attackedEvent = new AttackedEvent(meleeUid, user, targetXform.Coordinates); RaiseLocalEvent(target.Value, attackedEvent); + //ss220 extended weapon logic start + var weaponAttackEvent = new WeaponAttackEvent(user, target.Value, AttackType.LIGHT); + RaiseLocalEvent(meleeUid, weaponAttackEvent); + //ss220 extended weapon logic end + // SS220 hook attack event start if (attackedEvent.Cancelled) return; @@ -658,6 +663,11 @@ private bool DoHeavyAttack(EntityUid user, HeavyAttackEvent ev, EntityUid meleeU var attackedEvent = new AttackedEvent(meleeUid, user, GetCoordinates(ev.Coordinates)); RaiseLocalEvent(entity, attackedEvent); + //ss220 extended weapon logic start + var weaponAttackEvent = new WeaponAttackEvent(user, entity, AttackType.HEAVY); + RaiseLocalEvent(meleeUid, weaponAttackEvent); + //ss220 extended weapon logic end + // SS220 hook attack event start if (attackedEvent.Cancelled) continue;