mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-18 22:18:52 +03:00
Lots of stuff. Also moved everything I could to the _Shitmed namespace
as I do in Goob. Will make future ports way faster
# Changelog
🆑 Mocho
- add: Added some fun organs and other thingies, check out the Goob PRs
if you want more details.
- fix: Fixed tons of issues with shitmed. Too many for the changelog in
fact.
(cherry picked from commit 3c9db94102cb25b28a83d51ac8d659fa31fe7d12)
110 lines
3.7 KiB
C#
110 lines
3.7 KiB
C#
// We keep this clone of the other system since I don't know yet if I'll need organ specific functions in the future.
|
|
// will delete or refactor as time goes on.
|
|
using Content.Shared._Shitmed.Body.Organ;
|
|
using Content.Shared.Body.Organ;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Serialization.Manager;
|
|
using Robust.Shared.Timing;
|
|
using System.Linq;
|
|
using Robust.Shared.Network;
|
|
|
|
|
|
namespace Content.Shared._Shitmed.BodyEffects;
|
|
public partial class OrganEffectSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IComponentFactory _compFactory = default!;
|
|
[Dependency] private readonly ISerializationManager _serManager = default!;
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
[Dependency] private readonly INetManager _net = default!;
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<OrganComponent, OrganComponentsModifyEvent>(OnOrganComponentsModify);
|
|
}
|
|
|
|
// While I would love to kill this function, problem is that if we happen to have two parts that add the same
|
|
// effect, removing one will remove both of them, since we cant tell what the source of a Component is.
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
|
|
if (!_net.IsServer) // TODO: Kill this once I figure out whats breaking the Diagnostic Cybernetics.
|
|
return;
|
|
|
|
var query = EntityQueryEnumerator<OrganEffectComponent, OrganComponent>();
|
|
var now = _gameTiming.CurTime;
|
|
while (query.MoveNext(out var uid, out var comp, out var part))
|
|
{
|
|
if (now < comp.NextUpdate || !comp.Active.Any() || part.Body is not { } body)
|
|
continue;
|
|
|
|
comp.NextUpdate = now + comp.Delay;
|
|
AddComponents(body, uid, comp.Active);
|
|
}
|
|
}
|
|
|
|
private void OnOrganComponentsModify(Entity<OrganComponent> organEnt,
|
|
ref OrganComponentsModifyEvent ev)
|
|
{
|
|
if (!_net.IsServer) // TODO: Kill this once I figure out whats breaking the Diagnostic Cybernetics.
|
|
return;
|
|
|
|
if (organEnt.Comp.OnAdd != null)
|
|
{
|
|
if (ev.Add)
|
|
AddComponents(ev.Body, organEnt, organEnt.Comp.OnAdd);
|
|
else
|
|
RemoveComponents(ev.Body, organEnt, organEnt.Comp.OnAdd);
|
|
}
|
|
|
|
if (organEnt.Comp.OnRemove != null)
|
|
{
|
|
if (ev.Add)
|
|
RemoveComponents(ev.Body, organEnt, organEnt.Comp.OnRemove);
|
|
else
|
|
AddComponents(ev.Body, organEnt, organEnt.Comp.OnRemove);
|
|
}
|
|
}
|
|
|
|
private void AddComponents(EntityUid body,
|
|
EntityUid part,
|
|
ComponentRegistry reg,
|
|
OrganEffectComponent? effectComp = null)
|
|
{
|
|
if (!Resolve(part, ref effectComp, logMissing: false))
|
|
return;
|
|
|
|
foreach (var (key, comp) in reg)
|
|
{
|
|
var compType = comp.Component.GetType();
|
|
if (HasComp(body, compType))
|
|
continue;
|
|
|
|
var newComp = (Component) _serManager.CreateCopy(comp.Component, notNullableOverride: true);
|
|
newComp.Owner = body;
|
|
EntityManager.AddComponent(body, newComp, true);
|
|
effectComp.Active[key] = comp;
|
|
if (newComp.NetSyncEnabled)
|
|
{
|
|
Dirty(body, newComp);
|
|
Dirty(part, effectComp);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void RemoveComponents(EntityUid body,
|
|
EntityUid part,
|
|
ComponentRegistry reg,
|
|
OrganEffectComponent? effectComp = null)
|
|
{
|
|
if (!Resolve(part, ref effectComp, logMissing: false))
|
|
return;
|
|
|
|
foreach (var (key, comp) in reg)
|
|
{
|
|
RemComp(body, comp.Component.GetType());
|
|
effectComp.Active.Remove(key);
|
|
}
|
|
}
|
|
} |