prevent repeat TriggerOnCollide triggers (#40428)

* prevent repeat TriggerOnCollide triggers

* review comment: remove TriggerOnCollide when out of triggers
This commit is contained in:
Charlie Morley
2025-09-21 09:23:37 -06:00
committed by GitHub
parent 7678251ad5
commit 818a715822
6 changed files with 34 additions and 1 deletions

View File

@@ -20,4 +20,10 @@ public sealed partial class TriggerOnCollideComponent : BaseTriggerOnXComponent
/// </summary>
[DataField, AutoNetworkedField]
public bool IgnoreOtherNonHard = true;
/// <summary>
/// If not null, limits the amount of times this component can trigger.
/// </summary>
[DataField, AutoNetworkedField]
public int? MaxTriggers = null;
}

View File

@@ -18,8 +18,21 @@ public sealed partial class TriggerSystem
private void OnCollide(Entity<TriggerOnCollideComponent> ent, ref StartCollideEvent args)
{
if (args.OurFixtureId == ent.Comp.FixtureID && (!ent.Comp.IgnoreOtherNonHard || args.OtherFixture.Hard))
if (
args.OurFixtureId == ent.Comp.FixtureID
&& (!ent.Comp.IgnoreOtherNonHard || args.OtherFixture.Hard)
&& (ent.Comp.MaxTriggers == null || ent.Comp.MaxTriggers > 0)
)
{
if (ent.Comp.MaxTriggers != null)
{
ent.Comp.MaxTriggers--;
Dirty(ent);
if (ent.Comp.MaxTriggers <= 0)
RemCompDeferred<TriggerOnCollideComponent>(ent);
}
Trigger(ent.Owner, args.OtherEntity, ent.Comp.KeyOut);
}
}
private void OnStepTriggered(Entity<TriggerOnStepTriggerComponent> ent, ref StepTriggeredOffEvent args)

View File

@@ -176,6 +176,9 @@
Poison: 5
- type: TriggerOnCollide
fixtureID: projectile
# Projectile.DeleteOnCollide is true, but allow this to hit multiple entities if they're
# stacked up (they will all trigger a collide), so this isn't frustrating to use
maxTriggers: null
- type: PolymorphOnTrigger
targetUser: true

View File

@@ -101,6 +101,7 @@
components:
- type: TriggerOnCollide
fixtureID: projectile
maxTriggers: 1
- type: Projectile
damage:
types:

View File

@@ -55,6 +55,7 @@
components:
- type: TriggerOnCollide
fixtureID: rune
maxTriggers: 1
- type: ExplodeOnTrigger
- type: Explosive
explosionType: Cryo
@@ -74,6 +75,7 @@
components:
- type: TriggerOnCollide
fixtureID: rune
maxTriggers: 1
- type: DeleteOnTrigger
- type: StunOnCollide
stunAmount: 5
@@ -92,6 +94,7 @@
components:
- type: TriggerOnCollide
fixtureID: ignition
maxTriggers: 1
- type: Fixtures
fixtures:
ignition:

View File

@@ -40,6 +40,7 @@
components:
- type: TriggerOnCollide
fixtureID: floortrap
maxTriggers: 1
- type: ExplodeOnTrigger
- type: Explosive
explosionType: Default
@@ -55,6 +56,7 @@
components:
- type: TriggerOnCollide
fixtureID: floortrap
maxTriggers: 1
- type: EmpOnTrigger
range: 2
energyConsumption: 5000
@@ -67,6 +69,7 @@
components:
- type: TriggerOnCollide
fixtureID: floortrap
maxTriggers: 1
- type: SpawnOnTrigger
proto: MobCarp
- type: DeleteOnTrigger
@@ -78,6 +81,7 @@
components:
- type: TriggerOnCollide
fixtureID: floortrap
maxTriggers: 1
- type: SpawnOnTrigger
proto: MobBearSpace
- type: DeleteOnTrigger
@@ -89,6 +93,7 @@
components:
- type: TriggerOnCollide
fixtureID: floortrap
maxTriggers: 1
- type: SpawnOnTrigger
proto: MobKangarooSpace
- type: DeleteOnTrigger
@@ -100,6 +105,7 @@
components:
- type: TriggerOnCollide
fixtureID: floortrap
maxTriggers: 1
- type: SpawnOnTrigger
proto: MobXenoDrone
- type: DeleteOnTrigger
@@ -111,6 +117,7 @@
components:
- type: TriggerOnCollide
fixtureID: floortrap
maxTriggers: 1
- type: SpawnOnTrigger
proto: MobXeno
- type: DeleteOnTrigger