diff --git a/Content.Shared/Random/RulesPrototype.cs b/Content.Shared/Random/RulesPrototype.cs index a785447bec..cfa78ecdb5 100644 --- a/Content.Shared/Random/RulesPrototype.cs +++ b/Content.Shared/Random/RulesPrototype.cs @@ -55,6 +55,11 @@ public sealed class NearbyEntitiesRule : RulesRule public sealed class NearbyTilesPercentRule : RulesRule { + /// + /// If there are anchored entities on the tile do we ignore the tile. + /// + [DataField("anchored")] public bool Anchored; + [DataField("percent", required: true)] public float Percent; @@ -120,6 +125,12 @@ public sealed class NearbyAccessRule : RulesRule public sealed class NearbyComponentsRule : RulesRule { + /// + /// Does the entity need to be anchored. + /// + [DataField("anchored")] + public bool Anchored; + [DataField("count")] public int Count; [DataField("components", required: true)] diff --git a/Content.Shared/Random/RulesSystem.cs b/Content.Shared/Random/RulesSystem.cs index 5fb2de28c1..768aedf326 100644 --- a/Content.Shared/Random/RulesSystem.cs +++ b/Content.Shared/Random/RulesSystem.cs @@ -94,7 +94,9 @@ public sealed class RulesSystem : EntitySystem } case NearbyComponentsRule nearbyComps: { - if (!TryComp(uid, out var xform) || + var xformQuery = GetEntityQuery(); + + if (!xformQuery.TryGetComponent(uid, out var xform) || xform.MapUid == null) { return false; @@ -104,19 +106,25 @@ public sealed class RulesSystem : EntitySystem var worldPos = _transform.GetWorldPosition(xform); var count = 0; - foreach (var comp in nearbyComps.Components.Values) + foreach (var compType in nearbyComps.Components.Values) { // TODO: Update this when we get the callback version - foreach (var _ in _lookup.GetComponentsInRange(comp.Component.GetType(), xform.MapID, + foreach (var comp in _lookup.GetComponentsInRange(compType.Component.GetType(), xform.MapID, worldPos, nearbyComps.Range)) { + if (nearbyComps.Anchored && + (!xformQuery.TryGetComponent(comp.Owner, out var compXform) || !compXform.Anchored)) + { + continue; + } + count++; - if (count >= nearbyComps.Count) - { - found = true; - break; - } + if (count < nearbyComps.Count) + continue; + + found = true; + break; } if (found) @@ -178,6 +186,9 @@ public sealed class RulesSystem : EntitySystem if (!tiles.Tiles.Contains(_tileDef[tile.Tile.TypeId].ID)) continue; + if (tiles.Anchored && grid.GetAnchoredEntitiesEnumerator(tile.GridIndices).MoveNext(out _)) + continue; + matchingTileCount++; } diff --git a/Resources/Prototypes/audio.yml b/Resources/Prototypes/audio.yml index d3a96e2764..93f3a5f3da 100644 --- a/Resources/Prototypes/audio.yml +++ b/Resources/Prototypes/audio.yml @@ -225,10 +225,11 @@ id: NearMaintenance rules: - !type:NearbyTilesPercentRule + anchored: false percent: 0.25 tiles: - Plating - range: 3 + range: 2 - type: rules id: NearMedical @@ -243,6 +244,7 @@ id: NearPrayable rules: - !type:NearbyComponentsRule + anchored: true components: - type: Prayable range: 5