From 72ba0d9458462e1910a8608f55db505aa58ddbfa Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Tue, 13 Aug 2019 23:43:44 +0200 Subject: [PATCH] Don't let bullets fly forever. Give them 10 seconds until deleted. --- .../Projectiles/ProjectileComponent.cs | 2 ++ .../EntitySystems/ProjectileSystem.cs | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 Content.Server/GameObjects/EntitySystems/ProjectileSystem.cs diff --git a/Content.Server/GameObjects/Components/Projectiles/ProjectileComponent.cs b/Content.Server/GameObjects/Components/Projectiles/ProjectileComponent.cs index 48051aa31d..d2a36ae105 100644 --- a/Content.Server/GameObjects/Components/Projectiles/ProjectileComponent.cs +++ b/Content.Server/GameObjects/Components/Projectiles/ProjectileComponent.cs @@ -20,6 +20,8 @@ namespace Content.Server.GameObjects.Components.Projectiles public Dictionary damages = new Dictionary(); + public float TimeLeft { get; set; } = 10; + /// /// Function that makes the collision of this object ignore a specific entity so we don't collide with ourselves /// diff --git a/Content.Server/GameObjects/EntitySystems/ProjectileSystem.cs b/Content.Server/GameObjects/EntitySystems/ProjectileSystem.cs new file mode 100644 index 0000000000..a1e4713aa5 --- /dev/null +++ b/Content.Server/GameObjects/EntitySystems/ProjectileSystem.cs @@ -0,0 +1,34 @@ +using Content.Server.GameObjects.Components.Projectiles; +using JetBrains.Annotations; +using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects.Systems; + +namespace Content.Server.GameObjects.EntitySystems +{ + [UsedImplicitly] + internal sealed class ProjectileSystem : EntitySystem + { + public override void Initialize() + { + base.Initialize(); + + EntityQuery = new TypeEntityQuery(typeof(ProjectileComponent)); + } + + public override void Update(float frameTime) + { + base.Update(frameTime); + + foreach (var entity in RelevantEntities) + { + var component = entity.GetComponent(); + component.TimeLeft -= frameTime; + + if (component.TimeLeft <= 0) + { + entity.Delete(); + } + } + } + } +}