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

@@ -193,9 +193,9 @@ namespace Content.IntegrationTests.Tests.Damageable
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.Zero));
// Test SetAll function
sDamageableSystem.SetAllDamage(sDamageableComponent, 10);
sDamageableSystem.SetAllDamage(sDamageableEntity, sDamageableComponent, 10);
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.New(10 * sDamageableComponent.Damage.DamageDict.Count())));
sDamageableSystem.SetAllDamage(sDamageableComponent, 0);
sDamageableSystem.SetAllDamage(sDamageableEntity, sDamageableComponent, 0);
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.Zero));
// Test 'wasted' healing

View File

@@ -39,7 +39,7 @@ namespace Content.IntegrationTests.Tests.Destructible
var coordinates = testMap.GridCoords;
sDestructibleEntity = sEntityManager.SpawnEntity(DestructibleDamageGroupEntityId, coordinates);
sDamageableComponent = IoCManager.Resolve<IEntityManager>().GetComponent<DamageableComponent>(sDestructibleEntity);
sDamageableComponent = sEntityManager.GetComponent<DamageableComponent>(sDestructibleEntity);
sTestThresholdListenerSystem = sEntitySystemManager.GetEntitySystem<TestDestructibleListenerSystem>();
sTestThresholdListenerSystem.ThresholdsReached.Clear();
@@ -125,7 +125,7 @@ namespace Content.IntegrationTests.Tests.Destructible
sTestThresholdListenerSystem.ThresholdsReached.Clear();
// Heal both classes of damage to 0
sDamageableSystem.SetAllDamage(sDamageableComponent, 0);
sDamageableSystem.SetAllDamage(sDestructibleEntity, sDamageableComponent, 0);
// No new thresholds reached, healing should not trigger it
Assert.IsEmpty(sTestThresholdListenerSystem.ThresholdsReached);
@@ -163,7 +163,7 @@ namespace Content.IntegrationTests.Tests.Destructible
threshold.TriggersOnce = true;
// Heal brute and burn back to 0
sDamageableSystem.SetAllDamage(sDamageableComponent, 0);
sDamageableSystem.SetAllDamage(sDestructibleEntity, sDamageableComponent, 0);
// No new thresholds reached from healing
Assert.IsEmpty(sTestThresholdListenerSystem.ThresholdsReached);

View File

@@ -30,6 +30,7 @@ namespace Content.IntegrationTests.Tests.Destructible
var sEntityManager = server.ResolveDependency<IEntityManager>();
var sPrototypeManager = server.ResolveDependency<IPrototypeManager>();
var sEntitySystemManager = server.ResolveDependency<IEntitySystemManager>();
var audio = sEntitySystemManager.GetEntitySystem<SharedAudioSystem>();
var testMap = await PoolManager.CreateTestMap(pairTracker);
@@ -44,8 +45,8 @@ namespace Content.IntegrationTests.Tests.Destructible
var coordinates = testMap.GridCoords;
sDestructibleEntity = sEntityManager.SpawnEntity(DestructibleEntityId, coordinates);
sDamageableComponent = IoCManager.Resolve<IEntityManager>().GetComponent<DamageableComponent>(sDestructibleEntity);
sDestructibleComponent = IoCManager.Resolve<IEntityManager>().GetComponent<DestructibleComponent>(sDestructibleEntity);
sDamageableComponent = sEntityManager.GetComponent<DamageableComponent>(sDestructibleEntity);
sDestructibleComponent = sEntityManager.GetComponent<DestructibleComponent>(sDestructibleEntity);
sTestThresholdListenerSystem = sEntitySystemManager.GetEntitySystem<TestDestructibleListenerSystem>();
sTestThresholdListenerSystem.ThresholdsReached.Clear();
@@ -102,9 +103,9 @@ namespace Content.IntegrationTests.Tests.Destructible
var actsThreshold = (DoActsBehavior) threshold.Behaviors[2];
Assert.That(actsThreshold.Acts, Is.EqualTo(ThresholdActs.Breakage));
Assert.That(soundThreshold.Sound.GetSound(), Is.EqualTo("/Audio/Effects/woodhit.ogg"));
Assert.That(audio.GetSound(soundThreshold.Sound), Is.EqualTo("/Audio/Effects/woodhit.ogg"));
Assert.That(spawnThreshold.Spawn, Is.Not.Null);
Assert.That(spawnThreshold.Spawn.Count, Is.EqualTo(1));
Assert.That(spawnThreshold.Spawn, Has.Count.EqualTo(1));
Assert.That(spawnThreshold.Spawn.Single().Key, Is.EqualTo(SpawnedEntityId));
Assert.That(spawnThreshold.Spawn.Single().Value.Min, Is.EqualTo(1));
Assert.That(spawnThreshold.Spawn.Single().Value.Max, Is.EqualTo(1));
@@ -120,7 +121,7 @@ namespace Content.IntegrationTests.Tests.Destructible
Assert.IsEmpty(sTestThresholdListenerSystem.ThresholdsReached);
// Set damage to 0
sDamageableSystem.SetAllDamage(sDamageableComponent, 0);
sDamageableSystem.SetAllDamage(sDestructibleEntity, sDamageableComponent, 0);
// Damage for 100, up to 100
sDamageableSystem.TryChangeDamage(sDestructibleEntity, bluntDamage*10, true);
@@ -166,7 +167,7 @@ namespace Content.IntegrationTests.Tests.Destructible
// Check that it matches the YAML prototype
Assert.That(actsThreshold.Acts, Is.EqualTo(ThresholdActs.Breakage));
Assert.That(soundThreshold.Sound.GetSound(), Is.EqualTo("/Audio/Effects/woodhit.ogg"));
Assert.That(audio.GetSound(soundThreshold.Sound), Is.EqualTo("/Audio/Effects/woodhit.ogg"));
Assert.That(spawnThreshold.Spawn, Is.Not.Null);
Assert.That(spawnThreshold.Spawn.Count, Is.EqualTo(1));
Assert.That(spawnThreshold.Spawn.Single().Key, Is.EqualTo(SpawnedEntityId));
@@ -179,7 +180,7 @@ namespace Content.IntegrationTests.Tests.Destructible
sTestThresholdListenerSystem.ThresholdsReached.Clear();
// Heal all damage
sDamageableSystem.SetAllDamage(sDamageableComponent, 0);
sDamageableSystem.SetAllDamage(sDestructibleEntity, sDamageableComponent, 0);
// Damage up to 50
sDamageableSystem.TryChangeDamage(sDestructibleEntity, bluntDamage*5, true);
@@ -219,7 +220,7 @@ namespace Content.IntegrationTests.Tests.Destructible
Assert.That(actsThreshold.Acts, Is.EqualTo(ThresholdActs.Breakage));
Assert.That(soundThreshold.Sound.GetSound(), Is.EqualTo("/Audio/Effects/woodhit.ogg"));
Assert.That(spawnThreshold.Spawn, Is.Not.Null);
Assert.That(spawnThreshold.Spawn.Count, Is.EqualTo(1));
Assert.That(spawnThreshold.Spawn, Has.Count.EqualTo(1));
Assert.That(spawnThreshold.Spawn.Single().Key, Is.EqualTo(SpawnedEntityId));
Assert.That(spawnThreshold.Spawn.Single().Value.Min, Is.EqualTo(1));
Assert.That(spawnThreshold.Spawn.Single().Value.Max, Is.EqualTo(1));
@@ -230,7 +231,7 @@ namespace Content.IntegrationTests.Tests.Destructible
sTestThresholdListenerSystem.ThresholdsReached.Clear();
// Heal the entity completely
sDamageableSystem.SetAllDamage(sDamageableComponent, 0);
sDamageableSystem.SetAllDamage(sDestructibleEntity, sDamageableComponent, 0);
// Check that the entity has 0 damage
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.Zero));

View File

@@ -24,6 +24,7 @@ namespace Content.IntegrationTests.Tests
var mapManager = server.ResolveDependency<IMapManager>();
var sEntities = server.ResolveDependency<IEntityManager>();
var mapLoader = sEntities.System<MapLoaderSystem>();
var xformSystem = sEntities.EntitySysManager.GetEntitySystem<SharedTransformSystem>();
var resManager = server.ResolveDependency<IResourceManager>();
await server.WaitPost(() =>
@@ -36,13 +37,13 @@ namespace Content.IntegrationTests.Tests
{
var mapGrid = mapManager.CreateGrid(mapId);
var mapGridEnt = mapGrid.Owner;
sEntities.GetComponent<TransformComponent>(mapGridEnt).WorldPosition = new Vector2(10, 10);
xformSystem.SetWorldPosition(mapGridEnt, new Vector2(10, 10));
mapGrid.SetTile(new Vector2i(0,0), new Tile(1, (TileRenderFlag)1, 255));
}
{
var mapGrid = mapManager.CreateGrid(mapId);
var mapGridEnt = mapGrid.Owner;
sEntities.GetComponent<TransformComponent>(mapGridEnt).WorldPosition = new Vector2(-8, -8);
xformSystem.SetWorldPosition(mapGridEnt, new Vector2(-8, -8));
mapGrid.SetTile(new Vector2i(0, 0), new Tile(2, (TileRenderFlag)1, 254));
}
@@ -67,7 +68,7 @@ namespace Content.IntegrationTests.Tests
return;
}
Assert.That(gridXform.WorldPosition, Is.EqualTo(new Vector2(10, 10)));
Assert.That(xformSystem.GetWorldPosition(gridXform), Is.EqualTo(new Vector2(10, 10)));
Assert.That(mapGrid.GetTileRef(new Vector2i(0, 0)).Tile, Is.EqualTo(new Tile(1, (TileRenderFlag)1, 255)));
}
@@ -79,7 +80,7 @@ namespace Content.IntegrationTests.Tests
return;
}
Assert.That(gridXform.WorldPosition, Is.EqualTo(new Vector2(-8, -8)));
Assert.That(xformSystem.GetWorldPosition(gridXform), Is.EqualTo(new Vector2(-8, -8)));
Assert.That(mapGrid.GetTileRef(new Vector2i(0, 0)).Tile, Is.EqualTo(new Tile(2, (TileRenderFlag)1, 254)));
}
});

View File

@@ -39,7 +39,7 @@ namespace Content.Server.Damage.Systems
if (EntityManager.TryGetComponent(entity, out DamageableComponent? damageable))
{
_damageableSystem.SetDamage(damageable, new DamageSpecifier());
_damageableSystem.SetDamage(entity, damageable, new DamageSpecifier());
}
return true;
@@ -66,7 +66,7 @@ namespace Content.Server.Damage.Systems
{
if (old.Damage != null)
{
_damageableSystem.SetDamage(damageable, old.Damage);
_damageableSystem.SetDamage(entity, damageable, old.Damage);
}
}

View File

@@ -155,7 +155,7 @@ namespace Content.Server.Polymorph.Systems
_mobThreshold.GetScaledDamage(uid, child, out var damage) &&
damage != null)
{
_damageable.SetDamage(damageParent, damage);
_damageable.SetDamage(child, damageParent, damage);
}
if (proto.Inventory == PolymorphInventoryChange.Transfer)
@@ -244,7 +244,7 @@ namespace Content.Server.Polymorph.Systems
_mobThreshold.GetScaledDamage(uid, parent, out var damage) &&
damage != null)
{
_damageable.SetDamage(damageParent, damage);
_damageable.SetDamage(parent, damageParent, damage);
}
if (proto.Inventory == PolymorphInventoryChange.Transfer)

View File

@@ -34,7 +34,7 @@ namespace Content.Server.Repairable
else
{
// Repair all damage
_damageableSystem.SetAllDamage(damageable, 0);
_damageableSystem.SetAllDamage(uid, damageable, 0);
_adminLogger.Add(LogType.Healed, $"{ToPrettyString(args.User):user} repaired {ToPrettyString(uid):target} back to full health");
}

View File

@@ -62,7 +62,7 @@ public sealed class SalvageMobRestrictionsSystem : EntitySystem
}
else if (damageQuery.TryGetComponent(target, out var damageableComponent))
{
_damageableSystem.SetAllDamage(damageableComponent, 200);
_damageableSystem.SetAllDamage(target, damageableComponent, 200);
}
}
}

View File

@@ -165,7 +165,7 @@ namespace Content.Server.Zombies
//Heals the zombie from all the damage it took while human
if (TryComp<DamageableComponent>(target, out var damageablecomp))
_damageable.SetAllDamage(damageablecomp, 0);
_damageable.SetAllDamage(target, damageablecomp, 0);
//gives it the funny "Zombie ___" name.
var meta = MetaData(target);

View File

@@ -12,7 +12,7 @@ public sealed class StaminaMeleeHitEvent : HandledEntityEventArgs
/// <summary>
/// List of hit stamina components.
/// </summary>
public List<StaminaComponent> HitList;
public List<(EntityUid Entity, StaminaComponent Component)> HitList;
/// <summary>
/// The multiplier. Generally, try to use *= or /= instead of overwriting.
@@ -24,7 +24,7 @@ public sealed class StaminaMeleeHitEvent : HandledEntityEventArgs
/// </summary>
public float FlatModifier = 0;
public StaminaMeleeHitEvent(List<StaminaComponent> hitList)
public StaminaMeleeHitEvent(List<(EntityUid Entity, StaminaComponent Component)> hitList)
{
HitList = hitList;
}

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;