Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disarm comp fix #2206

Merged
merged 8 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

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;
}

This file was deleted.

This file was deleted.

46 changes: 46 additions & 0 deletions Content.Shared/SS220/Weapons/Melee/Systems/DisarmOnAttackSystem.cs
Original file line number Diff line number Diff line change
@@ -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<DisarmOnAttackComponent, WeaponAttackEvent>(OnAttackEvent);
}

private void OnAttackEvent(Entity<DisarmOnAttackComponent> 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);
}
}
Loading