CatStation/Content.Shared/Store/SharedStoreSystem.Generator.cs
ScarKy0 eefa7073c7
Changeling Fleshtomb (#45851)
* init

* make it proper

* listing, random humanoid appearance to shared

* oops

* moar

* pre-pr cleanup

* examine change

* partial review

* ye

* comment

* examinable

* sounds

* TrapInContainer >>>>>

* textures

* ambience

* fix

* Change collection to use leftclicking

* last minute balance change fuck everything

---------

Co-authored-by: SlamBamActionman <slambamactionman@gmail.com>
2026-09-24 12:31:06 +00:00

120 lines
4.4 KiB
C#

using Content.Shared.Examine;
using Content.Shared.FixedPoint;
using Content.Shared.Interaction;
using Content.Shared.Store.Components;
using Content.Shared.Whitelist;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
namespace Content.Shared.Store;
/// <summary>
/// This handles currency generation and collection for <see cref="StoreCurrencyGeneratorComponent"/>.
/// </summary>
public abstract partial class SharedStoreSystem
{
[Dependency] private IGameTiming _timing = default!;
[Dependency] private EntityWhitelistSystem _whitelist = default!;
[Dependency] private SharedAudioSystem _audio = default!;
[SubscribeLocalEvent]
private void OnGeneratorInitialize(Entity<StoreCurrencyGeneratorComponent> entity, ref MapInitEvent args)
{
entity.Comp.NextGenerationTime = _timing.CurTime + entity.Comp.GenerationDelay;
DirtyField(entity, entity.Comp, nameof(StoreCurrencyGeneratorComponent.NextGenerationTime));
}
[SubscribeLocalEvent]
private void OnInteractedUsingHand(Entity<StoreCurrencyGeneratorComponent> entity, ref InteractHandEvent args)
{
AttemptCollection(entity, args.User, args.User);
}
[SubscribeLocalEvent]
private void OnInteractedUsingStore(Entity<StoreCurrencyGeneratorComponent> entity, ref InteractUsingEvent args)
{
AttemptCollection(entity, args.Used, args.User);
}
[SubscribeLocalEvent]
private void OnExamined(Entity<StoreCurrencyGeneratorComponent> entity, ref ExaminedEvent args)
{
if (!args.IsInDetailsRange)
return;
// If we only wanna show the examine message to valid stores.
if (entity.Comp.StoreExaminable)
{
if (!HasComp<StoreComponent>(args.Examiner))
return;
if (!_whitelist.CheckBoth(args.Examiner, entity.Comp.Blacklist, entity.Comp.Whitelist))
return;
}
if (!ProtoMan.TryIndex(entity.Comp.Currency, out var proto))
return;
args.PushMarkup(Loc.GetString("store-generator-examine", ("amount", entity.Comp.Amount), ("currency", Loc.GetString(proto.DisplayName)), ("entity", entity)));
}
private void UpdateGenerator(float frameTime)
{
var query = EntityQueryEnumerator<StoreCurrencyGeneratorComponent>();
var curTime = _timing.CurTime;
while (query.MoveNext(out var uid, out var generator))
{
if (generator.NextGenerationTime > curTime)
return;
generator.NextGenerationTime += generator.GenerationDelay;
DirtyField(uid, generator, nameof(StoreCurrencyGeneratorComponent.NextGenerationTime));
if (!generator.Enabled)
return;
if (generator.Amount >= generator.MaxAmount)
return;
generator.Amount += generator.GeneratedAmount;
DirtyField(uid, generator, nameof(StoreCurrencyGeneratorComponent.Amount));
}
}
private void CollectGenerator(Entity<StoreCurrencyGeneratorComponent> generator, Entity<StoreComponent> collector, EntityUid user, CurrencyPrototype proto)
{
Dictionary<ProtoId<CurrencyPrototype>, FixedPoint2> currency = new();
currency.Add(proto.ID, generator.Comp.Amount);
if (TryAddCurrency(currency, collector, collector.Comp))
{
Popup.PopupEntity(Loc.GetString(generator.Comp.CollectPopup, ("amount", generator.Comp.Amount), ("currency", Loc.GetString(proto.DisplayName)), ("entity", generator)), generator, user);
generator.Comp.Amount = 0;
DirtyField(generator, generator.Comp, nameof(StoreCurrencyGeneratorComponent.Amount));
_audio.PlayPredicted(generator.Comp.CollectSound, generator, user);
}
}
private void AttemptCollection(Entity<StoreCurrencyGeneratorComponent> entity, EntityUid collector, EntityUid user)
{
if (!TryComp<StoreComponent>(collector, out var storeComp))
return;
if (!_whitelist.CheckBoth(collector, entity.Comp.Blacklist, entity.Comp.Whitelist))
return;
if (!ProtoMan.TryIndex(entity.Comp.Currency, out var proto))
return;
if (entity.Comp.Amount == 0)
{
Popup.PopupEntity(Loc.GetString(entity.Comp.EmptyPopup), entity, user);
return;
}
CollectGenerator(entity, (collector, storeComp), collector, proto);
}
}