2022-07-29 14:13:12 +12:00
|
|
|
using Content.Server.CombatMode.Disarm;
|
|
|
|
|
using Content.Server.Kitchen.Components;
|
2022-09-29 15:51:59 +10:00
|
|
|
using Content.Server.Weapons.Melee.EnergySword.Components;
|
2022-01-24 09:55:48 -03:00
|
|
|
using Content.Shared.Interaction;
|
2022-03-13 01:33:23 +13:00
|
|
|
using Content.Shared.Interaction.Events;
|
2022-01-24 09:55:48 -03:00
|
|
|
using Content.Shared.Item;
|
2022-04-16 17:11:48 +12:00
|
|
|
using Content.Shared.Light;
|
|
|
|
|
using Content.Shared.Light.Component;
|
2022-09-03 12:50:38 +02:00
|
|
|
using Content.Shared.Temperature;
|
2022-04-16 17:11:48 +12:00
|
|
|
using Content.Shared.Toggleable;
|
2022-04-02 16:52:44 +13:00
|
|
|
using Content.Shared.Tools.Components;
|
2022-09-29 15:51:59 +10:00
|
|
|
using Content.Shared.Weapons.Melee;
|
2022-11-09 07:34:07 +11:00
|
|
|
using Content.Shared.Weapons.Melee.Events;
|
2022-01-24 09:55:48 -03:00
|
|
|
using Robust.Shared.Audio;
|
|
|
|
|
using Robust.Shared.Player;
|
|
|
|
|
using Robust.Shared.Random;
|
|
|
|
|
|
2022-09-29 15:51:59 +10:00
|
|
|
namespace Content.Server.Weapons.Melee.EnergySword
|
2022-01-24 09:55:48 -03:00
|
|
|
{
|
2022-02-21 14:41:50 +11:00
|
|
|
public sealed class EnergySwordSystem : EntitySystem
|
2022-01-24 09:55:48 -03:00
|
|
|
{
|
|
|
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
2022-04-16 17:11:48 +12:00
|
|
|
[Dependency] private readonly SharedRgbLightControllerSystem _rgbSystem = default!;
|
2022-07-27 03:53:47 -07:00
|
|
|
[Dependency] private readonly SharedItemSystem _item = default!;
|
2022-02-21 14:41:50 +11:00
|
|
|
|
2022-01-24 09:55:48 -03:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<EnergySwordComponent, MapInitEvent>(OnMapInit);
|
2022-11-03 13:01:08 +01:00
|
|
|
SubscribeLocalEvent<EnergySwordComponent, MeleeHitEvent>(OnMeleeHit);
|
2022-01-24 09:55:48 -03:00
|
|
|
SubscribeLocalEvent<EnergySwordComponent, UseInHandEvent>(OnUseInHand);
|
|
|
|
|
SubscribeLocalEvent<EnergySwordComponent, InteractUsingEvent>(OnInteractUsing);
|
2022-09-03 12:50:38 +02:00
|
|
|
SubscribeLocalEvent<EnergySwordComponent, IsHotEvent>(OnIsHotEvent);
|
2022-01-24 09:55:48 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnMapInit(EntityUid uid, EnergySwordComponent comp, MapInitEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (comp.ColorOptions.Count != 0)
|
|
|
|
|
comp.BladeColor = _random.Pick(comp.ColorOptions);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-03 13:01:08 +01:00
|
|
|
private void OnMeleeHit(EntityUid uid, EnergySwordComponent comp, MeleeHitEvent args)
|
2022-01-24 09:55:48 -03:00
|
|
|
{
|
|
|
|
|
if (!comp.Activated) return;
|
|
|
|
|
|
|
|
|
|
// Overrides basic blunt damage with burn+slash as set in yaml
|
|
|
|
|
args.BonusDamage = comp.LitDamageBonus;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnUseInHand(EntityUid uid, EnergySwordComponent comp, UseInHandEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Handled) return;
|
|
|
|
|
|
|
|
|
|
args.Handled = true;
|
|
|
|
|
|
|
|
|
|
if (comp.Activated)
|
|
|
|
|
{
|
|
|
|
|
TurnOff(comp);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TurnOn(comp);
|
|
|
|
|
}
|
2022-04-16 17:11:48 +12:00
|
|
|
|
|
|
|
|
UpdateAppearance(comp);
|
2022-01-24 09:55:48 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TurnOff(EnergySwordComponent comp)
|
|
|
|
|
{
|
|
|
|
|
if (!comp.Activated)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-07-27 03:53:47 -07:00
|
|
|
if (TryComp(comp.Owner, out ItemComponent? item))
|
2022-01-24 09:55:48 -03:00
|
|
|
{
|
2022-07-27 03:53:47 -07:00
|
|
|
_item.SetSize(comp.Owner, 5, item);
|
2022-01-24 09:55:48 -03:00
|
|
|
}
|
|
|
|
|
|
2022-06-17 01:37:07 -04:00
|
|
|
if (TryComp<DisarmMalusComponent>(comp.Owner, out var malus))
|
|
|
|
|
{
|
|
|
|
|
malus.Malus -= comp.litDisarmMalus;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-21 21:54:28 -03:00
|
|
|
if(TryComp<MeleeWeaponComponent>(comp.Owner, out var weaponComp))
|
2022-09-11 08:39:36 +02:00
|
|
|
{
|
2022-06-21 21:54:28 -03:00
|
|
|
weaponComp.HitSound = comp.OnHitOff;
|
2022-09-11 08:39:36 +02:00
|
|
|
if (comp.Secret)
|
|
|
|
|
weaponComp.HideFromExamine = true;
|
|
|
|
|
}
|
2022-06-21 21:54:28 -03:00
|
|
|
|
2022-08-16 02:57:39 -07:00
|
|
|
if (comp.IsSharp)
|
|
|
|
|
RemComp<SharpComponent>(comp.Owner);
|
2022-06-21 21:54:28 -03:00
|
|
|
|
2022-06-12 19:45:47 -04:00
|
|
|
SoundSystem.Play(comp.DeActivateSound.GetSound(), Filter.Pvs(comp.Owner, entityManager: EntityManager), comp.Owner);
|
2022-01-24 09:55:48 -03:00
|
|
|
|
|
|
|
|
comp.Activated = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TurnOn(EnergySwordComponent comp)
|
|
|
|
|
{
|
|
|
|
|
if (comp.Activated)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-07-27 03:53:47 -07:00
|
|
|
if (TryComp(comp.Owner, out ItemComponent? item))
|
2022-01-24 09:55:48 -03:00
|
|
|
{
|
2022-07-27 03:53:47 -07:00
|
|
|
_item.SetSize(comp.Owner, 9999, item);
|
2022-01-24 09:55:48 -03:00
|
|
|
}
|
|
|
|
|
|
2022-08-16 02:57:39 -07:00
|
|
|
if (comp.IsSharp)
|
|
|
|
|
EnsureComp<SharpComponent>(comp.Owner);
|
2022-06-21 21:54:28 -03:00
|
|
|
|
|
|
|
|
if(TryComp<MeleeWeaponComponent>(comp.Owner, out var weaponComp))
|
2022-09-11 08:39:36 +02:00
|
|
|
{
|
2022-06-21 21:54:28 -03:00
|
|
|
weaponComp.HitSound = comp.OnHitOn;
|
2022-09-11 08:39:36 +02:00
|
|
|
if (comp.Secret)
|
|
|
|
|
weaponComp.HideFromExamine = false;
|
|
|
|
|
}
|
2022-06-21 21:54:28 -03:00
|
|
|
|
2022-06-12 19:45:47 -04:00
|
|
|
SoundSystem.Play(comp.ActivateSound.GetSound(), Filter.Pvs(comp.Owner, entityManager: EntityManager), comp.Owner);
|
2022-01-24 09:55:48 -03:00
|
|
|
|
2022-06-17 01:37:07 -04:00
|
|
|
if (TryComp<DisarmMalusComponent>(comp.Owner, out var malus))
|
|
|
|
|
{
|
|
|
|
|
malus.Malus += comp.litDisarmMalus;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-24 09:55:48 -03:00
|
|
|
comp.Activated = true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-16 17:11:48 +12:00
|
|
|
private void UpdateAppearance(EnergySwordComponent component)
|
2022-01-24 09:55:48 -03:00
|
|
|
{
|
2022-04-16 17:11:48 +12:00
|
|
|
if (!TryComp(component.Owner, out AppearanceComponent? appearanceComponent))
|
|
|
|
|
return;
|
2022-01-24 09:55:48 -03:00
|
|
|
|
2022-04-16 17:11:48 +12:00
|
|
|
appearanceComponent.SetData(ToggleableLightVisuals.Enabled, component.Activated);
|
|
|
|
|
appearanceComponent.SetData(ToggleableLightVisuals.Color, component.BladeColor);
|
2022-01-24 09:55:48 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnInteractUsing(EntityUid uid, EnergySwordComponent comp, InteractUsingEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Handled) return;
|
|
|
|
|
|
|
|
|
|
if (!TryComp(args.Used, out ToolComponent? tool) || !tool.Qualities.ContainsAny("Pulsing")) return;
|
|
|
|
|
|
|
|
|
|
args.Handled = true;
|
2022-04-16 17:11:48 +12:00
|
|
|
comp.Hacked = !comp.Hacked;
|
|
|
|
|
|
|
|
|
|
if (comp.Hacked)
|
|
|
|
|
{
|
|
|
|
|
var rgb = EnsureComp<RgbLightControllerComponent>(uid);
|
|
|
|
|
_rgbSystem.SetCycleRate(uid, comp.CycleRate, rgb);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
RemComp<RgbLightControllerComponent>(uid);
|
2022-01-24 09:55:48 -03:00
|
|
|
}
|
2022-09-03 12:50:38 +02:00
|
|
|
private void OnIsHotEvent(EntityUid uid, EnergySwordComponent energySword, IsHotEvent args)
|
|
|
|
|
{
|
|
|
|
|
args.IsHot = energySword.Activated;
|
|
|
|
|
}
|
2022-01-24 09:55:48 -03:00
|
|
|
}
|
|
|
|
|
}
|