Files
crystall-punk-14/Content.Server/_CP14/DPSMeter/CP14DPSMeterSystem.cs
Ed 109edeb4b5 Modular weapon crafting WIP (#611)
* data initalizing

* modular assembling

* grips and blades sprites

* first prototypes

* jewerly decoration

* disassemble modular weapon

* grip start stats

* blade modifiers

* inhand sprites generation

* resprites inhand, add sickle, add attempt modify size

* auto inhand sprite parsing

* icon default parsing

* spear blade

* mace ball

* sword blade

* sharedization + autonetwork hotswipe

* wielding sprite support!

* iron long grip

* wielded sickle, fix ERROR sprite if state not added

* Update grips.yml

* wielded spear + ruby rework

* wielding damage bonus modifier

* modular size fix

* fix storedOffset rotation

* parts offset

* fix inheriting modifiers

* some bugfix and balance tweaks

* DPS Meter

* fix dividing by zero

* rebalance

* replace baseknife to modular knife. Delete ice knife spell

* sickle and mace modular replace

* modular spear & sword replacement. add wielded icons

* Update CP14DPSMeterSystem.cs

* back to serverization

* grip disassemble drop again

* clothing sprite generation code

* back slot long grips and mace

* remove jewerly slot, add more clothing states

* finish clothing states

* shovel modular

* YEEEEE

* anvil modular craft

* bugfixes

* more integration check fixes
2024-11-29 01:31:42 +03:00

63 lines
1.9 KiB
C#

using Content.Shared.Damage;
using Content.Shared.FixedPoint;
using Content.Shared.Popups;
using Robust.Shared.Timing;
namespace Content.Server._CP14.DPSMeter;
public sealed class CP14DPSMeterSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<CP14DPSMeterComponent, DamageChangedEvent>(OnDamageChanged);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
var query = EntityQueryEnumerator<CP14DPSMeterComponent>();
while (query.MoveNext(out var uid, out var meter))
{
if (_timing.CurTime < meter.EndTrackTime || meter.EndTrackTime == TimeSpan.Zero)
continue;
//Clear tracking
_popup.PopupEntity($"TOTAL DPS: {GetDPS((uid, meter))}", uid, PopupType.Large);
meter.TotalDamage = new DamageSpecifier();
meter.EndTrackTime = TimeSpan.Zero;
meter.StartTrackTime = TimeSpan.Zero;
}
}
private void OnDamageChanged(Entity<CP14DPSMeterComponent> ent, ref DamageChangedEvent args)
{
if (args.DamageDelta is null)
return;
ent.Comp.TotalDamage += args.DamageDelta;
if (ent.Comp.StartTrackTime == TimeSpan.Zero)
ent.Comp.StartTrackTime = _timing.CurTime;
ent.Comp.LastHitTime = _timing.CurTime;
ent.Comp.EndTrackTime = _timing.CurTime + ent.Comp.TrackTimeAfterHit;
_popup.PopupEntity($"DPS: {GetDPS(ent)}", ent);
}
private FixedPoint2 GetDPS(Entity<CP14DPSMeterComponent> ent)
{
var totalDamage = ent.Comp.TotalDamage.GetTotal();
var totalSeconds = (ent.Comp.LastHitTime - ent.Comp.StartTrackTime).TotalSeconds;
var DPS = totalDamage / Math.Max(totalSeconds, 1f);
return DPS;
}
}