Skip to content

Commit

Permalink
Updates WelderRefinable Component (#687)
Browse files Browse the repository at this point in the history
# Description

I have made this originally for N14 as there was a heavy need for junk
items to be list instead of a hash. It created a few issues where you
were unable to put down 2 pieces of steel without making a new defined
entity which spawns a stack of 2.
I thought this was quite annoying so I decided to instead make it into a
`EntitySpawnEntry` from a `string` which would also give it options of
`amount` `prob` `maxAmount` and `orGroup` which would definitely aid in
the scrapping needs there as you could randomize the refined amounts.

I believe this could be useful upstream. As well as cleaning up code
which is more modifiable than before.

The new example of how it can be typed in yaml is also simpler in my
opinion as it is self-explanatory and used in various places like
StorageFill contents for one.
```YAML
  - type: WelderRefinable
    refineResult:
    - id: SheetGlass1
      amount: 1
      maxAmount: 2
      prob: 0.5
      orGroup: Glass
```

---

:cl:
refactor: Refactors WelderRefinableComponent.cs and RefiningSystem.cs
tweak: Tweaked the formatting for WelderRefinable refineResult to use
EntitySpawnEntry format
  • Loading branch information
BlueHNT authored Aug 8, 2024
1 parent 9b11260 commit e9e10f2
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Content.Shared.Tools;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Content.Shared.Storage;
using Robust.Shared.Prototypes;

namespace Content.Server.Construction.Components
{
Expand All @@ -10,13 +11,13 @@ namespace Content.Server.Construction.Components
[RegisterComponent]
public sealed partial class WelderRefinableComponent : Component
{
[DataField("refineResult")]
public HashSet<string>? RefineResult = new();
[DataField]
public List<EntitySpawnEntry> RefineResult = new();

[DataField("refineTime")]
[DataField]
public float RefineTime = 2f;

[DataField("qualityNeeded", customTypeSerializer:typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
public string QualityNeeded = "Welding";
[DataField]
public ProtoId<ToolQualityPrototype> QualityNeeded = "Welding";
}
}
15 changes: 3 additions & 12 deletions Content.Server/Construction/RefiningSystem.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
using Content.Server.Construction.Components;
using Content.Server.Stack;
using Content.Shared.Construction;
using Content.Shared.DoAfter;
using Content.Shared.Interaction;
using Content.Shared.Stacks;
using Content.Shared.Tools;
using Robust.Shared.Serialization;
using Content.Shared.Storage;
using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;

namespace Content.Server.Construction
{
public sealed class RefiningSystem : EntitySystem
{
[Dependency] private readonly SharedToolSystem _toolSystem = default!;
[Dependency] private readonly StackSystem _stackSystem = default!;
public override void Initialize()
{
base.Initialize();
Expand All @@ -39,14 +35,9 @@ private void OnDoAfter(EntityUid uid, WelderRefinableComponent component, Welder
EntityManager.DeleteEntity(uid);

// spawn each result after refine
foreach (var result in component.RefineResult!)
foreach (var ent in EntitySpawnCollection.GetSpawns(component.RefineResult))
{
var droppedEnt = EntityManager.SpawnEntity(result, resultPosition);

// TODO: If something has a stack... Just use a prototype with a single thing in the stack.
// This is not a good way to do it.
if (TryComp<StackComponent>(droppedEnt, out var stack))
_stackSystem.SetCount(droppedEnt, 1, stack);
Spawn(ent, resultPosition);
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions Resources/Prototypes/Entities/Objects/Materials/shards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
color: "#bbeeff"
- type: WelderRefinable
refineResult:
- SheetGlass1
- id: SheetGlass1
- type: DamageUserOnTrigger
damage:
types:
Expand Down Expand Up @@ -120,8 +120,8 @@
color: "#96cdef"
- type: WelderRefinable
refineResult:
- SheetGlass1
- PartRodMetal1
- id: SheetGlass1
- id: PartRodMetal1
- type: DamageUserOnTrigger
damage:
types:
Expand Down Expand Up @@ -152,8 +152,8 @@
color: "#FF72E7"
- type: WelderRefinable
refineResult:
- SheetGlass1
- SheetPlasma1
- id: SheetGlass1
- id: SheetPlasma1
- type: DamageUserOnTrigger
damage:
types:
Expand Down Expand Up @@ -186,8 +186,8 @@
color: "#8eff7a"
- type: WelderRefinable
refineResult:
- SheetGlass1
- SheetUranium1
- id: SheetGlass1
- id: SheetUranium1
- type: DamageUserOnTrigger
damage:
types:
Expand Down Expand Up @@ -221,8 +221,8 @@
color: "#e0aa36"
- type: WelderRefinable
refineResult:
- SheetGlass1
- SheetBrass1
- id: SheetGlass1
- id: SheetBrass1
- type: DamageUserOnTrigger
damage:
types:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
- type: SpaceGarbage
- type: WelderRefinable
refineResult:
- SheetGlass1
- id: SheetGlass1
26 changes: 13 additions & 13 deletions Resources/Prototypes/Entities/Objects/Power/lights.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
- type: SpaceGarbage
- type: WelderRefinable
refineResult:
- SheetGlass1
- id: SheetGlass1

- type: entity
parent: BaseLightbulb
Expand Down Expand Up @@ -276,8 +276,8 @@
node: icon
- type: WelderRefinable
refineResult:
- SheetGlass1
- ShardCrystalCyan
- id: SheetGlass1
- id: ShardCrystalCyan

- type: entity
parent: LightTubeCrystalCyan
Expand All @@ -296,8 +296,8 @@
node: icon
- type: WelderRefinable
refineResult:
- SheetGlass1
- ShardCrystalBlue
- id: SheetGlass1
- id: ShardCrystalBlue

- type: entity
parent: LightTubeCrystalCyan
Expand All @@ -316,8 +316,8 @@
node: icon
- type: WelderRefinable
refineResult:
- SheetGlass1
- ShardCrystalPink
- id: SheetGlass1
- id: ShardCrystalPink

- type: entity
parent: LightTubeCrystalCyan
Expand All @@ -336,8 +336,8 @@
node: icon
- type: WelderRefinable
refineResult:
- SheetGlass1
- ShardCrystalOrange
- id: SheetGlass1
- id: ShardCrystalOrange

- type: entity
parent: LightTubeCrystalCyan
Expand All @@ -356,8 +356,8 @@
node: icon
- type: WelderRefinable
refineResult:
- SheetGlass1
- ShardCrystalRed
- id: SheetGlass1
- id: ShardCrystalRed

- type: entity
parent: LightTubeCrystalCyan
Expand All @@ -376,5 +376,5 @@
node: icon
- type: WelderRefinable
refineResult:
- SheetGlass1
- ShardCrystalGreen
- id: SheetGlass1
- id: ShardCrystalGreen

0 comments on commit e9e10f2

Please sign in to comment.