Maint ambience tweaks (#16917)

This commit is contained in:
metalgearsloth
2023-05-29 14:19:00 +10:00
committed by GitHub
parent d5a24758b2
commit 42b4109bbb
3 changed files with 33 additions and 9 deletions

View File

@@ -55,6 +55,11 @@ public sealed class NearbyEntitiesRule : RulesRule
public sealed class NearbyTilesPercentRule : RulesRule public sealed class NearbyTilesPercentRule : RulesRule
{ {
/// <summary>
/// If there are anchored entities on the tile do we ignore the tile.
/// </summary>
[DataField("anchored")] public bool Anchored;
[DataField("percent", required: true)] [DataField("percent", required: true)]
public float Percent; public float Percent;
@@ -120,6 +125,12 @@ public sealed class NearbyAccessRule : RulesRule
public sealed class NearbyComponentsRule : RulesRule public sealed class NearbyComponentsRule : RulesRule
{ {
/// <summary>
/// Does the entity need to be anchored.
/// </summary>
[DataField("anchored")]
public bool Anchored;
[DataField("count")] public int Count; [DataField("count")] public int Count;
[DataField("components", required: true)] [DataField("components", required: true)]

View File

@@ -94,7 +94,9 @@ public sealed class RulesSystem : EntitySystem
} }
case NearbyComponentsRule nearbyComps: case NearbyComponentsRule nearbyComps:
{ {
if (!TryComp<TransformComponent>(uid, out var xform) || var xformQuery = GetEntityQuery<TransformComponent>();
if (!xformQuery.TryGetComponent(uid, out var xform) ||
xform.MapUid == null) xform.MapUid == null)
{ {
return false; return false;
@@ -104,20 +106,26 @@ public sealed class RulesSystem : EntitySystem
var worldPos = _transform.GetWorldPosition(xform); var worldPos = _transform.GetWorldPosition(xform);
var count = 0; 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 // 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)) worldPos, nearbyComps.Range))
{ {
if (nearbyComps.Anchored &&
(!xformQuery.TryGetComponent(comp.Owner, out var compXform) || !compXform.Anchored))
{
continue;
}
count++; count++;
if (count >= nearbyComps.Count) if (count < nearbyComps.Count)
{ continue;
found = true; found = true;
break; break;
} }
}
if (found) if (found)
break; break;
@@ -178,6 +186,9 @@ public sealed class RulesSystem : EntitySystem
if (!tiles.Tiles.Contains(_tileDef[tile.Tile.TypeId].ID)) if (!tiles.Tiles.Contains(_tileDef[tile.Tile.TypeId].ID))
continue; continue;
if (tiles.Anchored && grid.GetAnchoredEntitiesEnumerator(tile.GridIndices).MoveNext(out _))
continue;
matchingTileCount++; matchingTileCount++;
} }

View File

@@ -225,10 +225,11 @@
id: NearMaintenance id: NearMaintenance
rules: rules:
- !type:NearbyTilesPercentRule - !type:NearbyTilesPercentRule
anchored: false
percent: 0.25 percent: 0.25
tiles: tiles:
- Plating - Plating
range: 3 range: 2
- type: rules - type: rules
id: NearMedical id: NearMedical
@@ -243,6 +244,7 @@
id: NearPrayable id: NearPrayable
rules: rules:
- !type:NearbyComponentsRule - !type:NearbyComponentsRule
anchored: true
components: components:
- type: Prayable - type: Prayable
range: 5 range: 5