Remove stamina + damageable .Owner (#14602)

* Remove stamina + damageable .Owner

* More
This commit is contained in:
metalgearsloth
2023-03-13 00:19:05 +11:00
committed by GitHub
parent 058c732db1
commit 49c7c0f9a7
12 changed files with 70 additions and 59 deletions

View File

@@ -99,10 +99,10 @@ namespace Content.Shared.Damage
/// Useful for some unfriendly folk. Also ensures that cached values are updated and that a damage changed
/// event is raised.
/// </remarks>
public void SetDamage(DamageableComponent damageable, DamageSpecifier damage)
public void SetDamage(EntityUid uid, DamageableComponent damageable, DamageSpecifier damage)
{
damageable.Damage = damage;
DamageChanged(damageable);
DamageChanged(uid, damageable);
}
/// <summary>
@@ -112,19 +112,19 @@ namespace Content.Shared.Damage
/// This updates cached damage information, flags the component as dirty, and raises a damage changed event.
/// The damage changed event is used by other systems, such as damage thresholds.
/// </remarks>
public void DamageChanged(DamageableComponent component, DamageSpecifier? damageDelta = null,
public void DamageChanged(EntityUid uid, DamageableComponent component, DamageSpecifier? damageDelta = null,
bool interruptsDoAfters = true, EntityUid? origin = null)
{
component.DamagePerGroup = component.Damage.GetDamagePerGroup(_prototypeManager);
component.TotalDamage = component.Damage.Total;
Dirty(component);
if (EntityManager.TryGetComponent<AppearanceComponent>(component.Owner, out var appearance) && damageDelta != null)
if (EntityManager.TryGetComponent<AppearanceComponent>(uid, out var appearance) && damageDelta != null)
{
var data = new DamageVisualizerGroupData(damageDelta.GetDamagePerGroup(_prototypeManager).Keys.ToList());
_appearance.SetData(component.Owner, DamageVisualizerKeys.DamageUpdateGroups, data, appearance);
_appearance.SetData(uid, DamageVisualizerKeys.DamageUpdateGroups, data, appearance);
}
RaiseLocalEvent(component.Owner, new DamageChangedEvent(component, damageDelta, interruptsDoAfters, origin));
RaiseLocalEvent(uid, new DamageChangedEvent(component, damageDelta, interruptsDoAfters, origin));
}
/// <summary>
@@ -169,7 +169,7 @@ namespace Content.Shared.Damage
}
var ev = new DamageModifyEvent(damage);
RaiseLocalEvent(uid.Value, ev, false);
RaiseLocalEvent(uid.Value, ev);
damage = ev.Damage;
if (damage.Empty)
@@ -189,7 +189,7 @@ namespace Content.Shared.Damage
if (!delta.Empty)
{
DamageChanged(damageable, delta, interruptsDoAfters, origin);
DamageChanged(uid.Value, damageable, delta, interruptsDoAfters, origin);
}
return delta;
@@ -201,7 +201,7 @@ namespace Content.Shared.Damage
/// <remakrs>
/// Does nothing If the given damage value is negative.
/// </remakrs>
public void SetAllDamage(DamageableComponent component, FixedPoint2 newValue)
public void SetAllDamage(EntityUid uid, DamageableComponent component, FixedPoint2 newValue)
{
if (newValue < 0)
{
@@ -216,7 +216,7 @@ namespace Content.Shared.Damage
// Setting damage does not count as 'dealing' damage, even if it is set to a larger value, so we pass an
// empty damage delta.
DamageChanged(component, new DamageSpecifier());
DamageChanged(uid, component, new DamageSpecifier());
}
public void SetDamageModifierSetId(EntityUid uid, string damageModifierSetId, DamageableComponent? comp = null)
@@ -258,7 +258,7 @@ namespace Content.Shared.Damage
private void OnRejuvenate(EntityUid uid, DamageableComponent component, RejuvenateEvent args)
{
SetAllDamage(component, 0);
SetAllDamage(uid, component, 0);
}
private void DamageableHandleState(EntityUid uid, DamageableComponent component, ref ComponentHandleState args)
@@ -278,7 +278,7 @@ namespace Content.Shared.Damage
if (!delta.Empty)
{
component.Damage = newDamage;
DamageChanged(component, delta);
DamageChanged(uid, component, delta);
}
}
}

View File

@@ -6,7 +6,6 @@ using Content.Shared.Damage.Components;
using Content.Shared.Damage.Events;
using Content.Shared.Database;
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Shared.Rounding;
using Content.Shared.Stunnable;
@@ -24,12 +23,12 @@ namespace Content.Shared.Damage.Systems;
public sealed class StaminaSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
[Dependency] private readonly AlertsSystem _alerts = default!;
[Dependency] private readonly MetaDataSystem _metadata = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedStunSystem _stunSystem = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
private const string CollideFixture = "projectile";
@@ -150,21 +149,24 @@ public sealed class StaminaSystem : EntitySystem
var ev = new StaminaDamageOnHitAttemptEvent();
RaiseLocalEvent(uid, ref ev);
if (ev.Cancelled) return;
if (ev.Cancelled)
return;
args.HitSoundOverride = ev.HitSoundOverride;
var stamQuery = GetEntityQuery<StaminaComponent>();
var toHit = new List<StaminaComponent>();
var toHit = new List<(EntityUid Entity, StaminaComponent Component)>();
// Split stamina damage between all eligible targets.
foreach (var ent in args.HitEntities)
{
if (!stamQuery.TryGetComponent(ent, out var stam)) continue;
toHit.Add(stam);
if (!stamQuery.TryGetComponent(ent, out var stam))
continue;
toHit.Add((ent, stam));
}
var hitEvent = new StaminaMeleeHitEvent(toHit);
RaiseLocalEvent(uid, hitEvent, false);
RaiseLocalEvent(uid, hitEvent);
if (hitEvent.Handled)
return;
@@ -175,13 +177,13 @@ public sealed class StaminaSystem : EntitySystem
damage += hitEvent.FlatModifier;
foreach (var comp in toHit)
foreach (var (ent, comp) in toHit)
{
var oldDamage = comp.StaminaDamage;
TakeStaminaDamage(comp.Owner, damage / toHit.Count, comp, source:args.User, with:component.Owner);
TakeStaminaDamage(ent, damage / toHit.Count, comp, source:args.User, with:ent);
if (comp.StaminaDamage.Equals(oldDamage))
{
_popup.PopupEntity(Loc.GetString("stamina-resist"), comp.Owner, args.User);
_popup.PopupEntity(Loc.GetString("stamina-resist"), ent, args.User);
}
}
}
@@ -267,19 +269,20 @@ public sealed class StaminaSystem : EntitySystem
{
base.Update(frameTime);
if (!_timing.IsFirstTimePredicted) return;
if (!_timing.IsFirstTimePredicted)
return;
var metaQuery = GetEntityQuery<MetaDataComponent>();
var stamQuery = GetEntityQuery<StaminaComponent>();
var query = EntityQueryEnumerator<ActiveStaminaComponent>();
var curTime = _timing.CurTime;
foreach (var active in EntityQuery<ActiveStaminaComponent>())
while (query.MoveNext(out var uid, out _))
{
// Just in case we have active but not stamina we'll check and account for it.
if (!stamQuery.TryGetComponent(active.Owner, out var comp) ||
if (!stamQuery.TryGetComponent(uid, out var comp) ||
comp.StaminaDamage <= 0f && !comp.Critical)
{
RemComp<ActiveStaminaComponent>(active.Owner);
RemComp<ActiveStaminaComponent>(uid);
continue;
}
@@ -292,12 +295,12 @@ public sealed class StaminaSystem : EntitySystem
// We were in crit so come out of it and continue.
if (comp.Critical)
{
ExitStamCrit(active.Owner, comp);
ExitStamCrit(uid, comp);
continue;
}
comp.NextUpdate += TimeSpan.FromSeconds(1f);
TakeStaminaDamage(comp.Owner, -comp.Decay, comp);
TakeStaminaDamage(uid, -comp.Decay, comp);
Dirty(comp);
}
}
@@ -305,7 +308,10 @@ public sealed class StaminaSystem : EntitySystem
private void EnterStamCrit(EntityUid uid, StaminaComponent? component = null)
{
if (!Resolve(uid, ref component) ||
component.Critical) return;
component.Critical)
{
return;
}
// To make the difference between a stun and a stamcrit clear
// TODO: Mask?
@@ -326,7 +332,10 @@ public sealed class StaminaSystem : EntitySystem
private void ExitStamCrit(EntityUid uid, StaminaComponent? component = null)
{
if (!Resolve(uid, ref component) ||
!component.Critical) return;
!component.Critical)
{
return;
}
component.Critical = false;
component.StaminaDamage = 0f;