Files
crystall-punk-14/Content.Server/_CP14/Farming/CP14FarmingSystem.cs
Ed 48831380b4 Give some love to farming (#1124)
* give some love to farming

* Queryptimization

* Fuck soil!!!

* fuck soil in prototypes!

* seeds improve

* partial merge wild and farm

* some strange fix

* plant kills refactor, add compost

* fix compost

* Update migration.yml

* rain can watering plants

* sage update

* Update seeds.yml

* sage smoking update

* Update seeds.yml
2025-04-03 15:29:08 +03:00

60 lines
2.0 KiB
C#

using Content.Shared._CP14.Farming;
using Content.Shared._CP14.Farming.Components;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Damage;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Timing;
namespace Content.Server._CP14.Farming;
public sealed partial class CP14FarmingSystem : CP14SharedFarmingSystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainer = default!;
[Dependency] private readonly DamageableSystem _damageable = default!;
public override void Initialize()
{
base.Initialize();
InitializeResources();
SubscribeLocalEvent<CP14PlantComponent, MapInitEvent>(OnMapInit);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
var query = EntityQueryEnumerator<CP14PlantComponent>();
while (query.MoveNext(out var uid, out var plant))
{
if (_timing.CurTime <= plant.NextUpdateTime)
continue;
var newTime = _random.NextFloat(plant.UpdateFrequency);
plant.NextUpdateTime = _timing.CurTime + TimeSpan.FromSeconds(newTime);
var ev = new CP14PlantUpdateEvent((uid, plant));
RaiseLocalEvent(uid, ev);
AffectResource((uid, plant), ev.ResourceDelta);
AffectEnergy((uid, plant), ev.EnergyDelta);
var ev2 = new CP14AfterPlantUpdateEvent((uid, plant));
RaiseLocalEvent(uid, ev2);
Dirty(uid, plant);
}
}
private void OnMapInit(Entity<CP14PlantComponent> plant, ref MapInitEvent args)
{
var newTime = _random.NextFloat(plant.Comp.UpdateFrequency);
plant.Comp.NextUpdateTime = _timing.CurTime + TimeSpan.FromSeconds(newTime);
}
}