Files
tbd-station-14/Content.Server/GameObjects/Components/Projectiles/FlashProjectileComponent.cs
DrSmugleaf b9196d0a10 Add a test that puts all components on an entity and checks for no exceptions (#1815)
* Add test that puts all components on an entity and checks for no exceptions

Also fix all the exceptions that happened because of this

* Add comments to the test

* Fix nullable errors

* Fix more nullable errors

* More nullable error fixes

* Unignore basic actor component

* Fix more nullable errors

* NULLABLE ERROR

* Add string interpolation

* Merge if checks

* Remove redundant pragma warning disable 649

* Address reviews

* Remove null wrappers around TryGetComponent

* Merge conflict fixes

* APC battery component error fix

* Fix power test

* Fix atmos mapgrid usages
2020-08-22 22:29:20 +02:00

54 lines
1.6 KiB
C#

using System;
using Content.Server.GameObjects.Components.Weapon;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Serialization;
namespace Content.Server.GameObjects.Components.Projectiles
{
/// <summary>
/// Upon colliding with an object this will flash in an area around it
/// </summary>
[RegisterComponent]
public class FlashProjectileComponent : Component, ICollideBehavior
{
public override string Name => "FlashProjectile";
private float _range;
private float _duration;
private bool _flashed;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _range, "range", 1.0f);
serializer.DataField(ref _duration, "duration", 8.0f);
}
public override void Initialize()
{
base.Initialize();
// Shouldn't be using this without a ProjectileComponent because it will just immediately collide with thrower
Owner.EnsureComponent<ProjectileComponent>();
}
void ICollideBehavior.CollideWith(IEntity entity)
{
if (_flashed)
{
return;
}
FlashableComponent.FlashAreaHelper(Owner, _range, _duration);
_flashed = true;
}
// Projectile should handle the deleting
void ICollideBehavior.PostCollide(int collisionCount)
{
return;
}
}
}