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

[Feature] StepTriggerGroup to improve StepTriggerImmune behaviour #53

Merged
merged 12 commits into from
Sep 16, 2024
4 changes: 4 additions & 0 deletions Content.Shared/StepTrigger/Components/StepTriggerComponent.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared.StepTrigger.Prototypes;
using Content.Shared.StepTrigger.Systems;
using Content.Shared.Whitelist;
using Robust.Shared.GameStates;
Expand Down Expand Up @@ -57,6 +58,9 @@ public sealed partial class StepTriggerComponent : Component
/// </summary>
[DataField, AutoNetworkedField]
public bool StepOn = false;

[DataField, AutoNetworkedField]
public StepTriggerGroup? TriggerGroups = default!;
}

[RegisterComponent]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Content.Shared.StepTrigger.Prototypes;
using Content.Shared.StepTrigger.Systems;
using Robust.Shared.GameStates;

namespace Content.Shared.StepTrigger.Components;
Expand All @@ -12,4 +14,12 @@ namespace Content.Shared.StepTrigger.Components;
/// Consider using a subscription to StepTriggerAttemptEvent if you wish to be more selective.
/// </remarks>
[RegisterComponent, NetworkedComponent]
public sealed partial class StepTriggerImmuneComponent : Component { }
[Access(typeof(StepTriggerSystem))]
public sealed partial class StepTriggerImmuneComponent : Component
{
/// <summary>
/// WhiteList of immunable triggers.
/// </summary>
[DataField]
public StepTriggerGroup? Whitelist = default!;
}
21 changes: 21 additions & 0 deletions Content.Shared/StepTrigger/Prototypes/StepTriggerGroup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Content.Shared.Damage.Prototypes;
using Content.Shared.StepTrigger.Systems;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;

namespace Content.Shared.StepTrigger.Prototypes
{
/// <summary>
/// A group of <see cref="StepTriggerTypePrototype">
///
/// </summary>
[DataDefinition]
[Serializable, NetSerializable]
public sealed partial class StepTriggerGroup
{
[DataField("Types", customTypeSerializer:typeof(PrototypeIdListSerializer<StepTriggerTypePrototype>))]
[Access(typeof(StepTriggerSystem), Other = AccessPermissions.ReadExecute)]
public List<string> Types = new();
}
}
13 changes: 13 additions & 0 deletions Content.Shared/StepTrigger/Prototypes/StepTriggerTypePrototype.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Robust.Shared.Prototypes;

namespace Content.Shared.StepTrigger.Prototypes
{
[Prototype("StepTriggerType")]
HellCatten marked this conversation as resolved.
Show resolved Hide resolved
public sealed partial class StepTriggerTypePrototype : IPrototype
{
[ViewVariables]
[IdDataField]
public string ID { get; private set; } = default!;
}
}

19 changes: 19 additions & 0 deletions Content.Shared/StepTrigger/Systems/StepTriggerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Events;
using Enumerable = System.Linq.Enumerable;

namespace Content.Shared.StepTrigger.Systems;

Expand Down Expand Up @@ -118,10 +119,28 @@ private void UpdateColliding(EntityUid uid, StepTriggerComponent component, Tran

private bool CanTrigger(EntityUid uid, EntityUid otherUid, StepTriggerComponent component)
{
/*
if (HasComp<StepTriggerImmuneComponent>(otherUid)
|| !component.Active
|| component.CurrentlySteppedOn.Contains(otherUid))
return false;
*/
HellCatten marked this conversation as resolved.
Show resolved Hide resolved

if (!component.Active
|| component.CurrentlySteppedOn.Contains(otherUid))
return false;

if (TryComp<StepTriggerImmuneComponent>(otherUid, out var stepTriggerImmuneComponent))
{
if (stepTriggerImmuneComponent.Whitelist != null)
{
foreach (var type in stepTriggerImmuneComponent.Whitelist.Types)
{
if (component.TriggerGroups != null && component.TriggerGroups.Types != null && component.TriggerGroups.Types.Contains(type))
return false;
}
}
}

// Can't trigger if we don't ignore weightless entities
// and the entity is flying or currently weightless
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Mobs/Player/ipc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
- type: OfferItem
- type: LayingDown
- type: Carriable
- type: Damageable

- type: entity
save: false
Expand Down
9 changes: 6 additions & 3 deletions Resources/Prototypes/Entities/Tiles/chasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
blacklist:
tags:
- Catwalk
triggerGroup:
types:
- Chasm
- type: Transform
anchored: true
- type: Clickable
Expand Down Expand Up @@ -55,7 +58,7 @@
sprite: Tiles/Planet/Chasms/chromite_chasm.rsi
- type: Icon
sprite: Tiles/Planet/Chasms/chromite_chasm.rsi

- type: entity
parent: FloorChasmEntity
id: FloorDesertChasm
Expand All @@ -65,7 +68,7 @@
sprite: Tiles/Planet/Chasms/desert_chasm.rsi
- type: Icon
sprite: Tiles/Planet/Chasms/desert_chasm.rsi

- type: entity
parent: FloorChasmEntity
id: FloorSnowChasm
Expand All @@ -74,4 +77,4 @@
- type: Sprite
sprite: Tiles/Planet/Chasms/snow_chasm.rsi
- type: Icon
sprite: Tiles/Planet/Chasms/snow_chasm.rsi
sprite: Tiles/Planet/Chasms/snow_chasm.rsi
3 changes: 3 additions & 0 deletions Resources/Prototypes/Entities/Tiles/lava.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
blacklist:
tags:
- Catwalk
triggerGroup:
types:
- Lava
- type: Lava
fireStacks: 0.75
- type: Transform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
stripTimeReduction: 0
stripTimeMultiplier: 0.667
- type: StepTriggerImmune
whitelist:
types:
- Lava

- type: entity
save: false
Expand Down
Loading