-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Salvage Tokens and Requisitions #42724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 10 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
adc4a08
Fantastic tokens and where to salvage them
Mehnix a926073
Requisition Console: The Purchases of Salvage
Mehnix e828542
Remove the Jobs Board
Mehnix ba2ed50
Final nitpicks
Mehnix 64247b2
Oops
Mehnix 6d93da1
The Evil and Malicious Typo
Mehnix ace3fa2
PKA Arbitrage
Mehnix 9ef042c
More nitpicks
Mehnix 3830cf9
Updates based on comments
Mehnix 417d17a
Merge branch 'master' into SalvageTickets
Mehnix 4736063
Merge branch 'master' into SalvageTickets
Mehnix 765db45
updates based on comments
Mehnix 18385bc
Merge branch 'master' into SalvageTickets
Mehnix 7421880
H
Mehnix c67a87f
gamble test fail prevention maybe
Mehnix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| using Content.Shared.TicketPrinter; | ||
| using Robust.Shared.Prototypes; | ||
| using Content.Server.Stack; | ||
|
Mehnix marked this conversation as resolved.
Outdated
|
||
|
|
||
| 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 | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Mehnix marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| using Content.Shared.Lathe; | ||
| using Content.Shared.Stacks; | ||
| using Content.Shared.Materials; | ||
| using Content.Shared.Whitelist; | ||
| using Robust.Shared.Prototypes; | ||
| using Robust.Shared.GameObjects; | ||
|
Mehnix marked this conversation as resolved.
Outdated
|
||
|
|
||
| namespace Content.Shared.TicketPrinter; | ||
|
|
||
| public abstract class SharedTicketPrinterSystem : EntitySystem | ||
| { | ||
| [Dependency] private readonly IPrototypeManager _proto = default!; | ||
| [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!; | ||
| public override void Initialize() | ||
| { | ||
| base.Initialize(); | ||
|
|
||
| SubscribeLocalEvent<TicketPrinterComponent, LatheFinishPrintingEvent>(OnPrint); | ||
| SubscribeLocalEvent<TicketPrinterComponent, ReclaimFinishedEvent>(OnReclaimed); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Print tickets when lathe prints entities with a ticket value | ||
| /// </summary> | ||
| /// <param name="ent">The lathe</param> | ||
| /// <param name="args">event containing recipe</param> | ||
| private void OnPrint(Entity<TicketPrinterComponent> ent, ref LatheFinishPrintingEvent args) | ||
| { | ||
| if (args.Recipe.Result is not { } resultProto) //is the result empty, if not set as resultProto | ||
| return; | ||
|
|
||
| var entProto = _proto.Index(resultProto); | ||
| if (!entProto.TryGetComponent<TicketValueComponent>(out var ticketComp, EntityManager.ComponentFactory)) //does component exist from EntityProtoId of recipe result | ||
| return; | ||
|
|
||
| if (entProto.TryGetComponent<StackComponent>(out var stackComp, EntityManager.ComponentFactory))//if a stack, produce tickets for each item in the stack | ||
| PrintTickets(ent, ticketComp.TicketValue * stackComp.Count); | ||
| else | ||
| PrintTickets(ent, ticketComp.TicketValue); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// print tickets when reclaimer reclaims entities with a ticket value | ||
| /// </summary> | ||
| /// <param name="ent">the reclaimer</param> | ||
| /// <param name="args">reclaim event containing reclaimed item</param> | ||
| private void OnReclaimed(Entity<TicketPrinterComponent> ent, ref ReclaimFinishedEvent args) | ||
| { | ||
| if (_whitelistSystem.IsWhitelistFail(ent.Comp.Whitelist, args.Item)) //plenty of things are reclaimable but only some salvagable, should only give tickets for salvage scrap. | ||
| return; | ||
|
|
||
| if (!TryComp<PhysicalCompositionComponent>(args.Item, out var physComp)) | ||
| return; | ||
|
|
||
| foreach (var (material, amount) in physComp.MaterialComposition) //for each material making up the reclaimed item's physical composition | ||
| { | ||
| if (amount <= 0 || !_proto.TryIndex<MaterialPrototype>(material, out var materialProto) || materialProto.StackEntity == null) //get that material's Material Prototype | ||
| continue; | ||
| var entProto = _proto.Index<EntityPrototype>(materialProto.StackEntity); //use that to get its entity prototype | ||
|
|
||
| if (!entProto.TryGetComponent<TicketValueComponent>(out var ticketComp, EntityManager.ComponentFactory) || | ||
| !entProto.TryGetComponent<PhysicalCompositionComponent>(out var matphysComp, EntityManager.ComponentFactory)) //use that to get TicketValue and PhysicalComposition Components | ||
| continue; //theoretically an entity may have some materials that do and some materials that don't have ticket values so we have to check them all. | ||
|
|
||
| PrintTickets(ent, ticketComp.TicketValue * amount / matphysComp.MaterialComposition[materialProto.ID]); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// spawn appropriate amount of tickets | ||
| /// considerations of stack amounts should occur before this point | ||
| /// Ticketprinter modifer applied in this function | ||
| /// </summary> | ||
| /// <param name="ent">the entity printing the tickets</param> | ||
| /// <param name="amount">amount of tickets </param> | ||
| protected virtual void PrintTickets(Entity<TicketPrinterComponent> ent, float amount) | ||
| { | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| using Content.Shared.Whitelist; | ||
| using Robust.Shared.Prototypes; | ||
|
|
||
| namespace Content.Shared.TicketPrinter; | ||
|
|
||
| [RegisterComponent] | ||
| ///<summary> | ||
| /// Spawns bonus entities on creation of entities with a <see cref="TicketValueComponent"/> through crafting or reclaiming | ||
| ///</summary> | ||
| public sealed partial class TicketPrinterComponent : Component | ||
| { | ||
| /// <summary> | ||
| /// Entity Prototype to spawn as the "Ticket" | ||
| /// </summary> | ||
| [DataField, ViewVariables] | ||
| public EntProtoId TicketProtoId = "SalvageTicket"; | ||
|
|
||
| /// <summary> | ||
| /// How much to multiply the <see cref="TicketValueComponent"/> ticket value by, default 1. | ||
| /// </summary> | ||
| [DataField, ViewVariables] | ||
| public float TicketMultiplier = 1f; | ||
|
|
||
| [DataField, ViewVariables] | ||
| /// <summary> | ||
| /// Whitelist of allowed items that will produce tickets, if no whitelist everything is allowed | ||
| /// </summary> | ||
| public EntityWhitelist? Whitelist; | ||
|
|
||
| /// <summary> | ||
| /// If ticket value ends up less than 1, or has a remainder, store it for the future. | ||
| /// </summary> | ||
| public float Remainder = 0f; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| namespace Content.Shared.TicketPrinter; | ||
|
|
||
| [RegisterComponent] | ||
| ///<summary> | ||
| /// Contains the base amount of tickets that will be spawned by <see cref="TicketPrinterComponent"/> when this entity is crafted or reclaimed | ||
| ///</summary> | ||
| public sealed partial class TicketValueComponent : Component | ||
| { | ||
| /// <summary> | ||
| /// Base amount of tickets to spawn | ||
| /// </summary> | ||
| [DataField] | ||
| public float TicketValue = 1f; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.