* Add test for adding each component individually to entities * Put one-to-one test before all-at-once test
55 lines
1.8 KiB
C#
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) {}
|
|
}
|
|
}
|