committed by
GitHub
parent
afc8c9163c
commit
3a27490c59
@@ -0,0 +1,49 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Materials;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Materials
|
||||
{
|
||||
/// <summary>
|
||||
/// Component to store data such as "this object is made out of steel".
|
||||
/// This is not a storage system for say smelteries.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class MaterialComponent : Component
|
||||
{
|
||||
public override string Name => "Material";
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("materials", customTypeSerializer:typeof(PrototypeIdListSerializer<MaterialPrototype>))]
|
||||
// ReSharper disable once CollectionNeverUpdated.Local
|
||||
private readonly List<string> _materials = new();
|
||||
public IEnumerable<string> MaterialIds => _materials;
|
||||
|
||||
/// <summary>
|
||||
/// Returns all materials which make up this entity.
|
||||
/// This property has an IoC resolve and is generally slow, so be sure to cache the results if needed.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public IEnumerable<MaterialPrototype> Materials
|
||||
{
|
||||
get
|
||||
{
|
||||
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
||||
|
||||
foreach (var id in MaterialIds)
|
||||
{
|
||||
if(prototypeManager.TryIndex<MaterialPrototype>(id, out var material))
|
||||
yield return material;
|
||||
else
|
||||
Logger.Error($"Material prototype {id} does not exist! Entity: {Owner}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,10 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.GameObjects.Components.Materials;
|
||||
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
|
||||
using Content.Server.GameObjects.Components.Stack;
|
||||
using Content.Server.Utility;
|
||||
using Content.Shared.GameObjects.Components.Materials;
|
||||
using Content.Shared.GameObjects.Components.Power;
|
||||
using Content.Shared.GameObjects.Components.Research;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
@@ -160,37 +160,37 @@ namespace Content.Server.GameObjects.Components.Research
|
||||
var totalAmount = 0;
|
||||
|
||||
// Check if it can insert all materials.
|
||||
foreach (var (_, mat) in material.MaterialTypes)
|
||||
foreach (var mat in material.MaterialIds)
|
||||
{
|
||||
// TODO: Change how MaterialComponent works so this is not hard-coded.
|
||||
if (!storage.CanInsertMaterial(mat.ID, VolumePerSheet * multiplier)) return false;
|
||||
if (!storage.CanInsertMaterial(mat, VolumePerSheet * multiplier)) return false;
|
||||
totalAmount += VolumePerSheet * multiplier;
|
||||
}
|
||||
|
||||
// Check if it can take ALL of the material's volume.
|
||||
if (storage.CanTakeAmount(totalAmount)) return false;
|
||||
|
||||
foreach (var (_, mat) in material.MaterialTypes)
|
||||
foreach (var mat in material.MaterialIds)
|
||||
{
|
||||
storage.InsertMaterial(mat.ID, VolumePerSheet * multiplier);
|
||||
storage.InsertMaterial(mat, VolumePerSheet * multiplier);
|
||||
}
|
||||
|
||||
State = LatheState.Inserting;
|
||||
switch (material.MaterialTypes.First().Value.Name)
|
||||
switch (material.Materials.FirstOrDefault()?.ID)
|
||||
{
|
||||
case "steel":
|
||||
case "Steel":
|
||||
SetAppearance(LatheVisualState.InsertingMetal);
|
||||
break;
|
||||
case "glass":
|
||||
case "Glass":
|
||||
SetAppearance(LatheVisualState.InsertingGlass);
|
||||
break;
|
||||
case "gold":
|
||||
case "Gold":
|
||||
SetAppearance(LatheVisualState.InsertingGold);
|
||||
break;
|
||||
case "plastic":
|
||||
case "Plastic":
|
||||
SetAppearance(LatheVisualState.InsertingPlastic);
|
||||
break;
|
||||
case "plasma":
|
||||
case "Plasma":
|
||||
SetAppearance(LatheVisualState.InsertingPlasma);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user