Skip to content

Commit

Permalink
unshaded thrall's eyes & change thrall owner when real died
Browse files Browse the repository at this point in the history
  • Loading branch information
Doublechest committed Jul 30, 2024
1 parent 6466a81 commit 10534a6
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 12 deletions.
25 changes: 25 additions & 0 deletions Content.Client/Stories/Shadowling/ShadowlingSystem.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,45 @@
using Content.Shared.Humanoid;
using Content.Shared.StatusIcon.Components;
using Content.Shared.Stories.Conversion;
using Content.Shared.Stories.Shadowling;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.Prototypes;

namespace Content.Client.Stories.Shadowling;

public sealed partial class ShadowlingSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _prototype = default!;
private readonly ProtoId<ShaderPrototype> _unshadedShaderProtoId = "unshaded";
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<ShadowlingComponent, GetStatusIconsEvent>(OnGetStatusIconsEvent);

// TODO: Использовать события ConvertedEvent, RevertedEvent. Сейчас они только на сервере.
SubscribeLocalEvent<ShadowlingThrallComponent, ComponentInit>(OnConverted);
SubscribeLocalEvent<ShadowlingThrallComponent, ComponentShutdown>(OnReverted);
}
private void OnGetStatusIconsEvent(EntityUid uid, ShadowlingComponent component, ref GetStatusIconsEvent args)
{
args.StatusIcons.Add(_prototype.Index(component.StatusIcon));
}
private void OnConverted(EntityUid uid, ShadowlingThrallComponent component, ComponentInit args)
{
if (!HasComp<HumanoidAppearanceComponent>(uid))
return;

var sprite = Comp<SpriteComponent>(uid);
sprite.LayerSetShader(sprite.LayerMapReserveBlank(HumanoidVisualLayers.Eyes), _prototype.Index(_unshadedShaderProtoId).Instance());
}
private void OnReverted(EntityUid uid, ShadowlingThrallComponent component, ComponentShutdown args)
{
if (!HasComp<HumanoidAppearanceComponent>(uid))
return;

var sprite = Comp<SpriteComponent>(uid);
sprite.LayerSetShader(sprite.LayerMapReserveBlank(HumanoidVisualLayers.Eyes), (ShaderInstance?) null);
}
}
60 changes: 60 additions & 0 deletions Content.Server/Stories/GameTicking/Rules/ShadowlingRuleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
using Content.Server.GameTicking;
using Robust.Shared.Console;
using Content.Server.Nuke;
using Content.Server.Stories.Conversion;
using Content.Server.Stories.Shadowling;
using Content.Shared.Stories.Conversion;
using Robust.Shared.Random;
using System.Linq;
using Content.Server.Polymorph.Components;

namespace Content.Server.Stories.GameTicking.Rules;

Expand All @@ -58,10 +64,64 @@ public sealed class ShadowlingRuleSystem : GameRuleSystem<ShadowlingRuleComponen
[Dependency] private readonly StationSystem _stationSystem = default!;
[Dependency] private readonly NukeSystem _nuke = default!;
[Dependency] private readonly AudioSystem _audio = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ConversionSystem _conversion = default!;
[Dependency] private readonly ShadowlingSystem _shadowling = default!;

[ValidatePrototypeId<ConversionPrototype>]
public const string ShadowlingThrallConversion = "ShadowlingThrall";

/// <summary>
/// Шанс того, что слуга просто расконвертируется, вместо передачи.
/// </summary>
public const float ShadowlingThrallProbOfLost = 0.5f;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ShadowlingWorldAscendanceEvent>(OnWorldAscendance);
SubscribeLocalEvent<ShadowlingComponent, MobStateChangedEvent>(OnMobStateChanged);
}
private void OnMobStateChanged(EntityUid uid, ShadowlingComponent comp, MobStateChangedEvent args)
{
if (args.NewMobState != MobState.Dead)
return;

var query = QueryActiveRules();
while (query.MoveNext(out var ruleUid, out _, out var _, out _))
{
// FIXME: Плохой код.

HashSet<EntityUid> shadowlings = new();
var shadowlingsQuery = AllEntityQuery<ShadowlingComponent, MobStateComponent>();
while (shadowlingsQuery.MoveNext(out var shadowlingUid, out _, out var mobState))
if (_mobState.IsAlive(shadowlingUid, mobState))
shadowlings.Add(shadowlingUid);

shadowlings.ExceptWith(_antag.GetAliveAntags(ruleUid).ToHashSet());

if (shadowlings.Count == 0)
{
foreach (var ent in _conversion.GetEntitiesConvertedBy(uid, ShadowlingThrallConversion))
{
_conversion.TryRevert(ent, ShadowlingThrallConversion);
}
continue;
}

var shadowling = _random.Pick(shadowlings);

foreach (var ent in _conversion.GetEntitiesConvertedBy(uid, ShadowlingThrallConversion))
{
if (_random.Prob(ShadowlingThrallProbOfLost))
_conversion.TryRevert(ent, ShadowlingThrallConversion);
else if (_conversion.TryGetConversion(ent, ShadowlingThrallConversion, out var conversion))
{
conversion.Owner = GetNetEntity(shadowling);
}
}

_shadowling.RefreshActions(shadowling);
}
}
private void CheckWin()
{
Expand Down
13 changes: 1 addition & 12 deletions Content.Server/Stories/Shadowling/ShadowlingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public sealed partial class ShadowlingSystem : EntitySystem
[Dependency] private readonly FlashSystem _flash = default!;
[Dependency] private readonly StunSystem _stun = default!;
[Dependency] private readonly SharedSolutionContainerSystem _solution = default!;
public readonly Color ThrallEyeColor = Color.Red;
public override void Initialize()
{
base.Initialize();
Expand All @@ -70,16 +69,6 @@ public override void Initialize()
SubscribeLocalEvent<ShadowlingComponent, ShotAttemptedEvent>(OnShotAttempted);
SubscribeLocalEvent<ShadowlingThrallComponent, ConvertedEvent>(OnThrallConverted);
SubscribeLocalEvent<ShadowlingThrallComponent, RevertedEvent>(OnThrallReverted);

SubscribeLocalEvent<ShadowlingComponent, MobStateChangedEvent>(OnMobStateChanged);
}
private void OnMobStateChanged(EntityUid uid, ShadowlingComponent comp, MobStateChangedEvent args)
{
if (args.NewMobState == MobState.Dead)
foreach (var ent in _conversion.GetEntitiesConvertedBy(uid, ShadowlingThrallConversion))
{
_conversion.TryRevert(ent, ShadowlingThrallConversion);
}
}
private void OnShotAttempted(EntityUid uid, ShadowlingComponent comp, ref ShotAttemptedEvent args)
{
Expand All @@ -94,7 +83,7 @@ private void OnThrallConverted(EntityUid uid, ShadowlingThrallComponent comp, Co
if (TryComp<HumanoidAppearanceComponent>(uid, out var appearance))
{
comp.OldEyeColor = appearance.EyeColor;
appearance.EyeColor = ThrallEyeColor;
appearance.EyeColor = comp.EyeColor;
Dirty(uid, appearance);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ public sealed partial class ShadowlingThrallComponent : Component
{
[DataField]
public Color OldEyeColor = Color.Black;

[DataField]
public Color EyeColor = Color.Red;
}

0 comments on commit 10534a6

Please sign in to comment.