Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ngines into EE-Andromeda
  • Loading branch information
LaryNevesPR committed Jan 11, 2025
2 parents 1e8dd81 + 3b5303c commit 9a6a1c2
Show file tree
Hide file tree
Showing 272 changed files with 15,979 additions and 22,072 deletions.
5 changes: 5 additions & 0 deletions Content.Client/Materials/MaterialSiloSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using Content.Shared.Materials;

namespace Content.Client.Materials;

public sealed class MaterialSiloSystem : SharedMaterialSiloSystem;
3 changes: 2 additions & 1 deletion Content.Client/Materials/MaterialStorageSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ public override bool TryInsertMaterialEntity(EntityUid user,
EntityUid toInsert,
EntityUid receiver,
MaterialStorageComponent? storage = null,
MaterialSiloUtilizerComponent? utilizer = null,
MaterialComponent? material = null,
PhysicalCompositionComponent? composition = null)
{
if (!base.TryInsertMaterialEntity(user, toInsert, receiver, storage, material, composition))
if (!base.TryInsertMaterialEntity(user, toInsert, receiver, storage, utilizer, material, composition))
return false;
_transform.DetachParentToNull(toInsert, Transform(toInsert));
return true;
Expand Down
1 change: 1 addition & 0 deletions Content.Client/Materials/UI/MaterialStorageControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
HorizontalExpand="True"
VerticalExpand="True">
<BoxContainer Name="MaterialList" Orientation="Vertical">
<Label Name="ConnectToSiloLabel" Text="{Loc 'lathe-menu-connected-to-silo-message'}" Align="Center"/>
<Label Name="NoMatsLabel" Text="{Loc 'lathe-menu-no-materials-message'}" Align="Center"/>
</BoxContainer>
</ScrollContainer>
21 changes: 20 additions & 1 deletion Content.Client/Materials/UI/MaterialStorageControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public sealed partial class MaterialStorageControl : ScrollContainer
{
[Dependency] private readonly IEntityManager _entityManager = default!;

private readonly MaterialSiloSystem _materialSilo;

private EntityUid? _owner;

private Dictionary<string, int> _currentMaterials = new();
Expand All @@ -23,6 +25,8 @@ public MaterialStorageControl()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);

_materialSilo = _entityManager.System<MaterialSiloSystem>();
}

public void SetOwner(EntityUid owner)
Expand All @@ -44,7 +48,22 @@ protected override void FrameUpdate(FrameEventArgs args)
}

var canEject = materialStorage.CanEjectStoredMaterials;
var mats = materialStorage.Storage.Select(pair => (pair.Key.Id, pair.Value)).ToDictionary();

Dictionary<string, int> mats;
if (_entityManager.TryGetComponent<MaterialSiloUtilizerComponent>(_owner, out var utilizer) && utilizer.Silo.HasValue)
{
var silo = _materialSilo.GetSiloStorage(_owner.Value);
mats = silo != null
? silo.Value.Comp.Storage.Select(pair => (pair.Key.Id, pair.Value)).ToDictionary()
: materialStorage.Storage.Select(pair => (pair.Key.Id, pair.Value)).ToDictionary();
ConnectToSiloLabel.Visible = silo != null;
}
else
{
mats = materialStorage.Storage.Select(pair => (pair.Key.Id, pair.Value)).ToDictionary();
ConnectToSiloLabel.Visible = false;
}

if (_currentMaterials.Equals(mats))
return;

Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Body/Systems/InternalsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private void OnStartingGear(EntityUid uid, InternalsComponent component, ref Sta
return; // already connected

// Can the entity breathe the air it is currently exposed to?
if (_respirator.CanMetabolizeInhaledAir(uid))
if (!TryComp(uid, out RespiratorComponent? respirator) || _respirator.CanMetabolizeInhaledAir((uid, respirator)))
return;

var tank = FindBestGasTank(uid);
Expand Down
70 changes: 70 additions & 0 deletions Content.Server/Materials/MaterialSiloSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System.Linq;
using Content.Server.Lathe;
using Content.Server.Station.Components;
using Content.Shared.DeviceLinking;
using Content.Shared.Lathe;
using Content.Shared.Materials;
using Robust.Shared.Timing;

namespace Content.Server.Materials;

public sealed class MaterialSiloSystem : SharedMaterialSiloSystem
{
[Dependency] private readonly LatheSystem _lathe = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<BecomesStationComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<MaterialSiloComponent, MaterialAmountChangedEvent>(OnMaterialAmountChanged);
}

private void OnMaterialAmountChanged(Entity<MaterialSiloComponent> ent, ref MaterialAmountChangedEvent args)
{
// Spawning a timer because SetUiState in UpdateUserInterfaceState is being networked before
// silo's MaterialStorageComponent state gets handled.
// That causes lathe ui recipe list to not update properly.
Timer.Spawn(20,
() =>
{
if (!TryComp(ent, out DeviceLinkSourceComponent? source))
return;

foreach (var utilizerSet in source.Outputs.Where(x => x.Key == SourcePort).Select(x => x.Value))
{
foreach (var utilizer in utilizerSet)
{
if (TryComp(utilizer, out LatheComponent? lathe))
_lathe.UpdateUserInterfaceState(utilizer, lathe);
}
}
});
}

private void OnMapInit(Entity<BecomesStationComponent> ent, ref MapInitEvent args)
{
Entity<DeviceLinkSourceComponent>? silo = null;
var siloQuery = AllEntityQuery<MaterialSiloComponent, MaterialStorageComponent, TransformComponent, DeviceLinkSourceComponent>();
while (siloQuery.MoveNext(out var siloEnt, out _, out _, out var siloXform, out var source))
{
if (siloXform.GridUid != ent)
continue;

silo = (siloEnt, source);
break;
}

if (silo == null)
return;

var utilizerQuery = AllEntityQuery<MaterialSiloUtilizerComponent, MaterialStorageComponent, TransformComponent, DeviceLinkSinkComponent>();
while (utilizerQuery.MoveNext(out var utilizer, out _, out var storage, out var utilizerXform, out var sink))
{
if (utilizerXform.GridUid != ent)
continue;

DeviceLink.LinkDefaults(null, silo.Value, utilizer, silo.Value.Comp, sink);
}
}
}
17 changes: 11 additions & 6 deletions Content.Server/Materials/MaterialStorageSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ public override bool TryInsertMaterialEntity(EntityUid user,
EntityUid toInsert,
EntityUid receiver,
MaterialStorageComponent? storage = null,
MaterialSiloUtilizerComponent? utilizer = null,
MaterialComponent? material = null,
PhysicalCompositionComponent? composition = null)
{
if (!Resolve(receiver, ref storage) || !Resolve(toInsert, ref material, ref composition, false))
return false;
if (TryComp<ApcPowerReceiverComponent>(receiver, out var power) && !power.Powered)
return false;
if (!base.TryInsertMaterialEntity(user, toInsert, receiver, storage, material, composition))
if (!base.TryInsertMaterialEntity(user, toInsert, receiver, storage, utilizer, material, composition))
return false;
_audio.PlayPvs(storage.InsertingSound, receiver);
_popup.PopupEntity(Loc.GetString("machine-insert-item", ("user", user), ("machine", receiver),
Expand Down Expand Up @@ -187,26 +188,28 @@ public List<EntityUid> SpawnMultipleFromMaterial(int amount, MaterialPrototype m
/// <param name="maxAmount">The maximum amount to eject. If not given, as much as possible is ejected.</param>
/// <param name="coordinates">The position where to spawn the created sheets. If not given, they're spawned next to the entity.</param>
/// <param name="component">The storage component on <paramref name="entity"/>. Resolved automatically if not given.</param>
/// <param name="utilizer">The material silo utilizer component on <paramref name="uid"/>.</param>
/// <returns>The stack entities that were spawned.</returns>
public List<EntityUid> EjectMaterial(
EntityUid entity,
string material,
int? maxAmount = null,
EntityCoordinates? coordinates = null,
MaterialStorageComponent? component = null)
MaterialStorageComponent? component = null,
MaterialSiloUtilizerComponent? utilizer = null)
{
if (!Resolve(entity, ref component))
return new List<EntityUid>();

coordinates ??= Transform(entity).Coordinates;

var amount = GetMaterialAmount(entity, material, component);
var amount = GetMaterialAmount(entity, material, component, utilizer);
if (maxAmount != null)
amount = Math.Min(maxAmount.Value, amount);

var spawned = SpawnMultipleFromMaterial(amount, material, coordinates.Value, out var overflow);

TryChangeMaterialAmount(entity, material, -(amount - overflow), component);
TryChangeMaterialAmount(entity, material, -(amount - overflow), component, utilizer);
return spawned;
}

Expand All @@ -216,11 +219,13 @@ public List<EntityUid> EjectMaterial(
/// <param name="entity">The entity with storage to eject from.</param>
/// <param name="coordinates">The position where to spawn the created sheets. If not given, they're spawned next to the entity.</param>
/// <param name="component">The storage component on <paramref name="entity"/>. Resolved automatically if not given.</param>
/// <param name="utilizer">The material silo utilizer component on <paramref name="uid"/>.</param>
/// <returns>The stack entities that were spawned.</returns>
public List<EntityUid> EjectAllMaterial(
EntityUid entity,
EntityCoordinates? coordinates = null,
MaterialStorageComponent? component = null)
MaterialStorageComponent? component = null,
MaterialSiloUtilizerComponent? utilizer = null)
{
if (!Resolve(entity, ref component))
return new List<EntityUid>();
Expand All @@ -230,7 +235,7 @@ public List<EntityUid> EjectAllMaterial(
var allSpawned = new List<EntityUid>();
foreach (var material in component.Storage.Keys.ToArray())
{
var spawned = EjectMaterial(entity, material, null, coordinates, component);
var spawned = EjectMaterial(entity, material, null, coordinates, component, utilizer);
allSpawned.AddRange(spawned);
}

Expand Down
41 changes: 13 additions & 28 deletions Content.Server/StationEvents/Events/RandomSentienceRule.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Content.Server.Announcements.Systems;
using System.Linq;
using Content.Shared.Dataset;
using Content.Server.Ghost.Roles.Components;
using Content.Server.Station.Components;
using Content.Server.StationEvents.Components;
using Content.Shared.GameTicking.Components;
using Content.Shared.Random.Helpers;
Expand All @@ -13,27 +11,25 @@ namespace Content.Server.StationEvents.Events;

public sealed class RandomSentienceRule : StationEventSystem<RandomSentienceRuleComponent>
{
[Dependency] private readonly AnnouncerSystem _announcer = default!;

[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly IRobustRandom _random = default!;
protected override void Started(EntityUid uid, RandomSentienceRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
{
if (!TryGetRandomStation(out var randomStation))
if (!TryGetRandomStation(out var station))
return;

var targetList = new List<Entity<SentienceTargetComponent>>();
var query = EntityQueryEnumerator<SentienceTargetComponent, TransformComponent>();
while (query.MoveNext(out var targetUid, out var target, out var xform))
{
if (StationSystem.GetOwningStation(targetUid, xform) != randomStation)
if (StationSystem.GetOwningStation(targetUid, xform) != station)
continue;

targetList.Add((targetUid, target));
}

var toMakeSentient = _random.Next(component.MinSentiences, component.MaxSentiences);
var stationsToNotify = new List<EntityUid>();

var groups = new HashSet<string>();

for (var i = 0; i < toMakeSentient && targetList.Count > 0; i++)
Expand Down Expand Up @@ -72,27 +68,16 @@ protected override void Started(EntityUid uid, RandomSentienceRuleComponent comp
var kind2 = groupList.Count > 1 ? groupList[1] : "???";
var kind3 = groupList.Count > 2 ? groupList[2] : "???";

foreach (var target in targetList)
{
var targetStation = StationSystem.GetOwningStation(target);
if(targetStation == null)
continue;
stationsToNotify.Add((EntityUid) targetStation);
}
foreach (var station in stationsToNotify)
{
_announcer.SendAnnouncement(
_announcer.GetAnnouncementId(args.RuleId),
StationSystem.GetInStation(EntityManager.GetComponent<StationDataComponent>(station)),
ChatSystem.DispatchStationAnnouncement(
station.Value,
Loc.GetString(
"station-event-random-sentience-announcement",
null,
Color.Gold,
null,
null,
("kind1", kind1), ("kind2", kind2), ("kind3", kind3), ("amount", groupList.Count),
("data", _random.Pick(_prototype.Index<LocalizedDatasetPrototype>("RandomSentienceEventData"))),
("strength", _random.Pick(_prototype.Index<LocalizedDatasetPrototype>("RandomSentienceEventStrength")))
);
}
("kind1", kind1),
("kind2", kind2),
("kind3", kind3),
("amount", groupList.Count),
("data", _random.Pick(_prototype.Index<LocalizedDatasetPrototype>("RandomSentienceEventData"))),
("strength", _random.Pick(_prototype.Index<LocalizedDatasetPrototype>("RandomSentienceEventStrength"))))
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Content.Server.Chat.Systems;
using Content.Shared.WhiteDream.BloodCult.Items.BaseAura;
using Content.Shared.WhiteDream.BloodCult.Spells;

namespace Content.Server.WhiteDream.BloodCult.Items.BaseAura;

public abstract class BaseAuraSystem<T> : EntitySystem where T : BaseAuraComponent
{
[Dependency] private readonly ChatSystem _chat = default!;

public override void Initialize()
{
SubscribeLocalEvent<T, SpeakOnAuraUseEvent>(OnAuraUse);
}

private void OnAuraUse(EntityUid uid, T component, SpeakOnAuraUseEvent args)
{
// TODO: The charge of the aura spell should be spent here
if (component.Speech != null)
_chat.TrySendInGameICMessage(args.User, component.Speech, component.ChatType, false);
}
}
Original file line number Diff line number Diff line change
@@ -1,55 +1,25 @@
using System.Linq;
using Content.Server.Chat.Systems;
using Content.Server.Cuffs;
using Content.Server.Stunnable;
using Content.Server.WhiteDream.BloodCult.Items.BaseAura;
using Content.Shared.Speech.Muting;
using Content.Shared.StatusEffect;
using Content.Shared.Stunnable;
using Content.Shared.Weapons.Melee.Events;
using Content.Shared.WhiteDream.BloodCult.BloodCultist;
using Robust.Server.GameObjects;

using Content.Shared.WhiteDream.BloodCult.Items.ShadowShacklesAura;
using Robust.Shared.Containers;

namespace Content.Server.WhiteDream.BloodCult.Items.ShadowShacklesAura;

public sealed class ShadowShacklesAuraSystem : EntitySystem
public sealed class ShadowShacklesAuraSystem : BaseAuraSystem<ShadowShacklesAuraComponent>
{
[Dependency] private readonly StatusEffectsSystem _statusEffects = default!;
[Dependency] private readonly StunSystem _stun = default!;
[Dependency] private readonly ChatSystem _chat = default!;
[Dependency] private readonly TransformSystem _transform = default!;
[Dependency] private readonly CuffableSystem _cuffable = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<ShadowShacklesAuraComponent, MeleeHitEvent>(OnMeleeHit);
SubscribeLocalEvent<ShadowShacklesAuraComponent, EntRemovedFromContainerMessage>(OnShackles);
}

private void OnMeleeHit(EntityUid uid, ShadowShacklesAuraComponent component, MeleeHitEvent args)
private void OnShackles(EntityUid uid, ShadowShacklesAuraComponent component, EntRemovedFromContainerMessage args)
{
if (!args.HitEntities.Any())
return;

var target = args.HitEntities.First();
if (uid == target
|| HasComp<StunnedComponent>(target)
|| HasComp<BloodCultistComponent>(target))
return;

if (component.Speech != null)
_chat.TrySendInGameICMessage(args.User, component.Speech, component.ChatType, false);

var shuckles = Spawn(component.ShacklesProto, _transform.GetMapCoordinates(args.User));
if (!_cuffable.TryAddNewCuffs(target, args.User, shuckles))
{
QueueDel(shuckles);
return;
}

_stun.TryKnockdown(target, component.KnockdownDuration, true);
_statusEffects.TryAddStatusEffect<MutedComponent>(target, "Muted", component.MuteDuration, true);
QueueDel(uid);
_statusEffects.TryAddStatusEffect<MutedComponent>(component.Target, "Muted", component.MuteDuration, true);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Content.Server.WhiteDream.BloodCult.Items.BaseAura;
using Content.Shared.Chat;
using Content.Shared.WhiteDream.BloodCult.Items.BaseAura;

namespace Content.Server.WhiteDream.BloodCult.Items.StunAura;

Expand Down
Loading

0 comments on commit 9a6a1c2

Please sign in to comment.