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
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();
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);
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);
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);
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();
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));
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);
// 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));
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);
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));
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));
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(() =>
{
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));
}
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)));
}
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)));
}
});
if (EntityManager.TryGetComponent(entity, out DamageableComponent? damageable))
{
- _damageableSystem.SetDamage(damageable, new DamageSpecifier());
+ _damageableSystem.SetDamage(entity, damageable, new DamageSpecifier());
}
return true;
{
if (old.Damage != null)
{
- _damageableSystem.SetDamage(damageable, old.Damage);
+ _damageableSystem.SetDamage(entity, damageable, old.Damage);
}
}
_mobThreshold.GetScaledDamage(uid, child, out var damage) &&
damage != null)
{
- _damageable.SetDamage(damageParent, damage);
+ _damageable.SetDamage(child, damageParent, damage);
}
if (proto.Inventory == PolymorphInventoryChange.Transfer)
_mobThreshold.GetScaledDamage(uid, parent, out var damage) &&
damage != null)
{
- _damageable.SetDamage(damageParent, damage);
+ _damageable.SetDamage(parent, damageParent, damage);
}
if (proto.Inventory == PolymorphInventoryChange.Transfer)
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");
}
}
else if (damageQuery.TryGetComponent(target, out var damageableComponent))
{
- _damageableSystem.SetAllDamage(damageableComponent, 200);
+ _damageableSystem.SetAllDamage(target, damageableComponent, 200);
}
}
}
//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);
/// <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.
/// </summary>
public float FlatModifier = 0;
- public StaminaMeleeHitEvent(List<StaminaComponent> hitList)
+ public StaminaMeleeHitEvent(List<(EntityUid Entity, StaminaComponent Component)> hitList)
{
HitList = hitList;
}
/// 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>
/// 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>
}
var ev = new DamageModifyEvent(damage);
- RaiseLocalEvent(uid.Value, ev, false);
+ RaiseLocalEvent(uid.Value, ev);
damage = ev.Damage;
if (damage.Empty)
if (!delta.Empty)
{
- DamageChanged(damageable, delta, interruptsDoAfters, origin);
+ DamageChanged(uid.Value, damageable, delta, interruptsDoAfters, origin);
}
return delta;
/// <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)
{
// 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)
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)
if (!delta.Empty)
{
component.Damage = newDamage;
- DamageChanged(component, delta);
+ DamageChanged(uid, component, delta);
}
}
}
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;
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";
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;
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);
}
}
}
{
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;
}
// 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);
}
}
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?
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;