forked from space-wizards/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add extended melee weapon logic (#1831)
* add extended weapon logic * added a division by type of the attack * fixes * check fix
- Loading branch information
Showing
4 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
...20/Weapons/Melee/KnockingWeaponOutOfHands/Components/KnockingWeaponOutOfHandsComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
52 changes: 52 additions & 0 deletions
52
...ed/SS220/Weapons/Melee/KnockingWeaponOutOfHands/Systems/KnockingWeaponOutOfHandsSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<KnockingWeaponOutOfHandsComponent, WeaponAttackEvent>(OnAttackEvent); | ||
} | ||
|
||
private void OnAttackEvent(Entity<KnockingWeaponOutOfHandsComponent> 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<KnockingWeaponOutOfHandsComponent> entity, EntityUid target) | ||
{ | ||
foreach (var handOrInventoryEntity in _inventory.GetHandOrInventoryEntities(target, SlotFlags.POCKET)) | ||
{ | ||
if (!HasComp<MeleeWeaponComponent>(handOrInventoryEntity) | ||
|| !HasComp<GunComponent>(handOrInventoryEntity)) | ||
continue; | ||
if (!_random.Prob(entity.Comp.Chance)) | ||
continue; | ||
_handsSystem.TryDrop(target, handOrInventoryEntity); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters