forked from Rxup/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
586 changed files
with
2,074 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
Content.Server/Footprints/Components/CanLeaveFootprintsComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
6 changes: 6 additions & 0 deletions
6
Content.Server/Footprints/Components/GivesFootprintsComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
29
Content.Server/Footprints/Components/LeavesFootprintsComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
156
Content.Server/Footprints/Systems/LeaveFootprintSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
52
Content.Server/Footprints/Systems/UpdateFootprintsSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.