Skip to content

Commit

Permalink
Disarm comp fix (#2206)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
SkaldetSkaeg and Kirus59 authored Nov 5, 2024
1 parent 9e5ae30 commit a5b1a7b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 68 deletions.
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);
}
}

0 comments on commit a5b1a7b

Please sign in to comment.