Makes tools and welders ECS, add ToolQualityPrototype. (#4741)
This commit is contained in:
committed by
GitHub
parent
f2760d0002
commit
365c7da4dc
@@ -208,7 +208,7 @@ namespace Content.Shared.Chemistry.EntitySystems
|
||||
}
|
||||
|
||||
public bool TryGetSolution(IEntity? target, string name,
|
||||
[NotNullWhen(true)] out Solution? solution)
|
||||
[NotNullWhen(true)] out Solution? solution, SolutionContainerManagerComponent? solutionsMgr = null)
|
||||
{
|
||||
if (target == null || target.Deleted)
|
||||
{
|
||||
@@ -216,13 +216,12 @@ namespace Content.Shared.Chemistry.EntitySystems
|
||||
return false;
|
||||
}
|
||||
|
||||
return TryGetSolution(target.Uid, name, out solution);
|
||||
return TryGetSolution(target.Uid, name, out solution, solutionsMgr);
|
||||
}
|
||||
|
||||
public bool TryGetSolution(EntityUid uid, string name,
|
||||
[NotNullWhen(true)] out Solution? solution)
|
||||
public bool TryGetSolution(EntityUid uid, string name, [NotNullWhen(true)] out Solution? solution, SolutionContainerManagerComponent? solutionsMgr = null)
|
||||
{
|
||||
if (!EntityManager.TryGetComponent(uid, out SolutionContainerManagerComponent? solutionsMgr))
|
||||
if (!Resolve(uid, ref solutionsMgr))
|
||||
{
|
||||
solution = null;
|
||||
return false;
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
using System.Linq;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Tool;
|
||||
using Content.Shared.Tools;
|
||||
using Content.Shared.Tools.Components;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Shared.Construction.Steps
|
||||
@@ -9,7 +14,8 @@ namespace Content.Shared.Construction.Steps
|
||||
[DataDefinition]
|
||||
public class ToolConstructionGraphStep : ConstructionGraphStep
|
||||
{
|
||||
[DataField("tool")] public ToolQuality Tool { get; } = ToolQuality.None;
|
||||
[DataField("tool", required:true, customTypeSerializer:typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
|
||||
public string Tool { get; } = string.Empty;
|
||||
|
||||
[DataField("fuel")] public float Fuel { get; } = 10;
|
||||
|
||||
@@ -19,11 +25,15 @@ namespace Content.Shared.Construction.Steps
|
||||
{
|
||||
if (!string.IsNullOrEmpty(ExamineOverride))
|
||||
{
|
||||
examinedEvent.Message.AddMarkup(Loc.GetString(ExamineOverride));
|
||||
examinedEvent.PushMarkup(Loc.GetString(ExamineOverride));
|
||||
return;
|
||||
}
|
||||
|
||||
examinedEvent.Message.AddMarkup(Loc.GetString("construction-use-tool-entity", ("toolName", Tool.GetToolName())));
|
||||
if (string.IsNullOrEmpty(Tool) || !IoCManager.Resolve<IPrototypeManager>().TryIndex(Tool, out ToolQualityPrototype? quality))
|
||||
return;
|
||||
|
||||
examinedEvent.PushMarkup(Loc.GetString("construction-use-tool-entity", ("toolName", Loc.GetString(quality.ToolName))));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
using System;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Tool
|
||||
{
|
||||
[Flags]
|
||||
public enum ToolQuality : byte
|
||||
{
|
||||
None = 0,
|
||||
Anchoring = 1,
|
||||
Prying = 1 << 1,
|
||||
Screwing = 1 << 2,
|
||||
Cutting = 1 << 3,
|
||||
Welding = 1 << 4,
|
||||
Multitool = 1 << 5,
|
||||
}
|
||||
|
||||
public static class ToolQualityHelpers
|
||||
{
|
||||
public static string GetToolName(this ToolQuality quality)
|
||||
{
|
||||
return quality switch
|
||||
{
|
||||
ToolQuality.Anchoring => "Wrench",
|
||||
ToolQuality.Prying => "Crowbar",
|
||||
ToolQuality.Screwing => "Screwdriver",
|
||||
ToolQuality.Cutting => "Wirecutters",
|
||||
ToolQuality.Welding => "Welding tool",
|
||||
ToolQuality.Multitool => "Multitool",
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class SharedToolComponent : Component
|
||||
{
|
||||
public override string Name => "Tool";
|
||||
|
||||
public virtual ToolQuality Qualities { get; set; }
|
||||
}
|
||||
|
||||
[NetSerializable, Serializable]
|
||||
public class MultiToolComponentState : ComponentState
|
||||
{
|
||||
public ToolQuality Quality { get; }
|
||||
|
||||
public MultiToolComponentState(ToolQuality quality)
|
||||
{
|
||||
Quality = quality;
|
||||
}
|
||||
}
|
||||
|
||||
[NetSerializable, Serializable]
|
||||
public class WelderComponentState : ComponentState
|
||||
{
|
||||
public float FuelCapacity { get; }
|
||||
public float Fuel { get; }
|
||||
public bool Activated { get; }
|
||||
public ToolQuality Quality { get; }
|
||||
|
||||
public WelderComponentState(float fuelCapacity, float fuel, bool activated)
|
||||
{
|
||||
FuelCapacity = fuelCapacity;
|
||||
Fuel = fuel;
|
||||
Activated = activated;
|
||||
Quality = ToolQuality.Welding;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Tools.Components
|
||||
{
|
||||
[NetworkedComponent]
|
||||
public class SharedMultipleToolComponent : Component
|
||||
{
|
||||
public override string Name => "MultipleTool";
|
||||
}
|
||||
|
||||
[NetSerializable, Serializable]
|
||||
public class MultipleToolComponentState : ComponentState
|
||||
{
|
||||
public string QualityName { get; }
|
||||
|
||||
public MultipleToolComponentState(string qualityName)
|
||||
{
|
||||
QualityName = qualityName;
|
||||
}
|
||||
}
|
||||
}
|
||||
30
Content.Shared/Tools/Components/SharedWelderComponent.cs
Normal file
30
Content.Shared/Tools/Components/SharedWelderComponent.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Tools.Components
|
||||
{
|
||||
[NetworkedComponent]
|
||||
public abstract class SharedWelderComponent : Component
|
||||
{
|
||||
public override string Name => "Welder";
|
||||
|
||||
public bool Lit { get; set; }
|
||||
}
|
||||
|
||||
[NetSerializable, Serializable]
|
||||
public class WelderComponentState : ComponentState
|
||||
{
|
||||
public float FuelCapacity { get; }
|
||||
public float Fuel { get; }
|
||||
public bool Lit { get; }
|
||||
|
||||
public WelderComponentState(float fuelCapacity, float fuel, bool lit)
|
||||
{
|
||||
FuelCapacity = fuelCapacity;
|
||||
Fuel = fuel;
|
||||
Lit = lit;
|
||||
}
|
||||
}
|
||||
}
|
||||
41
Content.Shared/Tools/ToolQualityPrototype.cs
Normal file
41
Content.Shared/Tools/ToolQualityPrototype.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Content.Shared.Sound;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Shared.Tools
|
||||
{
|
||||
[Prototype("tool")]
|
||||
public class ToolQualityPrototype : IPrototype
|
||||
{
|
||||
[DataField("id", required: true)]
|
||||
public string ID { get; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Human-readable name for this tool quality e.g. "Anchoring"
|
||||
/// </summary>
|
||||
/// <remarks>This is a localization string ID.</remarks>
|
||||
[DataField("name")]
|
||||
public string Name { get; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Human-readable name for a tool of this type e.g. "Wrench"
|
||||
/// </summary>
|
||||
/// <remarks>This is a localization string ID.</remarks>
|
||||
[DataField("toolName")]
|
||||
public string ToolName { get; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// An icon that will be used to represent this tool type.
|
||||
/// </summary>
|
||||
[DataField("icon")]
|
||||
public SpriteSpecifier? Icon { get; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// The default entity prototype for this tool type.
|
||||
/// </summary>
|
||||
[DataField("spawn", required:true, customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string Spawn { get; } = string.Empty;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user