ConstructionGL2 Part 2: Better guided steps and recipes. (#5103)
This commit is contained in:
committed by
GitHub
parent
5be8271907
commit
5a5006e4cf
@@ -1,3 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Construction;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -34,13 +35,21 @@ namespace Content.Server.Construction.Conditions
|
||||
if (airlock.BoltsDown != Value)
|
||||
{
|
||||
if (Value == true)
|
||||
args.PushMarkup(Loc.GetString("construction-condition-airlock-bolt", ("entityName", entity.Name)) + "\n");
|
||||
args.PushMarkup(Loc.GetString("construction-examine-condition-airlock-bolt", ("entityName", entity.Name)) + "\n");
|
||||
else
|
||||
args.PushMarkup(Loc.GetString("construction-condition-airlock-unbolt", ("entityName", entity.Name)) + "\n");
|
||||
args.PushMarkup(Loc.GetString("construction-examine-condition-airlock-unbolt", ("entityName", entity.Name)) + "\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public IEnumerable<ConstructionGuideEntry> GenerateGuideEntry()
|
||||
{
|
||||
yield return new ConstructionGuideEntry()
|
||||
{
|
||||
Localization = Value ? "construction-step-condition-airlock-bolt" : "construction-step-condition-airlock-unbolt"
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.Construction;
|
||||
using Content.Shared.Examine;
|
||||
@@ -37,5 +38,16 @@ namespace Content.Server.Construction.Conditions
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public IEnumerable<ConstructionGuideEntry> GenerateGuideEntry()
|
||||
{
|
||||
foreach (var condition in Conditions)
|
||||
{
|
||||
foreach (var entry in condition.GenerateGuideEntry())
|
||||
{
|
||||
yield return entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.GameObjects.Components;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.WireHacking;
|
||||
using Content.Shared.Construction;
|
||||
using Content.Shared.Examine;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.Construction.Conditions
|
||||
@@ -37,6 +37,21 @@ namespace Content.Server.Construction.Conditions
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO CONSTRUCTION: Examine for this condition.
|
||||
public bool DoExamine(ExaminedEvent args)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString(Value
|
||||
? "construction-examine-condition-all-wires-cut"
|
||||
: "construction-examine-condition-all-wires-intact"));
|
||||
return true;
|
||||
}
|
||||
|
||||
public IEnumerable<ConstructionGuideEntry> GenerateGuideEntry()
|
||||
{
|
||||
yield return new ConstructionGuideEntry()
|
||||
{
|
||||
Localization = Value ? "construction-guide-condition-all-wires-cut"
|
||||
: "construction-guide-condition-all-wires-intact"
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Construction;
|
||||
using Content.Shared.Examine;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.Construction.Conditions
|
||||
@@ -24,6 +27,33 @@ namespace Content.Server.Construction.Conditions
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO CONSTRUCTION: Examine for this condition.
|
||||
public bool DoExamine(ExaminedEvent args)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("construction-examine-condition-any-conditions"));
|
||||
|
||||
foreach (var condition in Conditions)
|
||||
{
|
||||
condition.DoExamine(args);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public IEnumerable<ConstructionGuideEntry> GenerateGuideEntry()
|
||||
{
|
||||
yield return new ConstructionGuideEntry()
|
||||
{
|
||||
Localization = "construction-guide-condition-any-conditions",
|
||||
};
|
||||
|
||||
foreach (var condition in Conditions)
|
||||
{
|
||||
foreach (var entry in condition.GenerateGuideEntry())
|
||||
{
|
||||
entry.Padding += 4;
|
||||
yield return entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.Construction;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Maps;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Construction.Conditions
|
||||
{
|
||||
@@ -24,6 +29,15 @@ namespace Content.Server.Construction.Conditions
|
||||
[DataField("hasEntity")]
|
||||
public bool HasEntity { get; private set; }
|
||||
|
||||
[DataField("examineText")]
|
||||
public string? ExamineText { get; }
|
||||
|
||||
[DataField("guideText")]
|
||||
public string? GuideText { get; }
|
||||
|
||||
[DataField("guideIcon")]
|
||||
public SpriteSpecifier? GuideIcon { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The component name in question.
|
||||
/// </summary>
|
||||
@@ -49,6 +63,25 @@ namespace Content.Server.Construction.Conditions
|
||||
return !HasEntity;
|
||||
}
|
||||
|
||||
// TODO CONSTRUCTION: Custom examine for this condition.
|
||||
public bool DoExamine(ExaminedEvent args)
|
||||
{
|
||||
if (string.IsNullOrEmpty(ExamineText))
|
||||
return false;
|
||||
|
||||
args.PushMarkup(Loc.GetString(ExamineText));
|
||||
return true;
|
||||
}
|
||||
|
||||
public IEnumerable<ConstructionGuideEntry> GenerateGuideEntry()
|
||||
{
|
||||
if (string.IsNullOrEmpty(GuideText))
|
||||
yield break;
|
||||
|
||||
yield return new ConstructionGuideEntry()
|
||||
{
|
||||
Localization = GuideText,
|
||||
Icon = GuideIcon,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.Construction;
|
||||
using Content.Shared.Examine;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.Containers;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -14,8 +16,17 @@ namespace Content.Server.Construction.Conditions
|
||||
[DataDefinition]
|
||||
public class ContainerEmpty : IGraphCondition
|
||||
{
|
||||
[DataField("container")] public string Container { get; private set; } = string.Empty;
|
||||
[DataField("text")] public string Text { get; private set; } = string.Empty;
|
||||
[DataField("container")]
|
||||
public string Container { get; } = string.Empty;
|
||||
|
||||
[DataField("examineText")]
|
||||
public string? ExamineText { get; }
|
||||
|
||||
[DataField("guideStep")]
|
||||
public string? GuideText { get; }
|
||||
|
||||
[DataField("guideIcon")]
|
||||
public SpriteSpecifier? GuideIcon { get; }
|
||||
|
||||
public bool Condition(EntityUid uid, IEntityManager entityManager)
|
||||
{
|
||||
@@ -28,6 +39,9 @@ namespace Content.Server.Construction.Conditions
|
||||
|
||||
public bool DoExamine(ExaminedEvent args)
|
||||
{
|
||||
if (string.IsNullOrEmpty(ExamineText))
|
||||
return false;
|
||||
|
||||
var entity = args.Examined;
|
||||
|
||||
if (!entity.TryGetComponent(out ContainerManagerComponent? containerManager) ||
|
||||
@@ -36,9 +50,19 @@ namespace Content.Server.Construction.Conditions
|
||||
if (container.ContainedEntities.Count == 0)
|
||||
return false;
|
||||
|
||||
args.PushMarkup(Text);
|
||||
args.PushMarkup(Loc.GetString(ExamineText));
|
||||
return true;
|
||||
}
|
||||
public IEnumerable<ConstructionGuideEntry> GenerateGuideEntry()
|
||||
{
|
||||
if (string.IsNullOrEmpty(GuideText))
|
||||
yield break;
|
||||
|
||||
yield return new ConstructionGuideEntry()
|
||||
{
|
||||
Localization = GuideText,
|
||||
Icon = GuideIcon,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.Construction;
|
||||
using Content.Shared.Examine;
|
||||
@@ -5,6 +6,7 @@ using JetBrains.Annotations;
|
||||
using Robust.Server.Containers;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -15,7 +17,9 @@ namespace Content.Server.Construction.Conditions
|
||||
public class ContainerNotEmpty : IGraphCondition
|
||||
{
|
||||
[DataField("container")] public string Container { get; private set; } = string.Empty;
|
||||
[DataField("text")] public string Text { get; private set; } = string.Empty;
|
||||
[DataField("examineText")] public string? ExamineText { get; }
|
||||
[DataField("guideText")] public string? GuideText { get; }
|
||||
[DataField("guideIcon")] public SpriteSpecifier? GuideIcon { get; }
|
||||
|
||||
public bool Condition(EntityUid uid, IEntityManager entityManager)
|
||||
{
|
||||
@@ -28,6 +32,9 @@ namespace Content.Server.Construction.Conditions
|
||||
|
||||
public bool DoExamine(ExaminedEvent args)
|
||||
{
|
||||
if (ExamineText == null)
|
||||
return false;
|
||||
|
||||
var entity = args.Examined;
|
||||
|
||||
if (!entity.TryGetComponent(out ContainerManagerComponent? containerManager) ||
|
||||
@@ -36,9 +43,20 @@ namespace Content.Server.Construction.Conditions
|
||||
if (container.ContainedEntities.Count != 0)
|
||||
return false;
|
||||
|
||||
args.PushMarkup(Text);
|
||||
args.PushMarkup(Loc.GetString(ExamineText));
|
||||
return true;
|
||||
}
|
||||
|
||||
public IEnumerable<ConstructionGuideEntry> GenerateGuideEntry()
|
||||
{
|
||||
if (GuideText == null)
|
||||
yield break;
|
||||
|
||||
yield return new ConstructionGuideEntry()
|
||||
{
|
||||
Localization = GuideText,
|
||||
Icon = GuideIcon,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Doors.Components;
|
||||
using Content.Shared.Construction;
|
||||
using Content.Shared.Examine;
|
||||
@@ -32,13 +33,23 @@ namespace Content.Server.Construction.Conditions
|
||||
if (door.IsWeldedShut != Welded)
|
||||
{
|
||||
if (Welded == true)
|
||||
args.PushMarkup(Loc.GetString("construction-condition-door-weld", ("entityName", entity.Name)) + "\n");
|
||||
args.PushMarkup(Loc.GetString("construction-examine-condition-door-weld", ("entityName", entity.Name)) + "\n");
|
||||
else
|
||||
args.PushMarkup(Loc.GetString("construction-condition-door-unweld", ("entityName", entity.Name)) + "\n");
|
||||
args.PushMarkup(Loc.GetString("construction-examine-condition-door-unweld", ("entityName", entity.Name)) + "\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public IEnumerable<ConstructionGuideEntry> GenerateGuideEntry()
|
||||
{
|
||||
yield return new ConstructionGuideEntry()
|
||||
{
|
||||
Localization = Welded
|
||||
? "construction-guide-condition-door-weld"
|
||||
: "construction-guide-condition-door-unweld",
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.Construction;
|
||||
using Content.Shared.Examine;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Construction.Conditions
|
||||
{
|
||||
@@ -27,14 +30,25 @@ namespace Content.Server.Construction.Conditions
|
||||
switch (Anchored)
|
||||
{
|
||||
case true when !entity.Transform.Anchored:
|
||||
args.PushMarkup("First, anchor it.");
|
||||
args.PushMarkup(Loc.GetString("construction-examine-condition-entity-anchored"));
|
||||
return true;
|
||||
case false when entity.Transform.Anchored:
|
||||
args.PushMarkup("First, unanchor it.");
|
||||
args.PushMarkup(Loc.GetString("construction-examine-condition-entity-unanchored"));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public IEnumerable<ConstructionGuideEntry> GenerateGuideEntry()
|
||||
{
|
||||
yield return new ConstructionGuideEntry()
|
||||
{
|
||||
Localization = Anchored
|
||||
? "construction-step-condition-entity-anchored"
|
||||
: "construction-step-condition-entity-unanchored",
|
||||
Icon = new SpriteSpecifier.Rsi(new ResourcePath("Objects/Tools/wrench.rsi"), "icon"),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Construction.Components;
|
||||
using Content.Shared.Construction;
|
||||
@@ -17,6 +18,13 @@ namespace Content.Server.Construction.Conditions
|
||||
[DataDefinition]
|
||||
public class MachineFrameComplete : IGraphCondition
|
||||
{
|
||||
[DataField("guideIconBoard")]
|
||||
public SpriteSpecifier? GuideIconBoard { get; }
|
||||
|
||||
[DataField("guideIconParts")]
|
||||
public SpriteSpecifier? GuideIconPart { get; }
|
||||
|
||||
|
||||
public bool Condition(EntityUid uid, IEntityManager entityManager)
|
||||
{
|
||||
if (!entityManager.TryGetComponent(uid, out MachineFrameComponent? machineFrame))
|
||||
@@ -91,5 +99,22 @@ namespace Content.Server.Construction.Conditions
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public IEnumerable<ConstructionGuideEntry> GenerateGuideEntry()
|
||||
{
|
||||
yield return new ConstructionGuideEntry()
|
||||
{
|
||||
Localization = "construction-step-condition-machine-frame-board",
|
||||
Icon = GuideIconBoard,
|
||||
EntryNumber = 0, // Set this to anything so the guide generation takes this as a numbered step.
|
||||
};
|
||||
|
||||
yield return new ConstructionGuideEntry()
|
||||
{
|
||||
Localization = "construction-step-condition-machine-frame-parts",
|
||||
Icon = GuideIconPart,
|
||||
EntryNumber = 0, // Set this to anything so the guide generation takes this as a numbered step.
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Toilet;
|
||||
using Content.Shared.Construction;
|
||||
using Content.Shared.Examine;
|
||||
@@ -27,8 +28,16 @@ namespace Content.Server.Construction.Conditions
|
||||
if (!entity.TryGetComponent(out ToiletComponent? toilet)) return false;
|
||||
if (!toilet.LidOpen) return false;
|
||||
|
||||
args.PushMarkup(Loc.GetString("construction-condition-toilet-lid-closed") + "\n");
|
||||
args.PushMarkup(Loc.GetString("construction-examine-condition-toilet-lid-closed") + "\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
public IEnumerable<ConstructionGuideEntry> GenerateGuideEntry()
|
||||
{
|
||||
yield return new ConstructionGuideEntry()
|
||||
{
|
||||
Localization = "construction-step-condition-toilet-lid-closed"
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.GameObjects.Components;
|
||||
using Content.Server.WireHacking;
|
||||
@@ -34,14 +35,24 @@ namespace Content.Server.Construction.Conditions
|
||||
switch (Open)
|
||||
{
|
||||
case true when !wires.IsPanelOpen:
|
||||
args.PushMarkup(Loc.GetString("construction-condition-wire-panel-open"));
|
||||
args.PushMarkup(Loc.GetString("construction-examine-condition-wire-panel-open"));
|
||||
return true;
|
||||
case false when wires.IsPanelOpen:
|
||||
args.PushMarkup(Loc.GetString("construction-condition-wire-panel-close"));
|
||||
args.PushMarkup(Loc.GetString("construction-examine-condition-wire-panel-close"));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public IEnumerable<ConstructionGuideEntry> GenerateGuideEntry()
|
||||
{
|
||||
yield return new ConstructionGuideEntry()
|
||||
{
|
||||
Localization = Open
|
||||
? "construction-step-condition-wire-panel-open"
|
||||
: "construction-step-condition-wire-panel-close"
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
228
Content.Server/Construction/ConstructionSystem.Guided.cs
Normal file
228
Content.Server/Construction/ConstructionSystem.Guided.cs
Normal file
@@ -0,0 +1,228 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Construction.Components;
|
||||
using Content.Shared.Construction;
|
||||
using Content.Shared.Construction.Prototypes;
|
||||
using Content.Shared.Construction.Steps;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Server.Construction
|
||||
{
|
||||
public partial class ConstructionSystem
|
||||
{
|
||||
private readonly Dictionary<ConstructionPrototype, ConstructionGuide> _guideCache = new();
|
||||
|
||||
private void InitializeGuided()
|
||||
{
|
||||
SubscribeNetworkEvent<RequestConstructionGuide>(OnGuideRequested);
|
||||
SubscribeLocalEvent<ConstructionComponent, GetOtherVerbsEvent>(AddDeconstructVerb);
|
||||
SubscribeLocalEvent<ConstructionComponent, ExaminedEvent>(HandleConstructionExamined);
|
||||
}
|
||||
|
||||
private void OnGuideRequested(RequestConstructionGuide msg, EntitySessionEventArgs args)
|
||||
{
|
||||
if (!_prototypeManager.TryIndex(msg.ConstructionId, out ConstructionPrototype? prototype))
|
||||
return;
|
||||
|
||||
if(GetGuide(prototype) is {} guide)
|
||||
RaiseNetworkEvent(new ResponseConstructionGuide(msg.ConstructionId, guide), args.SenderSession.ConnectedClient);
|
||||
}
|
||||
|
||||
private void AddDeconstructVerb(EntityUid uid, ConstructionComponent component, GetOtherVerbsEvent args)
|
||||
{
|
||||
if (!args.CanAccess)
|
||||
return;
|
||||
|
||||
if (component.TargetNode == component.DeconstructionNode ||
|
||||
component.Node == component.DeconstructionNode)
|
||||
return;
|
||||
|
||||
Verb verb = new();
|
||||
//verb.Category = VerbCategories.Construction;
|
||||
//TODO VERBS add more construction verbs? Until then, removing construction category
|
||||
verb.Text = Loc.GetString("deconstructible-verb-begin-deconstruct");
|
||||
verb.IconTexture = "/Textures/Interface/hammer_scaled.svg.192dpi.png";
|
||||
|
||||
verb.Act = () =>
|
||||
{
|
||||
SetPathfindingTarget(uid, component.DeconstructionNode, component);
|
||||
if (component.TargetNode == null)
|
||||
{
|
||||
// Maybe check, but on the flip-side a better solution might be to not make it undeconstructible in the first place, no?
|
||||
component.Owner.PopupMessage(args.User, Loc.GetString("deconstructible-verb-activate-no-target-text"));
|
||||
}
|
||||
else
|
||||
{
|
||||
component.Owner.PopupMessage(args.User, Loc.GetString("deconstructible-verb-activate-text"));
|
||||
}
|
||||
};
|
||||
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
private void HandleConstructionExamined(EntityUid uid, ConstructionComponent component, ExaminedEvent args)
|
||||
{
|
||||
if (GetTargetNode(uid, component) is {} target)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString(
|
||||
"construction-component-to-create-header",
|
||||
("targetName", target.Name)) + "\n");
|
||||
}
|
||||
|
||||
if (component.EdgeIndex == null && GetTargetEdge(uid, component) is {} targetEdge)
|
||||
{
|
||||
var preventStepExamine = false;
|
||||
|
||||
foreach (var condition in targetEdge.Conditions)
|
||||
{
|
||||
preventStepExamine |= condition.DoExamine(args);
|
||||
}
|
||||
|
||||
if (!preventStepExamine)
|
||||
targetEdge.Steps[0].DoExamine(args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (GetCurrentEdge(uid, component) is {} edge)
|
||||
{
|
||||
var preventStepExamine = false;
|
||||
|
||||
foreach (var condition in edge.Conditions)
|
||||
{
|
||||
preventStepExamine |= condition.DoExamine(args);
|
||||
}
|
||||
|
||||
if (preventStepExamine) return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private ConstructionGuide? GetGuide(ConstructionPrototype construction)
|
||||
{
|
||||
// NOTE: This method might be allocate a fair bit, but do not worry!
|
||||
// This method is specifically designed to generate guides once and cache the results,
|
||||
// therefore we don't need to worry *too much* about the performance of this.
|
||||
|
||||
// If we've generated and cached this guide before, return it.
|
||||
if (_guideCache.TryGetValue(construction, out var guide))
|
||||
return guide;
|
||||
|
||||
// If the graph doesn't actually exist, do nothing.
|
||||
if (!_prototypeManager.TryIndex(construction.Graph, out ConstructionGraphPrototype? graph))
|
||||
return null;
|
||||
|
||||
// If either the start node or the target node are missing, do nothing.
|
||||
if (GetNodeFromGraph(graph, construction.StartNode) is not {} startNode
|
||||
|| GetNodeFromGraph(graph, construction.TargetNode) is not {} targetNode)
|
||||
return null;
|
||||
|
||||
// If there's no path from start to target, do nothing.
|
||||
if (graph.Path(construction.StartNode, construction.TargetNode) is not {} path
|
||||
|| path.Length == 0)
|
||||
return null;
|
||||
|
||||
var step = 1;
|
||||
|
||||
var entries = new List<ConstructionGuideEntry>()
|
||||
{
|
||||
// Initial construction header.
|
||||
new()
|
||||
{
|
||||
Localization = construction.Type == ConstructionType.Structure
|
||||
? "construction-presenter-to-build" : "construction-presenter-to-craft",
|
||||
EntryNumber = step,
|
||||
}
|
||||
};
|
||||
|
||||
var conditions = new HashSet<string>();
|
||||
|
||||
// Iterate until the penultimate node.
|
||||
var node = startNode;
|
||||
var index = 0;
|
||||
while(node != targetNode)
|
||||
{
|
||||
// Can't find path, therefore can't generate guide...
|
||||
if (!node.TryGetEdge(path[index].Name, out var edge))
|
||||
return null;
|
||||
|
||||
// First steps are handled specially.
|
||||
if (step == 1)
|
||||
{
|
||||
foreach (var graphStep in edge.Steps)
|
||||
{
|
||||
// This graph is invalid, we only allow insert steps as the initial construction steps.
|
||||
if (graphStep is not EntityInsertConstructionGraphStep insertStep)
|
||||
return null;
|
||||
|
||||
entries.Add(insertStep.GenerateGuideEntry());
|
||||
}
|
||||
|
||||
// Now actually list the construction conditions.
|
||||
foreach (var condition in construction.Conditions)
|
||||
{
|
||||
if (condition.GenerateGuideEntry() is not {} conditionEntry)
|
||||
continue;
|
||||
|
||||
conditionEntry.Padding += 4;
|
||||
entries.Add(conditionEntry);
|
||||
}
|
||||
|
||||
step++;
|
||||
node = path[index++];
|
||||
|
||||
// Add a bit of padding if there will be more steps after this.
|
||||
if(node != targetNode)
|
||||
entries.Add(new ConstructionGuideEntry());
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
var old = conditions;
|
||||
conditions = new HashSet<string>();
|
||||
|
||||
foreach (var condition in edge.Conditions)
|
||||
{
|
||||
foreach (var conditionEntry in condition.GenerateGuideEntry())
|
||||
{
|
||||
conditions.Add(conditionEntry.Localization);
|
||||
|
||||
// Okay so if the condition entry had a non-null value here, we take it as a numbered step.
|
||||
// This is for cases where there is a lot of snowflake behavior, such as machine frames...
|
||||
// So that the step of inserting a machine board and inserting all of its parts is numbered.
|
||||
if (conditionEntry.EntryNumber != null)
|
||||
conditionEntry.EntryNumber = step++;
|
||||
|
||||
// To prevent spamming the same stuff over and over again. This is a bit naive, but..ye.
|
||||
// Also we will only hide this condition *if* it isn't numbered.
|
||||
else
|
||||
{
|
||||
if (old.Contains(conditionEntry.Localization))
|
||||
continue;
|
||||
|
||||
// We only add padding for non-numbered entries.
|
||||
conditionEntry.Padding += 4;
|
||||
}
|
||||
|
||||
entries.Add(conditionEntry);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var graphStep in edge.Steps)
|
||||
{
|
||||
var entry = graphStep.GenerateGuideEntry();
|
||||
entry.EntryNumber = step++;
|
||||
entries.Add(entry);
|
||||
}
|
||||
|
||||
node = path[index++];
|
||||
}
|
||||
|
||||
guide = new ConstructionGuide(entries.ToArray());
|
||||
_guideCache[construction] = guide;
|
||||
return guide;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ namespace Content.Server.Construction
|
||||
{
|
||||
private readonly HashSet<EntityUid> _constructionUpdateQueue = new();
|
||||
|
||||
private void InitializeSteps()
|
||||
private void InitializeInteractions()
|
||||
{
|
||||
#region DoAfter Subscriptions
|
||||
|
||||
|
||||
@@ -39,13 +39,12 @@ namespace Content.Server.Construction
|
||||
_sawmill = _logManager.GetSawmill(SawmillName);
|
||||
|
||||
InitializeGraphs();
|
||||
InitializeSteps();
|
||||
InitializeGuided();
|
||||
InitializeInteractions();
|
||||
InitializeInitial();
|
||||
|
||||
SubscribeLocalEvent<ConstructionComponent, ComponentInit>(OnConstructionInit);
|
||||
SubscribeLocalEvent<ConstructionComponent, ComponentStartup>(OnConstructionStartup);
|
||||
SubscribeLocalEvent<ConstructionComponent, GetOtherVerbsEvent>(AddDeconstructVerb);
|
||||
SubscribeLocalEvent<ConstructionComponent, ExaminedEvent>(HandleConstructionExamined);
|
||||
}
|
||||
|
||||
private void OnConstructionInit(EntityUid uid, ConstructionComponent construction, ComponentInit args)
|
||||
@@ -94,74 +93,6 @@ namespace Content.Server.Construction
|
||||
PerformActions(uid, null, node.Actions);
|
||||
}
|
||||
|
||||
private void AddDeconstructVerb(EntityUid uid, ConstructionComponent component, GetOtherVerbsEvent args)
|
||||
{
|
||||
if (!args.CanAccess)
|
||||
return;
|
||||
|
||||
if (component.TargetNode == component.DeconstructionNode ||
|
||||
component.Node == component.DeconstructionNode)
|
||||
return;
|
||||
|
||||
Verb verb = new();
|
||||
//verb.Category = VerbCategories.Construction;
|
||||
//TODO VERBS add more construction verbs? Until then, removing construction category
|
||||
verb.Text = Loc.GetString("deconstructible-verb-begin-deconstruct");
|
||||
verb.IconTexture = "/Textures/Interface/hammer_scaled.svg.192dpi.png";
|
||||
|
||||
verb.Act = () =>
|
||||
{
|
||||
SetPathfindingTarget(uid, component.DeconstructionNode, component);
|
||||
if (component.TargetNode == null)
|
||||
{
|
||||
// Maybe check, but on the flip-side a better solution might be to not make it undeconstructible in the first place, no?
|
||||
component.Owner.PopupMessage(args.User, Loc.GetString("deconstructible-verb-activate-no-target-text"));
|
||||
}
|
||||
else
|
||||
{
|
||||
component.Owner.PopupMessage(args.User, Loc.GetString("deconstructible-verb-activate-text"));
|
||||
}
|
||||
};
|
||||
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
private void HandleConstructionExamined(EntityUid uid, ConstructionComponent component, ExaminedEvent args)
|
||||
{
|
||||
if (GetTargetNode(uid, component) is {} target)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString(
|
||||
"construction-component-to-create-header",
|
||||
("targetName", target.Name)) + "\n");
|
||||
}
|
||||
|
||||
if (component.EdgeIndex == null && GetTargetEdge(uid, component) is {} targetEdge)
|
||||
{
|
||||
var preventStepExamine = false;
|
||||
|
||||
foreach (var condition in targetEdge.Conditions)
|
||||
{
|
||||
preventStepExamine |= condition.DoExamine(args);
|
||||
}
|
||||
|
||||
if (!preventStepExamine)
|
||||
targetEdge.Steps[0].DoExamine(args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (GetCurrentEdge(uid, component) is {} edge)
|
||||
{
|
||||
var preventStepExamine = false;
|
||||
|
||||
foreach (var condition in edge.Conditions)
|
||||
{
|
||||
preventStepExamine |= condition.DoExamine(args);
|
||||
}
|
||||
|
||||
if (preventStepExamine) return;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
Reference in New Issue
Block a user