Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mucin speed boost now only affects Gastropoids #228

Merged
merged 4 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions Content.Server/Chemistry/TileReactions/EnsureTileReaction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Content.Server.Fluids.EntitySystems;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reaction;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Content.Shared.Tag;
using JetBrains.Annotations;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;

namespace Content.Server.Chemistry.TileReactions
{
[UsedImplicitly]
[DataDefinition]
public sealed partial class EnsureTileReaction : ITileReaction
{
[DataField, ViewVariables]
public ComponentRegistry Components = new();

[DataField, ViewVariables]
public HashSet<ProtoId<TagPrototype>> Tags = new();

[DataField, ViewVariables]
public bool Override = false;

public FixedPoint2 TileReact(TileRef tile,
ReagentPrototype reagent,
FixedPoint2 reactVolume,
IEntityManager entityManager,
List<ReagentData>? data)
{
if (reactVolume < 5)
return FixedPoint2.Zero;

if (entityManager.EntitySysManager.GetEntitySystem<PuddleSystem>()
.TrySpillAt(tile, new Solution(reagent.ID, reactVolume, data), out var puddleUid, false, false))
{
entityManager.AddComponents(puddleUid, Components, Override);
entityManager.EntitySysManager.GetEntitySystem<TagSystem>().AddTags(puddleUid, Tags);

return reactVolume;
}

return FixedPoint2.Zero;
}
}
}
11 changes: 11 additions & 0 deletions Content.Shared/Fluids/Components/PropulsedByComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Robust.Shared.GameStates;

namespace Content.Shared.Fluids.Components
{
[RegisterComponent, NetworkedComponent]
public sealed partial class PropulsedByComponent : Component
{
[ViewVariables(VVAccess.ReadOnly)]
public HashSet<Entity<PropulsionComponent>> Sources = new();
}
}
35 changes: 35 additions & 0 deletions Content.Shared/Fluids/Components/PropulsionComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Content.Shared.Whitelist;
using Robust.Shared.GameStates;

namespace Content.Shared.Fluids.Components
{
/// <summary>
/// This object will speed up the movement speed of entities
/// when collided with
///
/// Used for mucin
///
/// This partially replicates SpeedModifierContactsComponent because that
/// component is already heavily coupled with existing puddle code.
/// </summary>
[RegisterComponent, NetworkedComponent]
[AutoGenerateComponentState]
public sealed partial class PropulsionComponent : Component
{
[DataField, ViewVariables]
[AutoNetworkedField]
public float WalkSpeedModifier = 1.0f;

[AutoNetworkedField]
[DataField, ViewVariables]
public float SprintSpeedModifier = 1.0f;

/// <summary>
/// If an entity passes this, apply the speed modifier.
/// Passes all entities if not defined.
/// </summary>
[AutoNetworkedField]
[DataField, ViewVariables]
public EntityWhitelist? Whitelist;
}
}
62 changes: 62 additions & 0 deletions Content.Shared/Fluids/EntitySystems/PropulsionSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System.Linq;
using Content.Shared.Fluids.Components;
using Content.Shared.Movement.Components;
using Content.Shared.Movement.Systems;
using Content.Shared.Whitelist;
using Robust.Shared.Physics.Events;

namespace Content.Shared.Fluids.EntitySystems;

public sealed class PropulsionSystem : EntitySystem
{
[Dependency] private readonly SpeedModifierContactsSystem _speedModifier = default!;
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<PropulsionComponent, ComponentInit>(OnComponentInit);
SubscribeLocalEvent<PropulsionComponent, StartCollideEvent>(OnStartCollide);
SubscribeLocalEvent<PropulsionComponent, EndCollideEvent>(OnEndCollide);
SubscribeLocalEvent<PropulsedByComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshSpeed);
}

public void OnComponentInit(Entity<PropulsionComponent> ent, ref ComponentInit args)
{
EnsureComp<SpeedModifierContactsComponent>(ent);
}

public void OnStartCollide(Entity<PropulsionComponent> ent, ref StartCollideEvent args)
{
if (!HasComp<MovementSpeedModifierComponent>(args.OtherEntity))
return;

if (_whitelistSystem.IsWhitelistFail(ent.Comp.Whitelist, args.OtherEntity))
return;

_speedModifier.AddModifiedEntity(args.OtherEntity);

var propulse = EnsureComp<PropulsedByComponent>(args.OtherEntity);
propulse.Sources.Add(ent);
}

public void OnEndCollide(Entity<PropulsionComponent> ent, ref EndCollideEvent args)
{
if (TryComp<PropulsedByComponent>(args.OtherEntity, out var propulse))
{
propulse.Sources.Remove(ent);
}
}

public static void OnRefreshSpeed(Entity<PropulsedByComponent> ent, ref RefreshMovementSpeedModifiersEvent args)
{
ent.Comp.Sources.RemoveWhere((ent) => !ent.Owner.IsValid() || ent.Comp.Deleted);

if (ent.Comp.Sources.Count == 0)
return;

var modifier = ent.Comp.Sources.First();
args.ModifySpeed(modifier.Comp.WalkSpeedModifier, modifier.Comp.SprintSpeedModifier);
}
}
Binary file modified Resources/Audio/Effects/Footsteps/snailstep.ogg
Binary file not shown.
9 changes: 6 additions & 3 deletions Resources/Prototypes/Entities/Effects/puddle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,19 @@
parent: PuddleTemporary
suffix: Mucin
components:
- type: TimedDespawn
lifetime: 5
- type: EvaporationSparkle
- type: SolutionContainerManager
solutions:
puddle:
maxVol: 1000
reagents:
- ReagentId: Mucin
Quantity: 20
- type: Propulsion
walkSpeedModifier: 2.0
sprintSpeedModifier: 2.0
whitelist:
components:
- SnailSpeed

- type: entity
id: PuddleFlour
Expand Down
11 changes: 9 additions & 2 deletions Resources/Prototypes/Reagents/biological.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
recognizable: true
physicalDesc: reagent-physical-desc-viscous
slippery: false
viscosity: -0.5
viscosity: 0.1
metabolisms:
Food:
effects:
Expand All @@ -103,7 +103,14 @@
params:
volume: 6
tileReactions:
- !type:SpillTileReaction
- !type:EnsureTileReaction
components:
- type: Propulsion
walkSpeedModifier: 2.0
sprintSpeedModifier: 2.0
whitelist:
components:
- SnailSpeed

- type: reagent
id: Sap
Expand Down
Loading