Skip to content

Commit

Permalink
Merge branch 'master' into upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
CrimeMoot authored Sep 13, 2024
2 parents 32ce44c + c6bd43b commit efdc49b
Show file tree
Hide file tree
Showing 586 changed files with 2,074 additions and 195 deletions.
36 changes: 31 additions & 5 deletions Content.Server/Access/Systems/IdCardSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public sealed class IdCardSystem : SharedIdCardSystem
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<IdCardComponent, BeingMicrowavedEvent>(OnMicrowaved);
}

Expand All @@ -45,16 +44,15 @@ private void OnMicrowaved(EntityUid uid, IdCardComponent component, BeingMicrowa
{
_popupSystem.PopupCoordinates(Loc.GetString("id-card-component-microwave-burnt", ("id", uid)),
transformComponent.Coordinates, PopupType.Medium);
EntityManager.SpawnEntity("FoodBadRecipe",
transformComponent.Coordinates);
EntityManager.SpawnEntity("FoodBadRecipe", transformComponent.Coordinates);
}
_adminLogger.Add(LogType.Action, LogImpact.Medium,
$"{ToPrettyString(args.Microwave)} burnt {ToPrettyString(uid):entity}");
EntityManager.QueueDeleteEntity(uid);
return;
}

//Explode if the microwave can't handle it
// Explode if the microwave can't handle it
if (!micro.CanMicrowaveIdsSafely)
{
_microwave.Explode((args.Microwave, micro));
Expand Down Expand Up @@ -84,8 +82,36 @@ private void OnMicrowaved(EntityUid uid, IdCardComponent component, BeingMicrowa
Dirty(uid, access);

_adminLogger.Add(LogType.Action, LogImpact.Medium,
$"{ToPrettyString(args.Microwave)} added {random.ID} access to {ToPrettyString(uid):entity}");
$"{ToPrettyString(args.Microwave)} added {random.ID} access to {ToPrettyString(uid):entity}");
}
}

/// <summary>
/// Attempts to change the color of an ID card.
/// Returns true/false.
/// </summary>
/// <remarks>
/// If provided with a player's EntityUid, logs the change to the admin logs.
/// </remarks>
public bool TryChangeColor(EntityUid uid, Color? color, IdCardComponent? id = null, EntityUid? player = null)
{
if (!Resolve(uid, ref id))
return false;

if (color is null)
return false;

if (id.JobColor == color.Value)
return true;

id.JobColor = color.Value;
Dirty(id);

Check failure on line 108 in Content.Server/Access/Systems/IdCardSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type arguments for method 'EntitySystem.Dirty<T>(Entity<T>, MetaDataComponent?)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

Check failure on line 108 in Content.Server/Access/Systems/IdCardSystem.cs

View workflow job for this annotation

GitHub Actions / Test Packaging

The type arguments for method 'EntitySystem.Dirty<T>(Entity<T>, MetaDataComponent?)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

Check failure on line 108 in Content.Server/Access/Systems/IdCardSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type arguments for method 'EntitySystem.Dirty<T>(Entity<T>, MetaDataComponent?)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

Check failure on line 108 in Content.Server/Access/Systems/IdCardSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type arguments for method 'EntitySystem.Dirty<T>(Entity<T>, MetaDataComponent?)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

Check failure on line 108 in Content.Server/Access/Systems/IdCardSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type arguments for method 'EntitySystem.Dirty<T>(Entity<T>, MetaDataComponent?)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

Check failure on line 108 in Content.Server/Access/Systems/IdCardSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The type arguments for method 'EntitySystem.Dirty<T>(Entity<T>, MetaDataComponent?)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

Check failure on line 108 in Content.Server/Access/Systems/IdCardSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type arguments for method 'EntitySystem.Dirty<T>(Entity<T>, MetaDataComponent?)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

Check failure on line 108 in Content.Server/Access/Systems/IdCardSystem.cs

View workflow job for this annotation

GitHub Actions / YAML Linter

The type arguments for method 'EntitySystem.Dirty<T>(Entity<T>, MetaDataComponent?)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

if (player != null)
{
_adminLogger.Add(LogType.Identity, LogImpact.Low,
$"{ToPrettyString(player.Value):player} changed the color of {ToPrettyString(uid):entity} to {color} ");
}
return true;
}
}
17 changes: 17 additions & 0 deletions Content.Server/Access/Systems/PresetIdCardSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Content.Server.Station.Systems;
using Content.Shared.Access.Systems;
using Content.Shared.Roles;
using Content.Shared.Roles.Jobs;
using Content.Shared.StatusIcon;
using Robust.Shared.Prototypes;

Expand All @@ -15,6 +16,7 @@ public sealed class PresetIdCardSystem : EntitySystem
[Dependency] private readonly IdCardSystem _cardSystem = default!;
[Dependency] private readonly SharedAccessSystem _accessSystem = default!;
[Dependency] private readonly StationSystem _stationSystem = default!;
[Dependency] private readonly SharedJobSystem _jobSystem = default!;

public override void Initialize()
{
Expand All @@ -38,6 +40,7 @@ private void PlayerJobsAssigned(RulePlayerJobsAssignedEvent ev)

SetupIdAccess(uid, card, true);
SetupIdName(uid, card);
SetupIdColor(uid, card);
}
}

Expand Down Expand Up @@ -66,6 +69,20 @@ private void SetupIdName(EntityUid uid, PresetIdCardComponent id)
_cardSystem.TryChangeFullName(uid, id.IdName);
}

private void SetupIdColor(EntityUid uid, PresetIdCardComponent id)
{
if (id.JobName is not null)
{
var color = id.JobName is null ? null
: _prototypeManager.TryIndex(id.JobName, out JobPrototype? job) && job.Color is not null ? job.Color
: job is not null && _jobSystem.TryGetDepartment(job.ID, out var department) ? department.Color
: null;

if (color is not null)
_cardSystem.TryChangeColor(uid, color);
}
}

private void SetupIdAccess(EntityUid uid, PresetIdCardComponent id, bool extended)
{
if (id.JobName == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Robust.Shared.Map;

namespace Content.Server.Footprints.Components;

[RegisterComponent]
public sealed partial class CanLeaveFootprintsComponent : Component
{
/// <summary>
/// Where the last footprint was.
/// </summary>
[ViewVariables]
public MapCoordinates LastFootstep;

/// <summary>
/// How many footprints left to leave behind the entity.
/// </summary>
[ViewVariables]
public uint FootstepsLeft = 1;

/// <summary>
/// If non null represets if the decal is either the alt or normal decal.
/// Null represents always use normal.
/// </summary>
[ViewVariables]
public bool? UseAlternative;

[ViewVariables]
public Color Color = Color.White;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Content.Server.Footprints.Components;

[RegisterComponent]
public sealed partial class GivesFootprintsComponent : Component
{
}
29 changes: 29 additions & 0 deletions Content.Server/Footprints/Components/LeavesFootprintsComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Content.Server.Footprints.Components;

[RegisterComponent]
public sealed partial class LeavesFootprintsComponent : Component
{
/// <summary>
/// How many footsteps to leave behind the player once they step on something which gives it
/// </summary>
[DataField]
public uint MaxFootsteps = 8;

/// <summary>
/// How far should the player have to walk until we leave a footprint
/// </summary>
[DataField]
public float Distance = 0.8f;

/// <summary>
/// What decal to leave behind when the entity moves.
/// </summary>
[DataField]
public string FootprintDecal = "FootLeft";

/// <summary>
/// If set with will alternate between this decal and the regular decal
/// </summary>
[DataField]
public string FootprintDecalAlternative = "FootRight";
}
156 changes: 156 additions & 0 deletions Content.Server/Footprints/Systems/LeaveFootprintSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
using Content.Server.Decals;
using Content.Server.Footprints.Components;
using Content.Shared.Clothing.Components;
using Content.Shared.Decals;
using Content.Shared.Inventory;
using Robust.Shared.Containers;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
using System.Numerics;

namespace Content.Server.Footprint.Systems;


public sealed partial class FootprintSystem : EntitySystem
{

[Dependency] private readonly SharedContainerSystem _container = default!;
[Dependency] private readonly DecalSystem _decals = default!;
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly SharedMapSystem _map = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;

const float MaxAlpha = 0.5f;
const float MinAlpha = 0.2f;

const float DeltaAlpha = MaxAlpha - MinAlpha;

const string ShoeSlot = "shoes";

public override void Update(float frametime)
{
var query = EntityQueryEnumerator<CanLeaveFootprintsComponent, TransformComponent>();

while (query.MoveNext(out var uid, out var currentFootprintComp, out var transform))
{
if (!CanLeaveFootprints(uid, out var messMaker) ||
!TryComp<LeavesFootprintsComponent>(messMaker, out var footprintComp))
continue;

var posUid = messMaker;
var angle = transform.LocalRotation;

if (HasComp<ClothingComponent>(messMaker) &&
_container.TryGetContainingContainer((messMaker, null, null), out var container) &&
TryComp<TransformComponent>(container.Owner, out var xform))
{
posUid = container.Owner;
angle = xform.LocalRotation;
}

var newPos = _transform.GetMapCoordinates(posUid);
var oldPos = currentFootprintComp.LastFootstep;

if (newPos == MapCoordinates.Nullspace)
continue;

if (newPos.MapId != oldPos.MapId)
{
DoFootprint(messMaker, currentFootprintComp, footprintComp, newPos, angle);
return;
}

var delta = Vector2.Distance(newPos.Position, oldPos.Position);

if (delta < footprintComp.Distance)
continue;

DoFootprint(messMaker, currentFootprintComp, footprintComp, newPos, angle);
}
}

private void DoFootprint(EntityUid uid, CanLeaveFootprintsComponent currentFootprintComp, LeavesFootprintsComponent footprintComp, MapCoordinates pos, Angle angle)
{
var decal = footprintComp.FootprintDecal;

if (currentFootprintComp.UseAlternative != null)
{
if (currentFootprintComp.UseAlternative.Value)
decal = footprintComp.FootprintDecalAlternative;

currentFootprintComp.UseAlternative ^= true;
}

if (!_prototypeManager.TryIndex<DecalPrototype>(decal, out var footprintDecal))
{
RemComp<CanLeaveFootprintsComponent>(uid);
return;
}

if (!_mapManager.TryFindGridAt(pos, out var gridUid, out var grid))
return;

var color = currentFootprintComp.Color;

float onePiece = DeltaAlpha / (footprintComp.MaxFootsteps); //IS REAL!!
color = color.WithAlpha(MinAlpha + (onePiece * currentFootprintComp.FootstepsLeft));

var coords = new EntityCoordinates(gridUid, _map.WorldToLocal(gridUid, grid, pos.Position));

_decals.TryAddDecal(footprintDecal.ID, coords, out _, color, angle, cleanable: true);

currentFootprintComp.FootstepsLeft -= 1;

if (currentFootprintComp.FootstepsLeft <= 0)
{
RemComp<CanLeaveFootprintsComponent>(uid);
return;
}

currentFootprintComp.LastFootstep = pos;
currentFootprintComp.Color = color;
}

private bool CanLeaveFootprints(EntityUid uid, out EntityUid messMaker)
{
messMaker = EntityUid.Invalid;

if (_inventory.TryGetSlotEntity(uid, ShoeSlot, out var shoe) &&
EntityManager.HasComponent<LeavesFootprintsComponent>(shoe)) // check if their shoes have it too
{
messMaker = shoe.Value;
}
else if (EntityManager.HasComponent<LeavesFootprintsComponent>(uid))
{
if (shoe != null)
RemComp<CanLeaveFootprintsComponent>(shoe.Value);

messMaker = uid;
}
else
{
CleanupFootprintComp(uid, shoe);
return false;
}

if (messMaker == EntityUid.Invalid ||
!HasComp<LeavesFootprintsComponent>(messMaker))
{
CleanupFootprintComp(uid, shoe);
return false;
}

return true;
}

private void CleanupFootprintComp(EntityUid player, EntityUid? shoe)
{
RemComp<CanLeaveFootprintsComponent>(player);

if (shoe != null)
RemComp<CanLeaveFootprintsComponent>(shoe.Value);
}
}
52 changes: 52 additions & 0 deletions Content.Server/Footprints/Systems/UpdateFootprintsSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Content.Server.Footprints.Components;
using Content.Shared.Fluids;
using Robust.Shared.Physics.Events;
using Robust.Shared.Random;

namespace Content.Server.Footprint.Systems;

public sealed partial class FootprintSystem : EntitySystem
{
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly IRobustRandom _random = default!;

/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<GivesFootprintsComponent, EndCollideEvent>(OnStep);
SubscribeLocalEvent<CanLeaveFootprintsComponent, ComponentInit>(OnInit);
}

private void OnInit(EntityUid uid, CanLeaveFootprintsComponent component, ComponentInit args)
{
if (!TryComp<LeavesFootprintsComponent>(uid, out var footprintComp))
{
RemComp<CanLeaveFootprintsComponent>(uid);
return;
}

if (footprintComp.FootprintDecalAlternative != null)
component.UseAlternative = _random.Prob(0.5f);
}

private void OnStep(EntityUid uid, GivesFootprintsComponent component, ref EndCollideEvent args)
{

if (!CanLeaveFootprints(args.OtherEntity, out var messMaker) ||
!TryComp<LeavesFootprintsComponent>(messMaker, out var footprintComp))
return;

var playerFootprintComp = EnsureComp<CanLeaveFootprintsComponent>(messMaker);

var color = playerFootprintComp.Color;

if (_appearance.TryGetData<Color>(uid, PuddleVisuals.SolutionColor, out color))
{
color *= playerFootprintComp.Color;
}

playerFootprintComp.LastFootstep = _transform.GetMapCoordinates(args.OtherEntity);
playerFootprintComp.FootstepsLeft = footprintComp.MaxFootsteps;
playerFootprintComp.Color = color;
}
}
Loading

0 comments on commit efdc49b

Please sign in to comment.