forked from space-wizards/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTicketPrinterSystem.cs
More file actions
38 lines (30 loc) · 1.58 KB
/
Copy pathTicketPrinterSystem.cs
File metadata and controls
38 lines (30 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using Content.Shared.TicketPrinter;
using Robust.Shared.Prototypes;
using Content.Server.Stack;
namespace Content.Server.TicketPrinter;
public sealed class TicketPrinterSystem : SharedTicketPrinterSystem
{
[Dependency] private readonly StackSystem _stack = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
public override void Initialize()
{
base.Initialize();
}
/// <summary>
/// Applies ticket multiplier and spawns tickets, stores any remainder for future spawns
/// </summary>
/// <param name="ent">Entity spawning the tickets</param>
/// <param name="amount">Base amount of tickets to spawn</param>
protected override void PrintTickets(Entity<TicketPrinterComponent> ent, float amount)
{
if (!_proto.Resolve(ent.Comp.TicketProtoId, out var proto)) //does it exist?
return; //Will return Invalid EntProtoId errors if trying to spawn an entity proto ID that doesn't exist.
var spawnAmount = ent.Comp.Remainder + amount * ent.Comp.TicketMultiplier; //apply multiplier, then add on any remainders of previous prints.
if (spawnAmount <= 0) //if we're somehow less than zero don't print
return;
var tickets = _stack.SpawnMultipleAtPosition(proto, (int)Math.Floor(spawnAmount), Transform(ent).Coordinates);
foreach (var ticket in tickets)
_stack.TryMergeToContacts(ticket); //try to make into a single stack
ent.Comp.Remainder = spawnAmount - (float)Math.Floor(spawnAmount); //can't spawn fractional tickets so store for the future
}
}