Files
tbd-station-14/Content.Server/GameObjects/Components/Projectiles/StunnableProjectileComponent.cs
DrSmugleaf a4f527351e Add test for adding each component individually to an entity (#1870)
* Add test for adding each component individually to entities

* Put one-to-one test before all-at-once test
2020-08-24 13:39:00 +02:00

55 lines
1.8 KiB
C#

using Content.Server.GameObjects.Components.Mobs;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Log;
using Robust.Shared.Serialization;
namespace Content.Server.GameObjects.Components.Projectiles
{
/// <summary>
/// Adds stun when it collides with an entity
/// </summary>
[RegisterComponent]
public sealed class StunnableProjectileComponent : Component, ICollideBehavior
{
public override string Name => "StunnableProjectile";
// See stunnable for what these do
private int _stunAmount;
private int _knockdownAmount;
private int _slowdownAmount;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _stunAmount, "stunAmount", 0);
serializer.DataField(ref _knockdownAmount, "knockdownAmount", 0);
serializer.DataField(ref _slowdownAmount, "slowdownAmount", 0);
}
public override void Initialize()
{
base.Initialize();
if (!Owner.EnsureComponent(out ProjectileComponent _))
{
Logger.Warning(
$"Entity {Owner.Name} at {Owner.Transform.MapPosition} didn't have a {nameof(ProjectileComponent)}");
}
}
void ICollideBehavior.CollideWith(IEntity entity)
{
if (entity.TryGetComponent(out StunnableComponent stunnableComponent))
{
stunnableComponent.Stun(_stunAmount);
stunnableComponent.Knockdown(_knockdownAmount);
stunnableComponent.Slowdown(_slowdownAmount);
}
}
void ICollideBehavior.PostCollide(int collidedCount) {}
}
}