mirror of
https://github.com/corvax-team/ss14-wl.git
synced 2026-02-15 03:31:38 +01:00
Фикс дюпа с помощью [прото/авто/т.д.]-латов (#351)
* init * init 2 * summary и забытые wl теги * coderabbit фиксы
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
61
Content.Server/_WL/Lathe/Systems/LatheCraftedItemsSystem.cs
Normal file
61
Content.Server/_WL/Lathe/Systems/LatheCraftedItemsSystem.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
- type: entity
|
||||
- type: entity
|
||||
id: Recycler
|
||||
parent: BaseMachinePowered
|
||||
name: recycler
|
||||
|
||||
Reference in New Issue
Block a user