Fix popups (#176)

* fix: fix popups

* fix: fix naming for backstab
This commit is contained in:
ThereDrD0
2024-03-04 09:56:23 +03:00
committed by GitHub
parent 6a230aec72
commit 9251e909ab
7 changed files with 51 additions and 45 deletions

View File

@@ -49,29 +49,29 @@ public sealed class ExecutionSystem : EntitySystem
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,
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 = () =>
@@ -87,7 +87,7 @@ public sealed class ExecutionSystem : EntitySystem
}
private void OnGetInteractionVerbsGun(
EntityUid uid,
EntityUid uid,
GunComponent component,
GetVerbsEvent<UtilityVerb> args)
{
@@ -100,7 +100,7 @@ public sealed class ExecutionSystem : EntitySystem
if (!CanExecuteWithGun(weapon, victim, attacker))
return;
UtilityVerb verb = new()
{
Act = () =>
@@ -120,15 +120,15 @@ public sealed class ExecutionSystem : EntitySystem
// No point executing someone if they can't take damage
if (!TryComp<DamageableComponent>(victim, out var damage))
return false;
// You can't execute something that cannot die
if (!TryComp<MobStateComponent>(victim, out var mobState))
return false;
// You're not allowed to execute dead people (no fun allowed)
if (_mobStateSystem.IsDead(victim, mobState))
return false;
// You must be able to attack people to execute
if (!_actionBlockerSystem.CanAttack(attacker, victim))
return false;
@@ -144,25 +144,25 @@ public sealed class ExecutionSystem : EntitySystem
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;
// We must be able to actually fire the gun
if (!TryComp<GunComponent>(weapon, out var gun) && _gunSystem.CanShoot(gun!))
return false;
return true;
}
private void TryStartMeleeExecutionDoafter(EntityUid weapon, EntityUid victim, EntityUid attacker)
{
if (!CanExecuteWithMelee(weapon, victim, attacker))
@@ -180,7 +180,7 @@ public sealed class ExecutionSystem : EntitySystem
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)
{
@@ -192,12 +192,12 @@ public sealed class ExecutionSystem : EntitySystem
_doAfterSystem.TryStartDoAfter(doAfter);
}
private void TryStartGunExecutionDoafter(EntityUid weapon, EntityUid victim, EntityUid attacker)
{
if (!CanExecuteWithGun(weapon, victim, attacker))
return;
if (attacker == victim)
{
ShowExecutionPopup("suicide-popup-gun-initial-internal", Filter.Entities(attacker), PopupType.Medium, attacker, victim, weapon);
@@ -225,10 +225,10 @@ public sealed class ExecutionSystem : EntitySystem
{
if (args.Handled || args.Cancelled || args.Used == null || args.Target == null)
return false;
if (!CanExecuteWithAny(args.Used.Value, args.Target.Value, uid))
return false;
// All checks passed
return true;
}
@@ -237,7 +237,7 @@ public sealed class ExecutionSystem : EntitySystem
{
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;
@@ -246,7 +246,7 @@ public sealed class ExecutionSystem : EntitySystem
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);
@@ -261,26 +261,26 @@ public sealed class ExecutionSystem : EntitySystem
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)
{
if (args.Handled || args.Cancelled || args.Used == null || args.Target == null)
return;
var attacker = args.User;
var weapon = args.Used!.Value;
var victim = args.Target!.Value;
if (!CanExecuteWithGun(weapon, victim, attacker)) return;
// Check if any systems want to block our shot
var prevention = new ShotAttemptedEvent
{
User = attacker,
Used = weapon
};
RaiseLocalEvent(weapon, ref prevention);
if (prevention.Cancelled)
return;
@@ -288,7 +288,7 @@ public sealed class ExecutionSystem : EntitySystem
RaiseLocalEvent(attacker, ref prevention);
if (prevention.Cancelled)
return;
// Not sure what this is for but gunsystem uses it so ehhh
var attemptEv = new AttemptShootEvent(attacker, null);
RaiseLocalEvent(weapon, ref attemptEv);
@@ -297,11 +297,11 @@ public sealed class ExecutionSystem : EntitySystem
{
if (attemptEv.Message != null)
{
_popupSystem.PopupClient(attemptEv.Message, weapon, attacker);
_popupSystem.PopupEntity(attemptEv.Message, weapon, attacker);
return;
}
}
// Take some ammunition for the shot (one bullet)
var fromCoordinates = Transform(attacker).Coordinates;
var ev = new TakeAmmoEvent(1, new List<(EntityUid? Entity, IShootable Shootable)>(), fromCoordinates, attacker);
@@ -314,7 +314,7 @@ public sealed class ExecutionSystem : EntitySystem
ShowExecutionPopup("execution-popup-gun-empty", Filter.Pvs(weapon), PopupType.Medium, attacker, victim, weapon);
return;
}
// Information about the ammo like damage
DamageSpecifier damage = new DamageSpecifier();
@@ -335,9 +335,9 @@ public sealed class ExecutionSystem : EntitySystem
cartridge.Spent = true;
_appearanceSystem.SetData(ammoUid!.Value, AmmoVisuals.Spent, true);
Dirty(ammoUid.Value, cartridge);
break;
case AmmoComponent newAmmo:
TryComp<ProjectileComponent>(ammoUid, out var projectileB);
if (projectileB != null)
@@ -346,11 +346,11 @@ public sealed class ExecutionSystem : EntitySystem
}
Del(ammoUid);
break;
case HitscanPrototype hitscan:
damage = hitscan.Damage!;
break;
default:
throw new ArgumentOutOfRangeException();
}
@@ -369,11 +369,11 @@ public sealed class ExecutionSystem : EntitySystem
return;
}
}
// Gun successfully fired, deal damage
_damageableSystem.TryChangeDamage(victim, damage * DamageModifier, true);
_audioSystem.PlayEntity(component.SoundGunshot, Filter.Pvs(weapon), weapon, false, AudioParams.Default);
// Popups
if (attacker != victim)
{
@@ -394,4 +394,4 @@ public sealed class ExecutionSystem : EntitySystem
locString, ("attacker", attacker), ("victim", victim), ("weapon", weapon)),
attacker, filter, true, type);
}
}
}