Files
crystall-punk-14/Content.Shared/Ninja/Systems/EnergyKatanaSystem.cs

148 lines
5.2 KiB
C#
Raw Normal View History

[Antag] add space ninja as midround antag (#14069) * start of space ninja midround antag * suit has powercell, can be upgraded only (not replaced with equal or worse battery) * add doorjacking to ninja gloves, power cell, doorjack objective (broken), tweaks * :skull: * add basic suit power display that uses stamina rsi * add draining apc/sub/smes - no wires yet * add research downloading * ninja starts implanted, move some stuff to yaml * add Automated field to OnUseTimerTrigger * implement spider charge and objective * fix client crash when taking suit off, some refactor * add survive condition and tweak locale * add comms console icon for objective * add calling in a threat - currently revenant and dragon * combine all glove abilities * locale * spark sounds when draining, refactoring * toggle is actually toggle now * prevent crash if disabling stealth with outline * add antag ctrl for ninja, hopefully show greentext * fix greentext and some other things * disabling gloves if taken off or suit taken off * basic energy katana, change ninja loadout * recallable katana, refactoring * start of dash - not done yet * katana dashing ability * merge upstream + compiling, make AutomatedTimer its own component * docs and stuff * partial refactor of glove abilities, still need to move handling * make dooremaggedevent by ref * move bunch of stuff to shared - broken * clean ninja antag verb * doc * mark rule config fields as required * fix client crash * wip systems refactor * big refactor of systems * fuck * make TryDoElectrocution callable from shared * finish refactoring? * no guns * start with internals on * clean up glove abilities, add range check * create soap, in place of ninja throwing stars * add emp suit ability * able to eat chefs stolen food in space * stuff, tell client when un/cloaked but there is bug with gloves * fix prediction breaking gloves on client * ninja soap despawns after a minute * ninja spawns outside the station now, with gps + station coords to navigate * add cooldown to stun ability * cant use glove abilities in combat mode * require empty hand to use glove abilities * use ghost role spawner * Update Content.Server/Ninja/Systems/NinjaSuitSystem.cs Co-authored-by: keronshb <54602815+keronshb@users.noreply.github.com> * some review changes * show powercell charge on examine * new is needed * address some reviews * ninja starts with jetpack, i hope * partial feedback * uhh * pro * remove pirate from threats list * use doafter refactor * pro i gave skeleton jetpack * some stuff * use auto gen state * mr handy * use EntityQueryEnumerator * cleanup * spider charge target anti-troll * mmmmmm --------- Co-authored-by: deltanedas <deltanedas@laptop> Co-authored-by: deltanedas <user@zenith> Co-authored-by: deltanedas <@deltanedas:kde.org> Co-authored-by: keronshb <54602815+keronshb@users.noreply.github.com>
2023-04-17 07:33:27 +00:00
using Content.Shared.Examine;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
using Content.Shared.Inventory.Events;
using Content.Shared.Ninja.Components;
using Content.Shared.Physics;
using Content.Shared.Popups;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.Timing;
namespace Content.Shared.Ninja.Systems;
/// <summary>
/// System for katana dashing, recharging and what not.
/// </summary>
// TODO: move all recharging stuff into its own system and use for emag too
public sealed class EnergyKatanaSystem : EntitySystem
{
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedHandsSystem _hands = default!;
[Dependency] private readonly SharedInteractionSystem _interaction = default!;
[Dependency] private readonly SharedNinjaSystem _ninja = default!;
[Dependency] private readonly SharedPopupSystem _popups = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<EnergyKatanaComponent, GotEquippedEvent>(OnEquipped);
SubscribeLocalEvent<EnergyKatanaComponent, ExaminedEvent>(OnExamine);
SubscribeLocalEvent<NinjaSuitComponent, KatanaDashEvent>(OnDash);
SubscribeLocalEvent<EnergyKatanaComponent, EntityUnpausedEvent>(OnUnpaused);
}
private void OnEquipped(EntityUid uid, EnergyKatanaComponent comp, GotEquippedEvent args)
{
// check if already bound
if (comp.Ninja != null)
return;
// check if ninja already has a katana bound
var user = args.Equipee;
if (!TryComp<NinjaComponent>(user, out var ninja) || ninja.Katana != null)
return;
// bind it
comp.Ninja = user;
_ninja.BindKatana(ninja, uid);
}
private void OnUnpaused(EntityUid uid, EnergyKatanaComponent component, ref EntityUnpausedEvent args)
{
component.NextChargeTime += args.PausedTime;
}
private void OnExamine(EntityUid uid, EnergyKatanaComponent component, ExaminedEvent args)
{
args.PushMarkup(Loc.GetString("emag-charges-remaining", ("charges", component.Charges)));
if (component.Charges == component.MaxCharges)
{
args.PushMarkup(Loc.GetString("emag-max-charges"));
return;
}
var timeRemaining = Math.Round((component.NextChargeTime - _timing.CurTime).TotalSeconds);
args.PushMarkup(Loc.GetString("emag-recharging", ("seconds", timeRemaining)));
}
// TODO: remove and use LimitedCharges+AutoRecharge
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (var comp in EntityQuery<EnergyKatanaComponent>())
{
if (!comp.AutoRecharge)
continue;
if (comp.Charges == comp.MaxCharges)
continue;
if (_timing.CurTime < comp.NextChargeTime)
continue;
ChangeCharge(comp.Owner, 1, true, comp);
}
}
public void OnDash(EntityUid suit, NinjaSuitComponent comp, KatanaDashEvent args)
{
var user = args.Performer;
args.Handled = true;
if (!TryComp<NinjaComponent>(user, out var ninja) || ninja.Katana == null)
return;
var uid = ninja.Katana.Value;
if (!TryComp<EnergyKatanaComponent>(uid, out var katana) || !_hands.IsHolding(user, uid, out var _))
{
_popups.PopupEntity(Loc.GetString("ninja-katana-not-held"), user, user);
return;
}
if (katana.Charges <= 0)
{
_popups.PopupEntity(Loc.GetString("emag-no-charges"), user, user);
return;
}
// TODO: check that target is not dense
var origin = Transform(user).MapPosition;
var target = args.Target.ToMap(EntityManager, _transform);
// prevent collision with the user duh
if (!_interaction.InRangeUnobstructed(origin, target, 0f, CollisionGroup.Opaque, uid => uid == user))
{
// can only dash if the destination is visible on screen
_popups.PopupEntity(Loc.GetString("ninja-katana-cant-see"), user, user);
return;
}
_transform.SetCoordinates(user, args.Target);
_transform.AttachToGridOrMap(user);
_audio.PlayPvs(katana.BlinkSound, user, AudioParams.Default.WithVolume(katana.BlinkVolume));
// TODO: show the funny green man thing
ChangeCharge(uid, -1, false, katana);
}
/// <summary>
/// Changes the charge on an energy katana.
/// </summary>
public bool ChangeCharge(EntityUid uid, int change, bool resetTimer, EnergyKatanaComponent? katana = null)
{
if (!Resolve(uid, ref katana))
return false;
if (katana.Charges + change < 0 || katana.Charges + change > katana.MaxCharges)
return false;
if (resetTimer || katana.Charges == katana.MaxCharges)
katana.NextChargeTime = _timing.CurTime + katana.RechargeDuration;
katana.Charges += change;
Dirty(katana);
return true;
}
}