Files
crystall-punk-14/Content.Shared/_CP14/DayCycle/CP14SharedDayCycleSystem.cs
Ed b647583b7b Silva species gameplay difference (#701)
* plant growth spell, silva photosyntesis

* playable species guidebook

* fixes
2025-01-06 03:31:59 +03:00

56 lines
1.9 KiB
C#

using Content.Shared._CP14.DayCycle.Components;
using Content.Shared._CP14.DayCycle.Prototypes;
using Content.Shared.Maps;
using Content.Shared.Weather;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Prototypes;
namespace Content.Shared._CP14.DayCycle;
public abstract class CP14SharedDayCycleSystem : EntitySystem
{
private static readonly ProtoId<CP14DayCyclePeriodPrototype> DayPeriod = "Day";
[Dependency] private readonly SharedMapSystem _maps = default!;
[Dependency] private readonly ITileDefinitionManager _tileDefManager = default!;
[Dependency] private readonly SharedWeatherSystem _weather = default!;
private EntityQuery<MapGridComponent> _mapGridQuery;
public override void Initialize()
{
base.Initialize();
_mapGridQuery = GetEntityQuery<MapGridComponent>();
}
/// <summary>
/// Checks to see if the specified entity is on the map where it's daytime.
/// </summary>
/// <param name="target">An entity being tested to see if it is in daylight</param>
/// <param name="checkRoof">Checks if the tile covers the weather (the only "roof" factor at the moment)</param>
public bool TryDaylightThere(EntityUid target, bool checkRoof = true)
{
var xform = Transform(target);
if (!TryComp<CP14DayCycleComponent>(xform.MapUid, out var dayCycle))
return false;
var day = dayCycle.CurrentPeriod == DayPeriod;
if (!checkRoof || !TryComp<MapGridComponent>(xform.GridUid, out var mapGrid))
return day;
var grid = xform.GridUid;
if (grid is null)
return day;
if (!_mapGridQuery.TryComp(grid, out var gridComp))
return day;
if (!_weather.CanWeatherAffect(grid.Value, gridComp, _maps.GetTileRef(xform.GridUid.Value, mapGrid, xform.Coordinates)))
return false;
return day;
}
}