Files
crystall-punk-14/Content.Server/GameObjects/Components/Weapon/Melee/StunbatonComponent.cs

94 lines
3.1 KiB
C#
Raw Normal View History

2020-05-13 20:21:03 +02:00
using System.Collections.Generic;
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.EntitySystems;
2020-05-14 16:13:25 +02:00
using Content.Shared.Audio;
using Robust.Server.GameObjects;
2020-05-14 16:13:25 +02:00
using Robust.Server.GameObjects.EntitySystems;
2020-05-13 20:21:03 +02:00
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC;
using Robust.Shared.Random;
2020-05-13 20:21:03 +02:00
using Robust.Shared.Serialization;
2020-05-14 16:13:25 +02:00
using Robust.Shared.ViewVariables;
2020-05-13 20:21:03 +02:00
namespace Content.Server.GameObjects.Components.Weapon.Melee
{
[RegisterComponent]
public class StunbatonComponent : MeleeWeaponComponent, IUse
2020-05-13 20:21:03 +02:00
{
[Dependency] private IRobustRandom _robustRandom;
2020-05-14 16:13:25 +02:00
[Dependency] private IEntitySystemManager _entitySystemManager;
2020-05-13 20:21:03 +02:00
public override string Name => "Stunbaton";
2020-05-14 16:13:25 +02:00
private bool _activated = false;
[ViewVariables(VVAccess.ReadWrite)]
private float _paralyzeChance = 0.25f;
2020-05-14 16:13:25 +02:00
[ViewVariables(VVAccess.ReadWrite)]
private float _paralyzeTime = 10f;
[ViewVariables(VVAccess.ReadWrite)]
private float _slowdownTime = 5f;
2020-05-14 16:13:25 +02:00
[ViewVariables]
public bool Activated => _activated;
2020-05-13 20:21:03 +02:00
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _paralyzeChance, "paralyzeChance", 0.25f);
2020-05-13 20:21:03 +02:00
serializer.DataField(ref _paralyzeTime, "paralyzeTime", 10f);
serializer.DataField(ref _slowdownTime, "slowdownTime", 5f);
2020-05-13 20:21:03 +02:00
}
public override bool OnHitEntities(IReadOnlyList<IEntity> entities)
2020-05-13 20:21:03 +02:00
{
if (!Activated || entities.Count == 0)
return false;
2020-05-14 16:13:25 +02:00
_entitySystemManager.GetEntitySystem<AudioSystem>()
2020-05-14 17:26:08 +02:00
.Play("/Audio/weapons/egloves.ogg", Owner.Transform.GridPosition, AudioHelpers.WithVariation(0.25f));
2020-05-14 16:13:25 +02:00
2020-05-13 20:21:03 +02:00
foreach (var entity in entities)
{
if (!entity.TryGetComponent(out StunnableComponent stunnable)) continue;
if(_robustRandom.Prob(_paralyzeChance))
2020-05-13 20:21:03 +02:00
stunnable.Paralyze(_paralyzeTime);
else
stunnable.Slowdown(_slowdownTime);
}
return false;
}
public bool UseEntity(UseEntityEventArgs eventArgs)
{
var sprite = Owner.GetComponent<SpriteComponent>();
var item = Owner.GetComponent<ItemComponent>();
if (_activated)
{
item.EquippedPrefix = "off";
sprite.LayerSetState(0, "stunbaton_off");
_activated = false;
2020-05-13 20:21:03 +02:00
}
else
{
2020-05-14 16:13:25 +02:00
_entitySystemManager.GetEntitySystem<AudioSystem>()
2020-05-14 17:26:08 +02:00
.Play(AudioHelpers.GetRandomFileFromSoundCollection("sparks"), Owner.Transform.GridPosition, AudioHelpers.WithVariation(0.25f));
2020-05-14 16:13:25 +02:00
item.EquippedPrefix = "on";
sprite.LayerSetState(0, "stunbaton_on");
_activated = true;
}
return true;
2020-05-13 20:21:03 +02:00
}
}
}