Skip to content

Commit

Permalink
cleanup (#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rxup authored Mar 4, 2024
1 parent a1ae51f commit 9df43e3
Show file tree
Hide file tree
Showing 50 changed files with 645 additions and 564 deletions.
11 changes: 11 additions & 0 deletions Content.Client/Backmen/Blob/BlobCarrierSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Content.Shared.Backmen.Blob;

namespace Content.Client.Backmen.Blob;

public sealed class BlobCarrierSystem : SharedBlobCarrierSystem
{
protected override void TransformToBlob(Entity<BlobCarrierComponent> ent)
{
// do nothing
}
}
8 changes: 8 additions & 0 deletions Content.Client/Backmen/Blob/BlobCoreSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Content.Shared.Backmen.Blob;

namespace Content.Client.Backmen.Blob;

public sealed class BlobCoreSystem : SharedBlobCoreSystem
{

}
9 changes: 0 additions & 9 deletions Content.Client/Backmen/Blob/BlobTileComponent.cs

This file was deleted.

43 changes: 29 additions & 14 deletions Content.Client/Backmen/Blob/BlobTileSystem.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,53 @@
using Content.Client.DamageState;
using Content.Shared.Backmen.Blob;
using Content.Shared.Backmen.Blob.Components;
using Robust.Client.GameObjects;
using Robust.Shared.GameStates;

namespace Content.Client.Backmen.Blob;

public sealed class BlobTileSystem : EntitySystem
public sealed class BlobTileSystem : SharedBlobTileSystem
{
public override void Initialize()
protected override void TryRemove(EntityUid target, EntityUid coreUid, BlobTileComponent tile, BlobCoreComponent core)
{
base.Initialize();
SubscribeLocalEvent<BlobTileComponent, ComponentHandleState>(OnBlobTileHandleState);
// do nothing on client
}

private void OnBlobTileHandleState(EntityUid uid, BlobTileComponent component, ref ComponentHandleState args)
protected override void TryUpgrade(EntityUid target, EntityUid user, EntityUid coreUid, BlobTileComponent tile, BlobCoreComponent core)
{
if (args.Current is not BlobTileComponentState state)
return;

if (component.Color == state.Color)
return;
// do nothing on client
}
}

component.Color = state.Color;
TryComp<SpriteComponent>(uid, out var sprite);
public sealed class BlobTileVisualizerSystem : VisualizerSystem<BlobTileComponent>
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BlobTileComponent, AfterAutoHandleStateEvent>(OnBlobTileHandleState);
}

if (sprite == null)
private void UpdateAppearance(EntityUid id, BlobTileComponent tile, AppearanceComponent? appearance = null, SpriteComponent? sprite = null)
{
if (!Resolve(id, ref appearance, ref sprite))
return;

foreach (var key in new []{ DamageStateVisualLayers.Base, DamageStateVisualLayers.BaseUnshaded })
{
if (!sprite.LayerMapTryGet(key, out _))
continue;

sprite.LayerSetColor(key, component.Color);
sprite.LayerSetColor(key, tile.Color);
}
}

protected override void OnAppearanceChange(EntityUid uid, BlobTileComponent component, ref AppearanceChangeEvent args)
{
UpdateAppearance(uid, component, args.Component, args.Sprite);
}

private void OnBlobTileHandleState(EntityUid uid, BlobTileComponent component, ref AfterAutoHandleStateEvent args)
{
UpdateAppearance(uid, component);
}
}
9 changes: 0 additions & 9 deletions Content.Client/Backmen/Blob/BlobbernautComponent.cs

This file was deleted.

44 changes: 29 additions & 15 deletions Content.Client/Backmen/Blob/BlobbernautSystem.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,53 @@
using System.Linq;
using Content.Client.DamageState;
using Content.Shared.Backmen.Blob;
using Content.Shared.Backmen.Blob.Components;
using Content.Shared.Damage;
using Content.Shared.Popups;
using Robust.Client.GameObjects;
using Robust.Shared.GameStates;

namespace Content.Client.Backmen.Blob;

public sealed class BlobbernautSystem : EntitySystem
public sealed class BlobbernautSystem : SharedBlobbernautSystem
{
[Dependency] private readonly SharedPopupSystem _popup = default!;
protected override DamageSpecifier? TryChangeDamage(string msg, EntityUid ent, DamageSpecifier dmg)
{
_popup.PopupClient(Loc.GetString(msg), ent, ent, PopupType.LargeCaution);
return null;
}
}

public sealed class BlobbernautVisualizerSystem : VisualizerSystem<BlobbernautComponent>
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BlobbernautComponent, ComponentHandleState>(OnBlobTileHandleState);
SubscribeLocalEvent<BlobbernautComponent, AfterAutoHandleStateEvent>(OnBlobTileHandleState);
}

private void OnBlobTileHandleState(EntityUid uid, BlobbernautComponent component, ref ComponentHandleState args)
private void UpdateAppearance(EntityUid id, BlobbernautComponent blobbernaut, AppearanceComponent? appearance = null, SpriteComponent? sprite = null)
{
if (args.Current is not BlobbernautComponentState state)
return;

if (component.Color == state.Color)
return;

component.Color = state.Color;
TryComp<SpriteComponent>(uid, out var sprite);

if (sprite == null)
if (!Resolve(id, ref appearance, ref sprite))
return;

foreach (var key in new []{ DamageStateVisualLayers.Base })
foreach (var key in new []{ DamageStateVisualLayers.Base, DamageStateVisualLayers.BaseUnshaded })
{
if (!sprite.LayerMapTryGet(key, out _))
continue;

sprite.LayerSetColor(key, component.Color);
sprite.LayerSetColor(key, blobbernaut.Color);
}
}

protected override void OnAppearanceChange(EntityUid uid, BlobbernautComponent component, ref AppearanceChangeEvent args)
{
UpdateAppearance(uid, component, args.Component, args.Sprite);
}

private void OnBlobTileHandleState(EntityUid uid, BlobbernautComponent component, ref AfterAutoHandleStateEvent args)
{
UpdateAppearance(uid, component);
}
}
66 changes: 15 additions & 51 deletions Content.Server/Backmen/Blob/BlobCarrierSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Server.Actions;
using Content.Server.Backmen.Blob.Components;
using Content.Server.Body.Systems;
using Content.Server.Ghost.Roles.Components;
using Content.Server.Mind;
Expand All @@ -7,22 +8,18 @@
using Content.Shared.Mobs;
using Content.Shared.Popups;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;

namespace Content.Server.Backmen.Blob;

public sealed class BlobCarrierSystem : EntitySystem
public sealed class BlobCarrierSystem : SharedBlobCarrierSystem
{
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly BlobCoreSystem _blobCoreSystem = default!;
[Dependency] private readonly MindSystem _mind = default!;
[Dependency] private readonly BodySystem _bodySystem = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly ActionsSystem _action = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;


public override void Initialize()
{
Expand All @@ -32,7 +29,6 @@ public override void Initialize()
SubscribeLocalEvent<BlobCarrierComponent, TransformToBlobActionEvent>(OnTransformToBlobChanged);

SubscribeLocalEvent<BlobCarrierComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<BlobCarrierComponent, ComponentShutdown>(OnShutdown);

SubscribeLocalEvent<BlobCarrierComponent, MindAddedMessage>(OnMindAdded);
SubscribeLocalEvent<BlobCarrierComponent, MindRemovedMessage>(OnMindRemove);
Expand All @@ -51,14 +47,14 @@ private void OnMindRemove(EntityUid uid, BlobCarrierComponent component, MindRem
component.HasMind = false;
}

private void OnTransformToBlobChanged(EntityUid uid, BlobCarrierComponent component, TransformToBlobActionEvent args)
private void OnTransformToBlobChanged(Entity<BlobCarrierComponent> uid, ref TransformToBlobActionEvent args)
{
TransformToBlob(uid, component);
TransformToBlob(uid);
}

private void OnStartup(EntityUid uid, BlobCarrierComponent component, ComponentStartup args)
{
_action.AddAction(uid, ref component.TransformToBlob ,ActionTransformToBlob);
_action.AddAction(uid, ref component.TransformToBlob, ActionTransformToBlob);

var ghostRole = EnsureComp<GhostRoleComponent>(uid);
EnsureComp<GhostTakeoverAvailableComponent>(uid);
Expand All @@ -69,28 +65,23 @@ private void OnStartup(EntityUid uid, BlobCarrierComponent component, ComponentS
EnsureComp<BlobSpeakComponent>(uid);
}

private void OnShutdown(EntityUid uid, BlobCarrierComponent component, ComponentShutdown args)
{

}

private void OnMobStateChanged(EntityUid uid, BlobCarrierComponent component, MobStateChangedEvent args)
private void OnMobStateChanged(Entity<BlobCarrierComponent> uid, ref MobStateChangedEvent args)
{
if (args.NewMobState == MobState.Dead)
{
TransformToBlob(uid, component);
TransformToBlob(uid);
}
}

private void TransformToBlob(EntityUid uid, BlobCarrierComponent carrier)
protected override void TransformToBlob(Entity<BlobCarrierComponent> ent)
{
var xform = Transform(uid);
if (!_mapManager.TryGetGrid(xform.GridUid, out var map))
var xform = Transform(ent);
if (!HasComp<MapGridComponent>(xform.GridUid))
return;

if (_mind.TryGetMind(uid, out var mindId, out var mind) && mind.UserId != null)
if (_mind.TryGetMind(ent, out _, out var mind) && mind.UserId != null)
{
var core = Spawn(carrier.CoreBlobPrototype, xform.Coordinates);
var core = Spawn(ent.Comp.CoreBlobPrototype, xform.Coordinates);

if (!TryComp<BlobCoreComponent>(core, out var blobCoreComponent))
return;
Expand All @@ -99,36 +90,9 @@ private void TransformToBlob(EntityUid uid, BlobCarrierComponent carrier)
}
else
{
Spawn(carrier.CoreBlobGhostRolePrototype, xform.Coordinates);
Spawn(ent.Comp.CoreBlobGhostRolePrototype, xform.Coordinates);
}

_bodySystem.GibBody(uid);
}

public override void Update(float frameTime)
{
base.Update(frameTime);

var blobFactoryQuery = EntityQueryEnumerator<BlobCarrierComponent>();
while (blobFactoryQuery.MoveNext(out var ent, out var comp))
{
if (!comp.HasMind)
return;

comp.TransformationTimer += frameTime;

if (_gameTiming.CurTime < comp.NextAlert)
continue;

var remainingTime = Math.Round(comp.TransformationDelay - comp.TransformationTimer, 0);
_popup.PopupEntity(Loc.GetString("carrier-blob-alert", ("second", remainingTime)), ent, ent, PopupType.LargeCaution);

comp.NextAlert = _gameTiming.CurTime + TimeSpan.FromSeconds(comp.AlertInterval);

if (!(comp.TransformationTimer >= comp.TransformationDelay))
continue;

TransformToBlob(ent, comp);
}
_bodySystem.GibBody(ent);
}
}
Loading

0 comments on commit 9df43e3

Please sign in to comment.