Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…gines into beacons
  • Loading branch information
sleepyyapril committed Nov 9, 2024
2 parents e906f6b + d5f3d89 commit 1b6becc
Show file tree
Hide file tree
Showing 28 changed files with 2,773 additions and 933 deletions.
3 changes: 1 addition & 2 deletions Content.Server/Jobs/AddComponentSpecial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ namespace Content.Server.Jobs
[UsedImplicitly]
public sealed partial class AddComponentSpecial : JobSpecial
{
[DataField("components")]
[AlwaysPushInheritance]
[DataField, AlwaysPushInheritance]
public ComponentRegistry Components { get; private set; } = new();

public override void AfterEquip(EntityUid mob)
Expand Down
13 changes: 12 additions & 1 deletion Content.Server/Power/EntitySystems/PowerNetSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
using Content.Server.Power.Components;
using Content.Server.Power.NodeGroups;
using Content.Server.Power.Pow3r;
using Content.Shared.CCVar;
using Content.Shared.Power;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.Configuration;
using Robust.Shared.Threading;

namespace Content.Server.Power.EntitySystems
Expand All @@ -18,19 +20,21 @@ public sealed class PowerNetSystem : EntitySystem
{
[Dependency] private readonly AppearanceSystem _appearance = default!;
[Dependency] private readonly PowerNetConnectorSystem _powerNetConnector = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IParallelManager _parMan = default!;

private readonly PowerState _powerState = new();
private readonly HashSet<PowerNet> _powerNetReconnectQueue = new();
private readonly HashSet<ApcNet> _apcNetReconnectQueue = new();

private readonly BatteryRampPegSolver _solver = new();
private BatteryRampPegSolver _solver = new();

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

UpdatesAfter.Add(typeof(NodeGroupSystem));
_solver = new(_cfg.GetCVar(CCVars.DebugPow3rDisableParallel));

SubscribeLocalEvent<ApcPowerReceiverComponent, ComponentInit>(ApcPowerReceiverInit);
SubscribeLocalEvent<ApcPowerReceiverComponent, ComponentShutdown>(ApcPowerReceiverShutdown);
Expand All @@ -52,6 +56,13 @@ public override void Initialize()
SubscribeLocalEvent<PowerSupplierComponent, ComponentShutdown>(PowerSupplierShutdown);
SubscribeLocalEvent<PowerSupplierComponent, EntityPausedEvent>(PowerSupplierPaused);
SubscribeLocalEvent<PowerSupplierComponent, EntityUnpausedEvent>(PowerSupplierUnpaused);

Subs.CVar(_cfg, CCVars.DebugPow3rDisableParallel, DebugPow3rDisableParallelChanged);
}

private void DebugPow3rDisableParallelChanged(bool val)
{
_solver = new(val);
}

private void ApcPowerReceiverInit(EntityUid uid, ApcPowerReceiverComponent component, ComponentInit args)
Expand Down
9 changes: 7 additions & 2 deletions Content.Server/Power/Pow3r/BatteryRampPegSolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ namespace Content.Server.Power.Pow3r
public sealed class BatteryRampPegSolver : IPowerSolver
{
private UpdateNetworkJob _networkJob;
private bool _disableParallel;

public BatteryRampPegSolver()
public BatteryRampPegSolver(bool disableParallel = false)
{
_disableParallel = disableParallel;
_networkJob = new()
{
Solver = this,
Expand Down Expand Up @@ -54,7 +56,10 @@ public void Tick(float frameTime, PowerState state, IParallelManager parallel)
// suppliers + discharger) Then decide based on total layer size whether its worth parallelizing that
// layer?
_networkJob.Networks = group;
parallel.ProcessNow(_networkJob, group.Count);
if (_disableParallel)
parallel.ProcessSerialNow(_networkJob, group.Count);
else
parallel.ProcessNow(_networkJob, group.Count);
}

ClearBatteries(state);
Expand Down
9 changes: 9 additions & 0 deletions Content.Server/Punpun/PunpunComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Content.Server.Punpun;

[RegisterComponent]
public sealed partial class PunpunComponent : Component
{
/// How many rounds Punpun will be around for before disappearing with a note
[DataField]
public int Lifetime = 14;
}
114 changes: 114 additions & 0 deletions Content.Server/Punpun/PunpunSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using System.Linq;
using Content.Server.GameTicking;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Inventory;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Components;
using Robust.Server.GameObjects;

namespace Content.Server.Punpun;

public sealed class PunpunSystem : EntitySystem
{
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly ServerMetaDataSystem _meta = default!;

private (int, string, string, string) _punpunData = (1, string.Empty, string.Empty, string.Empty);


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

SubscribeLocalEvent<PunpunComponent, ComponentStartup>(OnRoundStart);
SubscribeLocalEvent<RoundEndTextAppendEvent>(OnRoundEnd);
}


// Checks if the Punpun data has any items to equip, and names the Punpun upon initialization
private void OnRoundStart(EntityUid uid, PunpunComponent component, ComponentStartup args)
{
if (_punpunData.Item1 > component.Lifetime)
{
EntityManager.SpawnEntity("PaperWrittenPunpunNote", Transform(uid).Coordinates);
EntityManager.QueueDeleteEntity(uid);
_punpunData = (1, string.Empty, string.Empty, string.Empty);

return;
}

var meta = MetaData(uid);
_meta.SetEntityName(uid, $"{meta.EntityName} {ToRomanNumeral(_punpunData.Item1)}", meta);

if (!EntityManager.TryGetComponent<InventoryComponent>(uid, out _))
return;
EquipItem(uid, "head", _punpunData.Item2);
EquipItem(uid, "mask", _punpunData.Item3);
EquipItem(uid, "jumpsuit", _punpunData.Item4);
}

// Checks if Punpun exists, and is alive at round end
// If so, stores the items and increments the Punpun count
private void OnRoundEnd(RoundEndTextAppendEvent ev)
{
// I couldn't find a method to get a single entity, so this just enumerates over the first and disposes it
var punpunComponents = EntityManager.EntityQueryEnumerator<PunpunComponent>();
punpunComponents.MoveNext(out var punpun, out _);

if (!EntityManager.TryGetComponent<MobStateComponent>(punpun, out var mobState)
|| mobState.CurrentState == MobState.Dead)
_punpunData = (1, string.Empty, string.Empty, string.Empty);

_punpunData.Item1++;

if (EntityManager.HasComponent<InventoryComponent>(punpun))
{
_punpunData.Item2 = CheckSlot(punpun, "head");
_punpunData.Item3 = CheckSlot(punpun, "mask");
_punpunData.Item4 = CheckSlot(punpun, "jumpsuit");
}

punpunComponents.Dispose();
}

// Equips an item to a slot, and names it.
private void EquipItem(EntityUid uid, string slot, string item)
{
if (item == string.Empty)
return;

var itemEnt = EntityManager.SpawnEntity(item, EntityManager.GetComponent<TransformComponent>(uid).Coordinates);
if (_inventory.TryEquip(uid, itemEnt, slot, true, true))
_meta.SetEntityName(itemEnt, $"{MetaData(uid).EntityName}'s {MetaData(itemEnt).EntityName}");
else
EntityManager.DeleteEntity(itemEnt);
}

// Checks if an item exists in a slot, and returns its name
private string CheckSlot(EntityUid uid, string slot)
{
return _inventory.TryGetSlotEntity(uid, slot, out var item)
? EntityManager.GetComponent<MetaDataComponent>(item.Value).EntityPrototype!.ID
: string.Empty;
}


// Punpun, the lord of Roman Numerals
public static List<string> RomanNumerals = new() { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" };
public static List<int> Numerals = new() { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 };

public static string ToRomanNumeral(int number)
{
var romanNumeral = string.Empty;
while (number > 0)
{
// Find the biggest numeral that is less than equal to number
var index = Numerals.FindIndex(x => x <= number);
// Subtract its value from your number
number -= Numerals[index];
// Add it onto the end of your roman numeral
romanNumeral += RomanNumerals[index];
}
return romanNumeral;
}
}
Loading

0 comments on commit 1b6becc

Please sign in to comment.