Port all construction conditions to the new examine.

This commit is contained in:
Vera Aguilera Puerto
2021-10-01 15:27:42 +02:00
parent f21c921c56
commit 3b14c21396
15 changed files with 85 additions and 40 deletions

View File

@@ -6,6 +6,7 @@ using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.Server.Doors.Components; using Content.Server.Doors.Components;
using Content.Shared.Examine;
namespace Content.Server.Construction.Conditions namespace Content.Server.Construction.Conditions
{ {
@@ -23,16 +24,18 @@ namespace Content.Server.Construction.Conditions
return airlock.BoltsDown == Value; return airlock.BoltsDown == Value;
} }
public bool DoExamine(IEntity entity, FormattedMessage message, bool inDetailsRange) public bool DoExamine(ExaminedEvent args)
{ {
var entity = args.Examined;
if (!entity.TryGetComponent(out AirlockComponent? airlock)) return false; if (!entity.TryGetComponent(out AirlockComponent? airlock)) return false;
if (airlock.BoltsDown != Value) if (airlock.BoltsDown != Value)
{ {
if (Value == true) if (Value == true)
message.AddMarkup(Loc.GetString("construction-condition-airlock-bolt", ("entityName", entity.Name)) + "\n"); args.PushMarkup(Loc.GetString("construction-condition-airlock-bolt", ("entityName", entity.Name)) + "\n");
else else
message.AddMarkup(Loc.GetString("construction-condition-airlock-unbolt", ("entityName", entity.Name)) + "\n"); args.PushMarkup(Loc.GetString("construction-condition-airlock-unbolt", ("entityName", entity.Name)) + "\n");
return true; return true;
} }

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.Shared.Construction; using Content.Shared.Construction;
using Content.Shared.Examine;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Serialization.Manager.Attributes;
@@ -24,5 +25,17 @@ namespace Content.Server.Construction.Conditions
return true; return true;
} }
public bool DoExamine(ExaminedEvent args)
{
var ret = false;
foreach (var condition in Conditions)
{
ret |= condition.DoExamine(args);
}
return ret;
}
} }
} }

View File

@@ -2,6 +2,7 @@
using Content.Server.GameObjects.Components; using Content.Server.GameObjects.Components;
using Content.Server.WireHacking; using Content.Server.WireHacking;
using Content.Shared.Construction; using Content.Shared.Construction;
using Content.Shared.Examine;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Serialization.Manager.Attributes;
@@ -38,5 +39,7 @@ namespace Content.Server.Construction.Conditions
return true; return true;
} }
// TODO CONSTRUCTION: Examine for this condition.
} }
} }

View File

@@ -24,5 +24,7 @@ namespace Content.Server.Construction.Conditions
return false; return false;
} }
// TODO CONSTRUCTION: Examine for this condition.
} }
} }

View File

@@ -55,5 +55,7 @@ namespace Content.Server.Construction.Conditions
return !HasEntity; return !HasEntity;
} }
// TODO CONSTRUCTION: Custom examine for this condition.
} }
} }

View File

@@ -1,5 +1,6 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.Shared.Construction; using Content.Shared.Construction;
using Content.Shared.Examine;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.Containers; using Robust.Shared.Containers;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
@@ -23,15 +24,17 @@ namespace Content.Server.Construction.Conditions
return container.ContainedEntities.Count == 0; return container.ContainedEntities.Count == 0;
} }
public bool DoExamine(IEntity entity, FormattedMessage message, bool inDetailsRange) public bool DoExamine(ExaminedEvent args)
{ {
var entity = args.Examined;
if (!entity.TryGetComponent(out ContainerManagerComponent? containerManager) || if (!entity.TryGetComponent(out ContainerManagerComponent? containerManager) ||
!containerManager.TryGetContainer(Container, out var container)) return false; !containerManager.TryGetContainer(Container, out var container)) return false;
if (container.ContainedEntities.Count == 0) if (container.ContainedEntities.Count == 0)
return false; return false;
message.AddMarkup(Text); args.PushMarkup(Text);
return true; return true;
} }

View File

@@ -1,5 +1,6 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.Shared.Construction; using Content.Shared.Construction;
using Content.Shared.Examine;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.Containers; using Robust.Shared.Containers;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
@@ -23,15 +24,17 @@ namespace Content.Server.Construction.Conditions
return container.ContainedEntities.Count != 0; return container.ContainedEntities.Count != 0;
} }
public bool DoExamine(IEntity entity, FormattedMessage message, bool inDetailsRange) public bool DoExamine(ExaminedEvent args)
{ {
var entity = args.Examined;
if (!entity.TryGetComponent(out ContainerManagerComponent? containerManager) || if (!entity.TryGetComponent(out ContainerManagerComponent? containerManager) ||
!containerManager.TryGetContainer(Container, out var container)) return false; !containerManager.TryGetContainer(Container, out var container)) return false;
if (container.ContainedEntities.Count != 0) if (container.ContainedEntities.Count != 0)
return false; return false;
message.AddMarkup(Text); args.PushMarkup(Text);
return true; return true;
} }

View File

@@ -1,6 +1,7 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.Server.Doors.Components; using Content.Server.Doors.Components;
using Content.Shared.Construction; using Content.Shared.Construction;
using Content.Shared.Examine;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Localization; using Robust.Shared.Localization;
@@ -24,16 +25,18 @@ namespace Content.Server.Construction.Conditions
return doorComponent.IsWeldedShut == Welded; return doorComponent.IsWeldedShut == Welded;
} }
public bool DoExamine(IEntity entity, FormattedMessage message, bool inDetailsRange) public bool DoExamine(ExaminedEvent args)
{ {
var entity = args.Examined;
if (!entity.TryGetComponent(out ServerDoorComponent? door)) return false; if (!entity.TryGetComponent(out ServerDoorComponent? door)) return false;
if (door.IsWeldedShut != Welded) if (door.IsWeldedShut != Welded)
{ {
if (Welded == true) if (Welded == true)
message.AddMarkup(Loc.GetString("construction-condition-door-weld", ("entityName", entity.Name)) + "\n"); args.PushMarkup(Loc.GetString("construction-condition-door-weld", ("entityName", entity.Name)) + "\n");
else else
message.AddMarkup(Loc.GetString("construction-condition-door-unweld", ("entityName", entity.Name)) + "\n"); args.PushMarkup(Loc.GetString("construction-condition-door-unweld", ("entityName", entity.Name)) + "\n");
return true; return true;
} }

View File

@@ -1,10 +1,10 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.Shared.Construction; using Content.Shared.Construction;
using Content.Shared.Examine;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Physics; using Robust.Shared.Physics;
using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
namespace Content.Server.Construction.Conditions namespace Content.Server.Construction.Conditions
{ {
@@ -21,17 +21,17 @@ namespace Content.Server.Construction.Conditions
return (physics.BodyType == BodyType.Static && Anchored) || (physics.BodyType != BodyType.Static && !Anchored); return (physics.BodyType == BodyType.Static && Anchored) || (physics.BodyType != BodyType.Static && !Anchored);
} }
public bool DoExamine(IEntity entity, FormattedMessage message, bool inDetailsRange) public bool DoExamine(ExaminedEvent args)
{ {
if (!entity.TryGetComponent(out IPhysBody? physics)) return false; var entity = args.Examined;
switch (Anchored) switch (Anchored)
{ {
case true when physics.BodyType != BodyType.Static: case true when !entity.Transform.Anchored:
message.AddMarkup("First, anchor it.\n"); args.PushMarkup("First, anchor it.");
return true; return true;
case false when physics.BodyType == BodyType.Static: case false when entity.Transform.Anchored:
message.AddMarkup("First, unanchor it.\n"); args.PushMarkup("First, unanchor it.");
return true; return true;
} }

View File

@@ -1,6 +1,7 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.Server.Construction.Components; using Content.Server.Construction.Components;
using Content.Shared.Construction; using Content.Shared.Construction;
using Content.Shared.Examine;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Localization; using Robust.Shared.Localization;
@@ -24,30 +25,32 @@ namespace Content.Server.Construction.Conditions
return machineFrame.IsComplete; return machineFrame.IsComplete;
} }
public bool DoExamine(IEntity entity, FormattedMessage message, bool inDetailsRange) public bool DoExamine(ExaminedEvent args)
{ {
var entity = args.Examined;
if (!entity.TryGetComponent<MachineFrameComponent>(out var machineFrame)) if (!entity.TryGetComponent<MachineFrameComponent>(out var machineFrame))
return false; return false;
if (!machineFrame.HasBoard) if (!machineFrame.HasBoard)
{ {
message.AddMarkup(Loc.GetString("construction-condition-machine-frame-insert-circuit-board-message")); args.PushMarkup(Loc.GetString("construction-condition-machine-frame-insert-circuit-board-message"));
return true; return true;
} }
if (machineFrame.IsComplete) return false; if (machineFrame.IsComplete) return false;
message.AddMarkup(Loc.GetString("construction-condition-machine-frame-requirement-label") + "\n"); args.Message.AddMarkup(Loc.GetString("construction-condition-machine-frame-requirement-label") + "\n");
foreach (var (part, required) in machineFrame.Requirements) foreach (var (part, required) in machineFrame.Requirements)
{ {
var amount = required - machineFrame.Progress[part]; var amount = required - machineFrame.Progress[part];
if(amount == 0) continue; if(amount == 0) continue;
message.AddMarkup(Loc.GetString("construction-condition-machine-frame-required-element-entry", args.Message.AddMarkup(Loc.GetString("construction-condition-machine-frame-required-element-entry",
("amount", amount), ("amount", amount),
("elementName", Loc.GetString(part.ToString()))) ("elementName", Loc.GetString(part.ToString())))
+ "\n"); + "\n");
} }
foreach (var (material, required) in machineFrame.MaterialRequirements) foreach (var (material, required) in machineFrame.MaterialRequirements)
@@ -56,10 +59,10 @@ namespace Content.Server.Construction.Conditions
if(amount == 0) continue; if(amount == 0) continue;
message.AddMarkup(Loc.GetString("construction-condition-machine-frame-required-element-entry", args.Message.AddMarkup(Loc.GetString("construction-condition-machine-frame-required-element-entry",
("amount", amount), ("amount", amount),
("elementName", Loc.GetString(material.ToString()))) ("elementName", Loc.GetString(material.ToString())))
+ "\n"); + "\n");
} }
foreach (var (compName, info) in machineFrame.ComponentRequirements) foreach (var (compName, info) in machineFrame.ComponentRequirements)
@@ -68,7 +71,7 @@ namespace Content.Server.Construction.Conditions
if(amount == 0) continue; if(amount == 0) continue;
message.AddMarkup(Loc.GetString("construction-condition-machine-frame-required-element-entry", args.Message.AddMarkup(Loc.GetString("construction-condition-machine-frame-required-element-entry",
("amount", info.Amount), ("amount", info.Amount),
("elementName", Loc.GetString(info.ExamineName))) ("elementName", Loc.GetString(info.ExamineName)))
+ "\n"); + "\n");
@@ -80,10 +83,10 @@ namespace Content.Server.Construction.Conditions
if(amount == 0) continue; if(amount == 0) continue;
message.AddMarkup(Loc.GetString("construction-condition-machine-frame-required-element-entry", args.Message.AddMarkup(Loc.GetString("construction-condition-machine-frame-required-element-entry",
("amount", info.Amount), ("amount", info.Amount),
("elementName", Loc.GetString(info.ExamineName))) ("elementName", Loc.GetString(info.ExamineName)))
+ "\n"); + "\n");
} }
return true; return true;

View File

@@ -1,6 +1,7 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.Server.Toilet; using Content.Server.Toilet;
using Content.Shared.Construction; using Content.Shared.Construction;
using Content.Shared.Examine;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Localization; using Robust.Shared.Localization;
@@ -19,12 +20,14 @@ namespace Content.Server.Construction.Conditions
return !toilet.LidOpen; return !toilet.LidOpen;
} }
public bool DoExamine(IEntity entity, FormattedMessage message, bool inExamineRange) public bool DoExamine(ExaminedEvent args)
{ {
var entity = args.Examined;
if (!entity.TryGetComponent(out ToiletComponent? toilet)) return false; if (!entity.TryGetComponent(out ToiletComponent? toilet)) return false;
if (!toilet.LidOpen) return false; if (!toilet.LidOpen) return false;
message.AddMarkup(Loc.GetString("construction-condition-toilet-lid-closed") + "\n"); args.PushMarkup(Loc.GetString("construction-condition-toilet-lid-closed") + "\n");
return true; return true;
} }
} }

View File

@@ -2,6 +2,7 @@ using System.Threading.Tasks;
using Content.Server.GameObjects.Components; using Content.Server.GameObjects.Components;
using Content.Server.WireHacking; using Content.Server.WireHacking;
using Content.Shared.Construction; using Content.Shared.Construction;
using Content.Shared.Examine;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Localization; using Robust.Shared.Localization;
@@ -23,17 +24,19 @@ namespace Content.Server.Construction.Conditions
return wires.IsPanelOpen == Open; return wires.IsPanelOpen == Open;
} }
public bool DoExamine(IEntity entity, FormattedMessage message, bool inDetailsRange) public bool DoExamine(ExaminedEvent args)
{ {
var entity = args.Examined;
if (!entity.TryGetComponent(out WiresComponent? wires)) return false; if (!entity.TryGetComponent(out WiresComponent? wires)) return false;
switch (Open) switch (Open)
{ {
case true when !wires.IsPanelOpen: case true when !wires.IsPanelOpen:
message.AddMarkup(Loc.GetString("construction-condition-wire-panel-open") + "\n"); args.PushMarkup(Loc.GetString("construction-condition-wire-panel-open"));
return true; return true;
case false when wires.IsPanelOpen: case false when wires.IsPanelOpen:
message.AddMarkup(Loc.GetString("construction-condition-wire-panel-close") + "\n"); args.PushMarkup(Loc.GetString("construction-condition-wire-panel-close"));
return true; return true;
} }

View File

@@ -59,7 +59,7 @@ namespace Content.Server.Construction
{ {
args.PushMarkup(Loc.GetString( args.PushMarkup(Loc.GetString(
"construction-component-to-create-header", "construction-component-to-create-header",
("targetName", component.Target.Name))); ("targetName", component.Target.Name)) + "\n");
} }
if (component.Edge == null && component.TargetNextEdge != null) if (component.Edge == null && component.TargetNextEdge != null)

View File

@@ -7,6 +7,6 @@ namespace Content.Shared.Construction
public interface IGraphCondition public interface IGraphCondition
{ {
Task<bool> Condition(IEntity entity); Task<bool> Condition(IEntity entity);
bool DoExamine(ExaminedEvent examinedEvent) { return false; } bool DoExamine(ExaminedEvent args) { return false; }
} }
} }

View File

@@ -0,0 +1,4 @@
author: Zumorica
changes:
- type: Fix # One of the following: Add, Remove, Tweak, Fix
message: Fix examine not showing the correct construction steps in certain cases.