Refactor MeleeWeaponComponent and related comps to be ECS (#4133)

* move everything to MeleeWeaponSystem

* refactor MeleeChemicalInjector

* hypospray and flash refactor

* stunbaton refactor

* bugfixes

* flash afterinteract

* resolve issues

* props

* playing the slots

* MeleeInteractEvent + bugfixes

* spear can actually use MeleeChemicalInjector
This commit is contained in:
mirrorcult
2021-06-05 00:20:52 -07:00
committed by GitHub
parent 3fa00d27df
commit f744b655b8
20 changed files with 895 additions and 750 deletions

View File

@@ -1,29 +1,23 @@
using System.Threading.Tasks;
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.Components.Mobs.State;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.GameObjects.EntitySystems.Weapon.Melee;
using Content.Shared.Chemistry;
using Content.Shared.GameObjects.Components.Chemistry;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.Player;
using Robust.Shared.Players;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
#nullable enable
namespace Content.Server.GameObjects.Components.Chemistry
{
[RegisterComponent]
public sealed class HyposprayComponent : SharedHyposprayComponent, IAttack, ISolutionChange, IAfterInteract
public sealed class HyposprayComponent : SharedHyposprayComponent, ISolutionChange
{
[DataField("ClumsyFailChance")]
[ViewVariables(VVAccess.ReadWrite)]
@@ -42,23 +36,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
Dirty();
}
bool IAttack.ClickAttack(AttackEvent eventArgs)
{
var target = eventArgs.TargetEntity;
var user = eventArgs.User;
return TryDoInject(target, user);
}
async Task<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
{
if (!eventArgs.CanReach)
return false;
return TryDoInject(eventArgs.Target, eventArgs.User);
}
private bool TryDoInject(IEntity? target, IEntity user)
public bool TryDoInject(IEntity? target, IEntity user)
{
if (target == null || !EligibleEntity(target))
return false;

View File

@@ -150,7 +150,8 @@ namespace Content.Server.GameObjects.Components.Power
{
SoundSystem.Play(Filter.Pvs(Owner), CellRemoveSound, Owner, AudioHelpers.WithVariation(0.125f));
}
SendMessage(new PowerCellChangedMessage(true));
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new PowerCellChangedEvent(true), false);
return cell;
}
@@ -172,7 +173,8 @@ namespace Content.Server.GameObjects.Components.Power
{
SoundSystem.Play(Filter.Pvs(Owner), CellInsertSound, Owner, AudioHelpers.WithVariation(0.125f));
}
SendMessage(new PowerCellChangedMessage(false));
Owner.EntityManager.EventBus.RaiseLocalEvent(Owner.Uid, new PowerCellChangedEvent(false), false);
return true;
}
@@ -238,14 +240,14 @@ namespace Content.Server.GameObjects.Components.Power
}
}
public class PowerCellChangedMessage : ComponentMessage
public class PowerCellChangedEvent : EntityEventArgs
{
/// <summary>
/// If true, the cell was ejected; if false, it was inserted.
/// </summary>
public bool Ejected { get; }
public PowerCellChangedMessage(bool ejected)
public PowerCellChangedEvent(bool ejected)
{
Ejected = ejected;
}

View File

@@ -1,162 +1,36 @@
#nullable enable
using System.Collections.Generic;
using Content.Server.GameObjects.Components.Mobs;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Player;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Weapon.Melee
{
[RegisterComponent]
public class FlashComponent : MeleeWeaponComponent, IUse, IExamine
public class FlashComponent : Component
{
public override string Name => "Flash";
public FlashComponent() { Range = 7f; }
[DataField("duration")]
[ViewVariables(VVAccess.ReadWrite)]
public int FlashDuration { get; set; } = 5000;
[DataField("duration")] [ViewVariables(VVAccess.ReadWrite)] private int _flashDuration = 5000;
[DataField("uses")] [ViewVariables(VVAccess.ReadWrite)] private int _uses = 5;
[ViewVariables(VVAccess.ReadWrite)] private float _range => Range;
[ViewVariables(VVAccess.ReadWrite)] private int _aoeFlashDuration => _internalAoeFlashDuration ?? _flashDuration / 3;
[DataField("aoeFlashDuration")] private int? _internalAoeFlashDuration;
[DataField("slowTo")] [ViewVariables(VVAccess.ReadWrite)] private float _slowTo = 0.75f;
private bool _flashing;
[DataField("uses")]
[ViewVariables(VVAccess.ReadWrite)]
public int Uses { get; set; } = 5;
private int Uses
{
get => _uses;
set
{
_uses = value;
Dirty();
}
}
[DataField("range")]
[ViewVariables(VVAccess.ReadWrite)]
public float Range { get; set; } = 7f;
private bool HasUses => _uses > 0;
[ViewVariables(VVAccess.ReadWrite)]
[DataField("aoeFlashDuration")]
public int AoeFlashDuration { get; set; } = 2000;
protected override bool OnHitEntities(IReadOnlyList<IEntity> entities, AttackEvent eventArgs)
{
if (entities.Count == 0)
{
return false;
}
[DataField("slowTo")]
[ViewVariables(VVAccess.ReadWrite)]
public float SlowTo { get; set; } = 0.5f;
if (!Use(eventArgs.User))
{
return false;
}
public bool Flashing;
foreach (var entity in entities)
{
Flash(entity, eventArgs.User);
}
return true;
}
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
{
if (!Use(eventArgs.User))
{
return false;
}
foreach (var entity in IoCManager.Resolve<IEntityLookup>().GetEntitiesInRange(Owner.Transform.Coordinates, _range))
{
Flash(entity, eventArgs.User, _aoeFlashDuration);
}
return true;
}
private bool Use(IEntity user)
{
if (HasUses)
{
var sprite = Owner.GetComponent<SpriteComponent>();
if (--Uses == 0)
{
sprite.LayerSetState(0, "burnt");
Owner.PopupMessage(user, Loc.GetString("flash-component-becomes-empty"));
}
else if (!_flashing)
{
int animLayer = sprite.AddLayerWithState("flashing");
_flashing = true;
Owner.SpawnTimer(400, () =>
{
sprite.RemoveLayer(animLayer);
_flashing = false;
});
}
SoundSystem.Play(Filter.Pvs(Owner), "/Audio/Weapons/flash.ogg", Owner.Transform.Coordinates,
AudioParams.Default);
return true;
}
return false;
}
private void Flash(IEntity entity, IEntity user)
{
Flash(entity, user, _flashDuration);
}
// TODO: Check if target can be flashed (e.g. things like sunglasses would block a flash)
// TODO: Merge with the code in FlashableComponent
private void Flash(IEntity entity, IEntity user, int flashDuration)
{
if (entity.TryGetComponent<FlashableComponent>(out var flashable))
{
flashable.Flash(flashDuration / 1000d);
}
if (entity.TryGetComponent<StunnableComponent>(out var stunnableComponent))
{
stunnableComponent.Slowdown(flashDuration / 1000f, _slowTo, _slowTo);
}
if (entity != user)
{
user.PopupMessage(entity,
Loc.GetString(
"flash-component-user-blinds-you",
("user", user)
)
);
}
}
public void Examine(FormattedMessage message, bool inDetailsRange)
{
if (!HasUses)
{
message.AddText(Loc.GetString("flash-component-examine-empty"));
return;
}
if (inDetailsRange)
{
message.AddMarkup(
Loc.GetString(
"flash-component-examine-detail-count",
("count", Uses),
("markupCountColor", "green")
)
);
}
}
public bool HasUses => Uses > 0;
}
}

View File

@@ -1,14 +1,7 @@
#nullable enable
using Content.Server.GameObjects.Components.Body.Circulatory;
using Content.Server.GameObjects.Components.Chemistry;
using Content.Shared.Chemistry;
using Content.Shared.Chemistry;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
using System;
using System.Collections.Generic;
using System.Linq;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.GameObjects.Components.Weapon.Melee
@@ -24,48 +17,8 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
[ViewVariables(VVAccess.ReadWrite)]
public float TransferEfficiency { get => _transferEfficiency; set => _transferEfficiency = Math.Clamp(value, 0, 1); }
[DataField("transferEfficiency")]
private float _transferEfficiency = 1f;
public override void HandleMessage(ComponentMessage message, IComponent? component)
{
base.HandleMessage(message, component);
switch (message)
{
case MeleeHitMessage meleeHit:
InjectEntities(meleeHit.HitEntities);
break;
}
}
private void InjectEntities(List<IEntity> hitEntities)
{
if (!Owner.TryGetComponent<SolutionContainerComponent>(out var solutionContainer))
return;
var hitBloodstreams = new List<BloodstreamComponent>();
foreach (var entity in hitEntities)
{
if (entity.Deleted)
continue;
if (entity.TryGetComponent<BloodstreamComponent>(out var bloodstream))
hitBloodstreams.Add(bloodstream);
}
if (!hitBloodstreams.Any())
return;
var removedSolution = solutionContainer.Solution.SplitSolution(TransferAmount * hitBloodstreams.Count);
var removedVol = removedSolution.TotalVolume;
var solutionToInject = removedSolution.SplitSolution(removedVol * TransferEfficiency);
var volPerBloodstream = solutionToInject.TotalVolume * (1 / hitBloodstreams.Count);
foreach (var bloodstream in hitBloodstreams)
{
var individualInjection = solutionToInject.SplitSolution(volPerBloodstream);
bloodstream.TryTransferSolution(individualInjection);
}
}
}
}

View File

@@ -1,46 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Server.GameObjects.EntitySystems;
using Content.Shared.Damage;
using Content.Shared.GameObjects.Components.Damage;
using Content.Shared.GameObjects.Components.Items;
using Content.Shared.Interfaces.GameObjects.Components;
using Content.Shared.Physics;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Broadphase;
using Robust.Shared.Player;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Timing;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Weapon.Melee
{
[RegisterComponent]
public class MeleeWeaponComponent : Component, IAttack, IHandSelected
public class MeleeWeaponComponent : Component
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
public override string Name => "MeleeWeapon";
private TimeSpan _lastAttackTime;
private TimeSpan _cooldownEnd;
[ViewVariables(VVAccess.ReadWrite)]
[DataField("hitSound")]
private string _hitSound = "/Audio/Weapons/genhit1.ogg";
public string HitSound { get; set; } = "/Audio/Weapons/genhit1.ogg";
[ViewVariables(VVAccess.ReadWrite)]
[DataField("missSound")]
private string _missSound = "/Audio/Weapons/punchmiss.ogg";
public string MissSound { get; set; } = "/Audio/Weapons/punchmiss.ogg";
[ViewVariables]
[DataField("arcCooldownTime")]
public float ArcCooldownTime { get; private set; } = 1f;
public float ArcCooldownTime { get; } = 1f;
[ViewVariables]
[DataField("cooldownTime")]
public float CooldownTime { get; private set; } = 1f;
public float CooldownTime { get; } = 1f;
[ViewVariables(VVAccess.ReadWrite)]
[DataField("clickArc")]
@@ -50,7 +35,9 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
[DataField("arc")]
public string Arc { get; set; } = "default";
[ViewVariables(VVAccess.ReadWrite)] [DataField("arcwidth")] public float ArcWidth { get; set; } = 90;
[ViewVariables(VVAccess.ReadWrite)]
[DataField("arcwidth")]
public float ArcWidth { get; set; } = 90;
[ViewVariables(VVAccess.ReadWrite)]
[DataField("range")]
@@ -64,185 +51,11 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
[DataField("damageType")]
public DamageType DamageType { get; set; } = DamageType.Blunt;
[ViewVariables(VVAccess.ReadWrite)] [DataField("clickAttackEffect")] public bool ClickAttackEffect { get; set; } = true;
[ViewVariables(VVAccess.ReadWrite)]
[DataField("clickAttackEffect")]
public bool ClickAttackEffect { get; set; } = true;
protected virtual bool OnHitEntities(IReadOnlyList<IEntity> entities, AttackEvent eventArgs)
{
return true;
}
bool IAttack.WideAttack(AttackEvent eventArgs)
{
if (!eventArgs.WideAttack) return true;
var curTime = _gameTiming.CurTime;
if (curTime < _cooldownEnd)
return true;
var location = eventArgs.User.Transform.Coordinates;
var diff = eventArgs.ClickLocation.ToMapPos(Owner.EntityManager) - location.ToMapPos(Owner.EntityManager);
var angle = Angle.FromWorldVec(diff);
// This should really be improved. GetEntitiesInArc uses pos instead of bounding boxes.
var entities = ArcRayCast(eventArgs.User.Transform.WorldPosition, angle, eventArgs.User);
if (entities.Count != 0)
{
SoundSystem.Play(Filter.Pvs(Owner), _hitSound, entities.First().Transform.Coordinates);
}
else
{
SoundSystem.Play(Filter.Pvs(Owner), _missSound, eventArgs.User.Transform.Coordinates);
}
var hitEntities = new List<IEntity>();
foreach (var entity in entities)
{
if (!entity.Transform.IsMapTransform || entity == eventArgs.User)
continue;
if (entity.TryGetComponent(out IDamageableComponent? damageComponent))
{
damageComponent.ChangeDamage(DamageType, Damage, false, Owner);
hitEntities.Add(entity);
}
}
SendMessage(new MeleeHitMessage(hitEntities));
if (!OnHitEntities(hitEntities, eventArgs)) return false;
if (Arc != null)
{
var sys = EntitySystem.Get<MeleeWeaponSystem>();
sys.SendAnimation(Arc, angle, eventArgs.User, Owner, hitEntities);
}
_lastAttackTime = curTime;
_cooldownEnd = _lastAttackTime + TimeSpan.FromSeconds(ArcCooldownTime);
RefreshItemCooldown();
return true;
}
bool IAttack.ClickAttack(AttackEvent eventArgs)
{
if (eventArgs.WideAttack) return false;
var curTime = _gameTiming.CurTime;
if (curTime < _cooldownEnd || !eventArgs.Target.IsValid())
return true;
var target = eventArgs.TargetEntity;
var location = eventArgs.User.Transform.Coordinates;
var diff = eventArgs.ClickLocation.ToMapPos(Owner.EntityManager) - location.ToMapPos(Owner.EntityManager);
var angle = Angle.FromWorldVec(diff);
if (target != null)
{
SoundSystem.Play(Filter.Pvs(Owner), _hitSound, target);
}
else
{
SoundSystem.Play(Filter.Pvs(Owner), _missSound, eventArgs.User);
return false;
}
if (target.TryGetComponent(out IDamageableComponent? damageComponent))
{
damageComponent.ChangeDamage(DamageType, Damage, false, Owner);
}
SendMessage(new MeleeHitMessage(new List<IEntity> { target }));
var targets = new[] { target };
if (!OnHitEntities(targets, eventArgs))
return false;
if (ClickArc != null)
{
var sys = EntitySystem.Get<MeleeWeaponSystem>();
sys.SendAnimation(ClickArc, angle, eventArgs.User, Owner, targets, ClickAttackEffect, false);
}
_lastAttackTime = curTime;
_cooldownEnd = _lastAttackTime + TimeSpan.FromSeconds(CooldownTime);
RefreshItemCooldown();
return true;
}
private HashSet<IEntity> ArcRayCast(Vector2 position, Angle angle, IEntity ignore)
{
var widthRad = Angle.FromDegrees(ArcWidth);
var increments = 1 + 35 * (int) Math.Ceiling(widthRad / (2 * Math.PI));
var increment = widthRad / increments;
var baseAngle = angle - widthRad / 2;
var resSet = new HashSet<IEntity>();
var mapId = Owner.Transform.MapID;
for (var i = 0; i < increments; i++)
{
var castAngle = new Angle(baseAngle + increment * i);
var res = EntitySystem.Get<SharedBroadPhaseSystem>().IntersectRay(mapId,
new CollisionRay(position, castAngle.ToWorldVec(),
(int) (CollisionGroup.Impassable | CollisionGroup.MobImpassable)), Range, ignore).ToList();
if (res.Count != 0)
{
resSet.Add(res[0].HitEntity);
}
}
return resSet;
}
void IHandSelected.HandSelected(HandSelectedEventArgs eventArgs)
{
var curTime = _gameTiming.CurTime;
var cool = TimeSpan.FromSeconds(CooldownTime * 0.5f);
if (curTime < _cooldownEnd)
{
if (_cooldownEnd - curTime < cool)
{
_lastAttackTime = curTime;
_cooldownEnd += cool;
}
else
return;
}
else
{
_lastAttackTime = curTime;
_cooldownEnd = curTime + cool;
}
RefreshItemCooldown();
}
private void RefreshItemCooldown()
{
if (Owner.TryGetComponent(out ItemCooldownComponent? cooldown))
{
cooldown.CooldownStart = _lastAttackTime;
cooldown.CooldownEnd = _cooldownEnd;
}
}
}
public class MeleeHitMessage : ComponentMessage
{
public readonly List<IEntity> HitEntities;
public MeleeHitMessage(List<IEntity> hitEntities)
{
HitEntities = hitEntities;
}
public TimeSpan LastAttackTime;
public TimeSpan CooldownEnd;
}
}

View File

@@ -1,219 +1,35 @@
#nullable enable
using System.Collections.Generic;
using System.Threading.Tasks;
using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.Components.Power;
using Content.Shared.Audio;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Weapon.Melee
{
[RegisterComponent]
public class StunbatonComponent : MeleeWeaponComponent, IUse, IExamine, IInteractUsing, IThrowCollide
public class StunbatonComponent : Component
{
[Dependency] private readonly IRobustRandom _robustRandom = default!;
public override string Name => "Stunbaton";
private bool _activated = false;
[ViewVariables] private PowerCellSlotComponent _cellSlot = default!;
private PowerCellComponent? Cell => _cellSlot.Cell;
public bool Activated = false;
[ViewVariables(VVAccess.ReadWrite)]
[DataField("paralyzeChanceNoSlowdown")]
private float _paralyzeChanceNoSlowdown = 0.35f;
public float ParalyzeChanceNoSlowdown { get; set; } = 0.35f;
[ViewVariables(VVAccess.ReadWrite)]
[DataField("paralyzeChanceWithSlowdown")]
private float _paralyzeChanceWithSlowdown = 0.85f;
public float ParalyzeChanceWithSlowdown { get; set; } = 0.85f;
[ViewVariables(VVAccess.ReadWrite)]
[DataField("paralyzeTime")]
private float _paralyzeTime = 10f;
public float ParalyzeTime { get; set; } = 10f;
[ViewVariables(VVAccess.ReadWrite)]
[DataField("slowdownTime")]
private float _slowdownTime = 5f;
public float SlowdownTime { get; set; } = 5f;
[ViewVariables(VVAccess.ReadWrite)] public float EnergyPerUse { get; set; } = 50;
[ViewVariables]
public bool Activated => _activated;
public override void Initialize()
{
base.Initialize();
_cellSlot = Owner.EnsureComponent<PowerCellSlotComponent>();
}
public override void HandleMessage(ComponentMessage message, IComponent? component)
{
base.HandleMessage(message, component);
switch (message)
{
case PowerCellChangedMessage m:
if (component is PowerCellSlotComponent slotComponent && slotComponent == _cellSlot)
{
if (m.Ejected)
{
TurnOff();
}
}
break;
}
}
protected override bool OnHitEntities(IReadOnlyList<IEntity> entities, AttackEvent eventArgs)
{
if (!Activated || entities.Count == 0 || Cell == null)
return true;
if (!Cell.TryUseCharge(EnergyPerUse))
return true;
SoundSystem.Play(Filter.Pvs(Owner), "/Audio/Weapons/egloves.ogg", Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));
foreach (var entity in entities)
{
if (!entity.TryGetComponent(out StunnableComponent? stunnable)) continue;
if(!stunnable.SlowedDown)
{
if(_robustRandom.Prob(_paralyzeChanceNoSlowdown))
stunnable.Paralyze(_paralyzeTime);
else
stunnable.Slowdown(_slowdownTime);
}
else
{
if(_robustRandom.Prob(_paralyzeChanceWithSlowdown))
stunnable.Paralyze(_paralyzeTime);
else
stunnable.Slowdown(_slowdownTime);
}
}
if (!(Cell.CurrentCharge < EnergyPerUse)) return true;
SoundSystem.Play(Filter.Pvs(Owner), AudioHelpers.GetRandomFileFromSoundCollection("sparks"), Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));
TurnOff();
return true;
}
private bool ToggleStatus(IEntity user)
{
if (!ActionBlockerSystem.CanUse(user)) return false;
if (Activated)
{
TurnOff();
}
else
{
TurnOn(user);
}
return true;
}
private void TurnOff()
{
if (!_activated)
{
return;
}
var sprite = Owner.GetComponent<SpriteComponent>();
var item = Owner.GetComponent<ItemComponent>();
SoundSystem.Play(Filter.Pvs(Owner), AudioHelpers.GetRandomFileFromSoundCollection("sparks"), Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));
item.EquippedPrefix = "off";
sprite.LayerSetState(0, "stunbaton_off");
_activated = false;
}
private void TurnOn(IEntity user)
{
if (_activated)
{
return;
}
var sprite = Owner.GetComponent<SpriteComponent>();
var item = Owner.GetComponent<ItemComponent>();
var playerFilter = Filter.Pvs(Owner);
if (Cell == null)
{
SoundSystem.Play(playerFilter, "/Audio/Machines/button.ogg", Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));
Owner.PopupMessage(user, Loc.GetString("Cell missing..."));
return;
}
if (Cell.CurrentCharge < EnergyPerUse)
{
SoundSystem.Play(playerFilter, "/Audio/Machines/button.ogg", Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));
Owner.PopupMessage(user, Loc.GetString("Dead cell..."));
return;
}
SoundSystem.Play(playerFilter, AudioHelpers.GetRandomFileFromSoundCollection("sparks"), Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));
item.EquippedPrefix = "on";
sprite.LayerSetState(0, "stunbaton_on");
_activated = true;
}
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
{
ToggleStatus(eventArgs.User);
return true;
}
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
{
if (!ActionBlockerSystem.CanInteract(eventArgs.User)) return false;
if (!_cellSlot.InsertCell(eventArgs.Using)) return false;
Dirty();
return true;
}
public void Examine(FormattedMessage message, bool inDetailsRange)
{
if (Activated)
{
message.AddMarkup(Loc.GetString("The light is currently [color=darkgreen]on[/color]."));
}
}
void IThrowCollide.DoHit(ThrowCollideEventArgs eventArgs)
{
if (!Activated || Cell == null || !Cell.TryUseCharge(EnergyPerUse) || !eventArgs.Target.TryGetComponent(out StunnableComponent? stunnable))
return;
SoundSystem.Play(Filter.Pvs(Owner), "/Audio/Weapons/egloves.ogg", Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));
stunnable.Paralyze(_paralyzeTime);
}
[ViewVariables(VVAccess.ReadWrite)]
[DataField("energyPerUse")]
public float EnergyPerUse { get; set; } = 50;
}
}