Skip to content

Commit

Permalink
remove dupe melee execution code, fix
Browse files Browse the repository at this point in the history
  • Loading branch information
deltanedas committed Sep 1, 2024
1 parent e1eb837 commit 6d0102f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 104 deletions.
102 changes: 0 additions & 102 deletions Content.Server/Execution/ExecutionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Content.Shared.Popups;
using Content.Shared.Projectiles;
using Content.Shared.Verbs;
using Content.Shared.Weapons.Melee;
using Content.Shared.Weapons.Ranged;
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Events;
Expand Down Expand Up @@ -41,7 +40,6 @@ public sealed class ExecutionSystem : EntitySystem
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
[Dependency] private readonly GunSystem _gunSystem = default!;

private const float MeleeExecutionTimeModifier = 5.0f;
private const float GunExecutionTime = 6.0f;
private const float DamageModifier = 9.0f;

Expand All @@ -50,42 +48,11 @@ public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<SharpComponent, GetVerbsEvent<UtilityVerb>>(OnGetInteractionVerbsMelee);
SubscribeLocalEvent<GunComponent, GetVerbsEvent<UtilityVerb>>(OnGetInteractionVerbsGun);

SubscribeLocalEvent<SharpComponent, ExecutionDoAfterEvent>(OnDoafterMelee);
SubscribeLocalEvent<GunComponent, ExecutionDoAfterEvent>(OnDoafterGun);
}

private void OnGetInteractionVerbsMelee(
EntityUid uid,
SharpComponent component,
GetVerbsEvent<UtilityVerb> args)
{
if (args.Hands == null || args.Using == null || !args.CanAccess || !args.CanInteract)
return;

var attacker = args.User;
var weapon = args.Using!.Value;
var victim = args.Target;

if (!CanExecuteWithMelee(weapon, victim, attacker))
return;

UtilityVerb verb = new()
{
Act = () =>
{
TryStartMeleeExecutionDoafter(weapon, victim, attacker);
},
Impact = LogImpact.High,
Text = Loc.GetString("execution-verb-name"),
Message = Loc.GetString("execution-verb-message"),
};

args.Verbs.Add(verb);
}

private void OnGetInteractionVerbsGun(
EntityUid uid,
GunComponent component,
Expand Down Expand Up @@ -144,17 +111,6 @@ private bool CanExecuteWithAny(EntityUid weapon, EntityUid victim, EntityUid att
return true;
}

private bool CanExecuteWithMelee(EntityUid weapon, EntityUid victim, EntityUid user)
{
if (!CanExecuteWithAny(weapon, victim, user)) return false;

// We must be able to actually hurt people with the weapon
if (!TryComp<MeleeWeaponComponent>(weapon, out var melee) && melee!.Damage.GetTotal() > 0.0f)
return false;

return true;
}

private bool CanExecuteWithGun(EntityUid weapon, EntityUid victim, EntityUid user)
{
if (!CanExecuteWithAny(weapon, victim, user)) return false;
Expand All @@ -166,35 +122,6 @@ private bool CanExecuteWithGun(EntityUid weapon, EntityUid victim, EntityUid use
return true;
}

private void TryStartMeleeExecutionDoafter(EntityUid weapon, EntityUid victim, EntityUid attacker)
{
if (!CanExecuteWithMelee(weapon, victim, attacker))
return;

var executionTime = (1.0f / Comp<MeleeWeaponComponent>(weapon).AttackRate) * MeleeExecutionTimeModifier;

if (attacker == victim)
{
ShowExecutionPopup("suicide-popup-melee-initial-internal", Filter.Entities(attacker), PopupType.Medium, attacker, victim, weapon);
ShowExecutionPopup("suicide-popup-melee-initial-external", Filter.PvsExcept(attacker), PopupType.MediumCaution, attacker, victim, weapon);
}
else
{
ShowExecutionPopup("execution-popup-melee-initial-internal", Filter.Entities(attacker), PopupType.Medium, attacker, victim, weapon);
ShowExecutionPopup("execution-popup-melee-initial-external", Filter.PvsExcept(attacker), PopupType.MediumCaution, attacker, victim, weapon);
}

var doAfter =
new DoAfterArgs(EntityManager, attacker, executionTime, new ExecutionDoAfterEvent(), weapon, target: victim, used: weapon)
{
BreakOnMove = true,
BreakOnDamage = true,
NeedHand = true
};

_doAfterSystem.TryStartDoAfter(doAfter);
}

private void TryStartGunExecutionDoafter(EntityUid weapon, EntityUid victim, EntityUid attacker)
{
if (!CanExecuteWithGun(weapon, victim, attacker))
Expand Down Expand Up @@ -234,35 +161,6 @@ private bool OnDoafterChecks(EntityUid uid, DoAfterEvent args)
return true;
}

private void OnDoafterMelee(EntityUid uid, SharpComponent component, DoAfterEvent args)
{
if (args.Handled || args.Cancelled || args.Used == null || args.Target == null)
return;

var attacker = args.User;
var victim = args.Target!.Value;
var weapon = args.Used!.Value;

if (!CanExecuteWithMelee(weapon, victim, attacker)) return;

if (!TryComp<MeleeWeaponComponent>(weapon, out var melee) && melee!.Damage.GetTotal() > 0.0f)
return;

_damageableSystem.TryChangeDamage(victim, melee.Damage * DamageModifier, true);
_audioSystem.PlayEntity(melee.HitSound, Filter.Pvs(weapon), weapon, true, AudioParams.Default);

if (attacker == victim)
{
ShowExecutionPopup("suicide-popup-melee-complete-internal", Filter.Entities(attacker), PopupType.Medium, attacker, victim, weapon);
ShowExecutionPopup("suicide-popup-melee-complete-external", Filter.PvsExcept(attacker), PopupType.MediumCaution, attacker, victim, weapon);
}
else
{
ShowExecutionPopup("execution-popup-melee-complete-internal", Filter.Entities(attacker), PopupType.Medium, attacker, victim, weapon);
ShowExecutionPopup("execution-popup-melee-complete-external", Filter.PvsExcept(attacker), PopupType.MediumCaution, attacker, victim, weapon);
}
}

// TODO: This repeats a lot of the code of the serverside GunSystem, make it not do that
private void OnDoafterGun(EntityUid uid, GunComponent component, DoAfterEvent args)
{
Expand Down
4 changes: 4 additions & 0 deletions Content.Shared/Execution/SharedExecutionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ public bool CanBeExecuted(EntityUid victim, EntityUid attacker)
if (victim != attacker && _actionBlocker.CanInteract(victim, null))
return false;

// DeltaV: no suicide
if (victim == attacker)
return false;

// All checks passed
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions Resources/Prototypes/DeltaV/Catalog/Fills/Lockers/cargo.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Added to LockerFillSalvageSpecialist with a nested selector
- type: entityTable
id: LockerFillSalvageSpecialistDeltaV
table: !AllSelector
table: !type:AllSelector
children:
- id: SeismicCharge
amount: 2
- id: SeismicCharge
- id: OreBag
- id: ClothingShoesBootsWinterMiner
- id: JetpackMiniFilled # replaces fire extinguisher
Expand Down

0 comments on commit 6d0102f

Please sign in to comment.