Фикс дюпа с помощью [прото/авто/т.д.]-латов (#351)

* init

* init 2

* summary и забытые wl теги

* coderabbit фиксы
This commit is contained in:
Pupchansky
2025-10-29 20:35:58 +05:00
committed by GitHub
parent e48b0e8b31
commit 247c92fc5e
9 changed files with 128 additions and 10 deletions

View File

@@ -245,9 +245,14 @@ namespace Content.Server.Lathe
if (currentRecipe.Result is { } resultProto)
{
var result = Spawn(resultProto, Transform(uid).Coordinates);
// WL-Changes-start
var ev = new LatheGetResultEvent(result, (uid, comp), currentRecipe.ID);
//Corvax
RaiseLocalEvent(uid, new LatheGetResultEvent(result));
RaiseLocalEvent(uid, ev);
//Corvax
RaiseLocalEvent(ev);
// WL-Changes-end
_stack.TryMergeToContacts(result);
}

View File

@@ -4,6 +4,7 @@ using Content.Server.Ghost;
using Content.Server.Popups;
using Content.Server.Stack;
using Content.Server.Wires;
using Content.Shared._WL.Materials.Events;
using Content.Shared.Body.Systems;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Components.SolutionManager;
@@ -11,6 +12,7 @@ using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Database;
using Content.Shared.Destructible;
using Content.Shared.Emag.Components;
using Content.Shared.Humanoid;
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
@@ -25,7 +27,6 @@ using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
using System.Linq;
using Content.Shared.Humanoid;
namespace Content.Server.Materials;
@@ -202,7 +203,10 @@ public sealed class MaterialReclaimerSystem : SharedMaterialReclaimerSystem
SpawnChemicalsFromComposition(uid, item, completion, true, component, xform);
}
QueueDel(item);
// WL-Changes-start
//QueueDel(item);
Del(item);
// WL-Changes-end
}
private void SpawnMaterialsFromComposition(EntityUid reclaimer,
@@ -223,7 +227,12 @@ public sealed class MaterialReclaimerSystem : SharedMaterialReclaimerSystem
foreach (var (material, amount) in composition.MaterialComposition)
{
var outputAmount = (int) (amount * efficiency * modifier);
// WL-Changes-start
var ev = new BeforeItemMaterialReclaimedEvent(efficiency, modifier, amount, material);
RaiseLocalEvent(item, ev);
// WL-Changes-end
var outputAmount = Math.Max(0, (int)(ev.Amount * ev.Efficiency * ev.Modifier)); // WL-Changes-start
_materialStorage.TryChangeMaterialAmount(reclaimer, material, outputAmount, storage);
}

View File

@@ -0,0 +1,8 @@
namespace Content.Server._WL.Lathe.Components;
[RegisterComponent]
public sealed partial class CraftedOnLatheComponent : Component
{
[ViewVariables]
public Dictionary<string, int> ConsumedMaterials { get; set; } = new();
}

View File

@@ -0,0 +1,61 @@
using Content.Server._WL.Lathe.Components;
using Content.Shared._WL.Materials.Events;
using Content.Shared.Lathe;
using Content.Shared.Stacks;
using Robust.Shared.Prototypes;
namespace Content.Server._WL.Lathe.Systems;
public sealed class LatheCraftedItemsSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _protoMan = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<CraftedOnLatheComponent, BeforeItemMaterialReclaimedEvent>(OnCraftedItemReclaim);
SubscribeLocalEvent<CraftedOnLatheComponent, StackSplitEvent>(OnStackSplit);
SubscribeLocalEvent<LatheGetResultEvent>(OnLatheCraft);
}
private void OnCraftedItemReclaim(EntityUid item, CraftedOnLatheComponent comp, BeforeItemMaterialReclaimedEvent ev)
{
var material = ev.Material;
if (material == null)
return;
if (!comp.ConsumedMaterials.TryGetValue(material, out var consumedAmount))
{
ev.Amount = 0;
return;
}
ev.Amount = Math.Clamp(ev.Amount, 0, consumedAmount);
}
private void OnStackSplit(EntityUid item, CraftedOnLatheComponent itemComp, StackSplitEvent ev)
{
var newItem = ev.NewId;
var newItemComp = EnsureComp<CraftedOnLatheComponent>(newItem);
newItemComp.ConsumedMaterials = new(itemComp.ConsumedMaterials);
}
private void OnLatheCraft(LatheGetResultEvent ev)
{
if (!_protoMan.TryIndex(ev.Recipe, out var recipe))
return;
var latheComp = ev.Lathe.Comp;
var comp = EnsureComp<CraftedOnLatheComponent>(ev.ResultItem);
var consumedMaterials = new Dictionary<string, int>();
foreach (var (material, amount) in recipe.Materials)
{
var consumeAmount = recipe.ApplyMaterialDiscount ? (int)(amount * latheComp.MaterialUseMultiplier) : amount;
consumedMaterials[material] = consumeAmount;
}
comp.ConsumedMaterials = consumedMaterials;
}
}

View File

@@ -123,9 +123,25 @@ namespace Content.Shared.Lathe
{
public readonly EntityUid ResultItem;
public LatheGetResultEvent(EntityUid result)
// WL-Changes-start
public readonly Entity<LatheComponent> Lathe;
public readonly ProtoId<LatheRecipePrototype> Recipe;
// WL-Changes-end
public LatheGetResultEvent(
EntityUid result,
/*WL-Changes-start*/
Entity<LatheComponent> lathe,
ProtoId<LatheRecipePrototype> recipe
/*WL-Changes-end*/
)
{
ResultItem = result;
// WL-Changes-start
Lathe = lathe;
Recipe = recipe;
// WL-Changes-end
}
}
//Corvax

View File

@@ -1,4 +1,4 @@
namespace Content.Shared.Materials;
namespace Content.Shared.Materials;
/// <summary>
/// Valid items that collide with an entity with this component
@@ -11,6 +11,6 @@ public sealed partial class CollideMaterialReclaimerComponent : Component
/// <summary>
/// The fixture that starts reclaiming on collision.
/// </summary>
[DataField("fixtureId")]
[DataField]
public string FixtureId = "brrt";
}

View File

@@ -1,9 +1,7 @@
using System.Linq;
using Content.Shared.Administration.Logs;
using Content.Shared.Audio;
using Content.Shared.Body.Components;
using Content.Shared.Database;
using Content.Shared.Emag.Components;
using Content.Shared.Emag.Systems;
using Content.Shared.Examine;
using Content.Shared.Mobs.Components;
@@ -14,6 +12,7 @@ using Robust.Shared.Containers;
using Robust.Shared.Map;
using Robust.Shared.Physics.Events;
using Robust.Shared.Timing;
using System.Linq;
namespace Content.Shared.Materials;

View File

@@ -0,0 +1,20 @@
using Robust.Shared.Serialization;
namespace Content.Shared._WL.Materials.Events;
/// <summary>
/// Raised on item before each of its materials is reclaimed by reclaimer.
/// </summary>
[Serializable, NetSerializable]
public sealed class BeforeItemMaterialReclaimedEvent(
float efficiency,
float modifier,
int amount,
string? material
) : EntityEventArgs
{
public float Efficiency { get; } = efficiency;
public float Modifier { get; } = modifier;
public int Amount { get; set; } = amount;
public string? Material { get; set; } = material;
}

View File

@@ -1,4 +1,4 @@
- type: entity
- type: entity
id: Recycler
parent: BaseMachinePowered
name: recycler