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

View File

@@ -120,7 +120,7 @@ public sealed class InteractionPopupSystem : EntitySystem
_popupSystem.PopupEntity(msg, uid, user);
_popupSystem.PopupEntity(msgOthers, uid, Filter.PvsExcept(user, entityManager: EntityManager), true);
}
else
else if (msg != "") // WD edit
_popupSystem.PopupEntity(msg, uid, user); //play only for the initiating entity.
if (sfx is not null) //not all cases will have sound.

View File

@@ -323,7 +323,7 @@ namespace Content.Server.VendingMachines
if (_accessReader.IsAllowed(sender, uid, accessReader) || HasComp<EmaggedComponent>(uid))
return true;
Popup.PopupClient(Loc.GetString("vending-machine-component-try-eject-access-denied"), uid, sender);
Popup.PopupEntity(Loc.GetString("vending-machine-component-try-eject-access-denied"), uid, sender);
Deny(uid, vendComponent);
return false;
}
@@ -352,7 +352,7 @@ namespace Content.Server.VendingMachines
if (entry == null)
{
if (sender.HasValue)
Popup.PopupClient(Loc.GetString("vending-machine-component-try-eject-invalid-item"), uid, sender.Value);
Popup.PopupEntity(Loc.GetString("vending-machine-component-try-eject-invalid-item"), uid, sender.Value);
Deny(uid, vendComponent);
@@ -362,7 +362,7 @@ namespace Content.Server.VendingMachines
if (entry.Amount <= 0)
{
if (sender.HasValue)
Popup.PopupClient(Loc.GetString("vending-machine-component-try-eject-out-of-stock"), uid, sender.Value);
Popup.PopupEntity(Loc.GetString("vending-machine-component-try-eject-out-of-stock"), uid, sender.Value);
Deny(uid, vendComponent);
return;

View File

@@ -1,7 +1,7 @@
using Content.Server.Popups;
using Content.Server.Xenoarchaeology.Equipment.Components;
using Content.Server.Xenoarchaeology.XenoArtifacts;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Shared.Timing;
namespace Content.Server.Xenoarchaeology.Equipment.Systems;
@@ -9,7 +9,7 @@ namespace Content.Server.Xenoarchaeology.Equipment.Systems;
public sealed class NodeScannerSystem : EntitySystem
{
[Dependency] private readonly UseDelaySystem _useDelay = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
/// <inheritdoc/>
public override void Initialize()
@@ -36,7 +36,7 @@ public sealed class NodeScannerSystem : EntitySystem
return;
// WD edit
_popupSystem.PopupClient(Loc.GetString("node-scan-popup",
_popupSystem.PopupEntity(Loc.GetString("node-scan-popup",
("id", $"{artifact.CurrentNodeId}")), target, args.User);
}
}

View File

@@ -147,12 +147,12 @@ public sealed class CultistFactorySystem : EntitySystem
if (args.IsAnchored)
{
_transform.Unanchor(target, xform);
_popup.PopupClient(Loc.GetString("anchorable-unanchored"), uid, args.User);
_popup.PopupEntity(Loc.GetString("anchorable-unanchored"), uid, args.User);
}
else
{
_transform.AnchorEntity(target, xform);
_popup.PopupClient(Loc.GetString("anchorable-anchored"), uid, args.User);
_popup.PopupEntity(Loc.GetString("anchorable-anchored"), uid, args.User);
}
_audio.PlayPvs("/Audio/Items/ratchet.ogg", uid);

View File

@@ -48,5 +48,10 @@ public sealed class BackstabSystem : EntitySystem
args.PenetrateArmor = ent.Comp.PenetrateArmor;
if (!_net.IsServer)
return;
var message = Loc.GetString("backstab-damage-betrayal-dagger", ("damage", damage));
_popup.PopupClient(message, args.User, args.User, PopupType.MediumCaution);
}
}

View File

@@ -0,0 +1 @@
backstab-damage-betrayal-dagger = Удар в спину: {$damage}!