Files
Pieter-Jan BriersandGitHub 5168b5f3d4 IoC source gen compatibility (#43863)
* IoC source gen compatibility

Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter.

* Missed a spot
2026-05-09 03:29:58 +00:00

53 lines
1.7 KiB
C#

using Content.Shared.Destructible;
using Content.Shared.Mining;
using Content.Shared.Mining.Components;
using Content.Shared.Random;
using Content.Shared.Random.Helpers;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
namespace Content.Server.Mining;
/// <summary>
/// This handles creating ores when the entity is destroyed.
/// </summary>
public sealed partial class MiningSystem : EntitySystem
{
[Dependency] private IPrototypeManager _proto = default!;
[Dependency] private IRobustRandom _random = default!;
/// <inheritdoc/>
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<OreVeinComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<OreVeinComponent, DestructionEventArgs>(OnDestruction);
}
private void OnDestruction(EntityUid uid, OreVeinComponent component, DestructionEventArgs args)
{
if (component.CurrentOre == null)
return;
var proto = _proto.Index<OrePrototype>(component.CurrentOre);
if (proto.OreEntity == null)
return;
var coords = Transform(uid).Coordinates;
var toSpawn = _random.Next(proto.MinOreYield, proto.MaxOreYield+1);
for (var i = 0; i < toSpawn; i++)
{
Spawn(proto.OreEntity, coords.Offset(_random.NextVector2(0.2f)));
}
}
private void OnMapInit(EntityUid uid, OreVeinComponent component, MapInitEvent args)
{
if (component.CurrentOre != null || component.OreRarityPrototypeId == null || !_random.Prob(component.OreChance))
return;
component.CurrentOre = _proto.Index<WeightedRandomOrePrototype>(component.OreRarityPrototypeId).Pick(_random);
}
}