Files
tbd-station-14/Content.Server/Spider/SpiderSystem.cs
TemporalOroboros d4876be6f0 Kills TurfHelpers (#37939)
* Create TurfSystem equivalent for and obsolete TurfHelpers.GetTileRef

* Fix EntitySystem uses of TurfHelpers.GetTileRef

* Fix EntitySystem uses of TurfHelpers.TryGetTileRef

* Fix construction condition uses of TurfHelpers.GetTileRef

* Fix last use of TurfHelpers.IsBlockedTurf

* Create TurfSystem equivalent to and obsolete TurfHelpers.GetContentTileDefinition

* Fix uses of TurfHelpers.GetContentTileDefinition(TileRef)

* Fix uses of TurfHelpers.GetContentTileDefinition(Tile)

* Create TurfSystem equivalent to and obsolete TurfHelpers.IsSpace

* Fix EntitySystem uses of TurfHelpers.IsSpace(Tile)

* Fix EntitySystem uses of TurfHelpers.IsSpace(TileRef)

* Fix remaining uses of TurfHelpers.IsSpace

* Fix uses of TurfHelpers.GetEntitiesInTile

* Delete TurfHelpers.cs

* Add GetEntitiesInTile lookup methods

* Convert some GetEntitiesInTile methods to LookupSystem extension methods

* Use new GetEntitiesInTile methods

* Recycle spiderweb hashset

* Recycle floor tile hashset
2025-06-21 11:23:19 -04:00

87 lines
2.4 KiB
C#

using System.Linq;
using Content.Server.Popups;
using Content.Shared.Spider;
using Content.Shared.Maps;
using Robust.Server.GameObjects;
using Robust.Shared.Map;
namespace Content.Server.Spider;
public sealed class SpiderSystem : SharedSpiderSystem
{
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly TurfSystem _turf = default!;
/// <summary>
/// A recycled hashset used to check turfs for spiderwebs.
/// </summary>
private readonly HashSet<EntityUid> _webs = [];
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SpiderComponent, SpiderWebActionEvent>(OnSpawnNet);
}
private void OnSpawnNet(EntityUid uid, SpiderComponent component, SpiderWebActionEvent args)
{
if (args.Handled)
return;
var transform = Transform(uid);
if (transform.GridUid == null)
{
_popup.PopupEntity(Loc.GetString("spider-web-action-nogrid"), args.Performer, args.Performer);
return;
}
var coords = transform.Coordinates;
// TODO generic way to get certain coordinates
var result = false;
// Spawn web in center
if (!IsTileBlockedByWeb(coords))
{
Spawn(component.WebPrototype, coords);
result = true;
}
// Spawn web in other directions
for (var i = 0; i < 4; i++)
{
var direction = (DirectionFlag) (1 << i);
coords = transform.Coordinates.Offset(direction.AsDir().ToVec());
if (!IsTileBlockedByWeb(coords))
{
Spawn(component.WebPrototype, coords);
result = true;
}
}
if (result)
{
_popup.PopupEntity(Loc.GetString("spider-web-action-success"), args.Performer, args.Performer);
args.Handled = true;
}
else
_popup.PopupEntity(Loc.GetString("spider-web-action-fail"), args.Performer, args.Performer);
}
private bool IsTileBlockedByWeb(EntityCoordinates coords)
{
_webs.Clear();
_turf.GetEntitiesInTile(coords, _webs);
foreach (var entity in _webs)
{
if (HasComp<SpiderWebObjectComponent>(entity))
return true;
}
return false;
}
}