Antag preferences and antag prototype (#1264)
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
48
Content.Shared/Roles/AntagPrototype.cs
Normal file
48
Content.Shared/Roles/AntagPrototype.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
|
||||
namespace Content.Shared.Antags
|
||||
{
|
||||
/// <summary>
|
||||
/// Describes information for a single antag.
|
||||
/// </summary>
|
||||
[Prototype("antag")]
|
||||
public class AntagPrototype : IPrototype, IIndexedPrototype
|
||||
{
|
||||
public string ID { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of this antag as displayed to players.
|
||||
/// </summary>
|
||||
public string Name { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The antag's objective, displayed at round-start to the player.
|
||||
/// </summary>
|
||||
public string Objective { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not the antag role is one of the bad guys.
|
||||
/// </summary>
|
||||
public bool Antagonist { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not the player can set the antag role in antag preferences.
|
||||
/// </summary>
|
||||
public bool SetPreference { get; private set; }
|
||||
|
||||
public void LoadFrom(YamlMappingNode mapping)
|
||||
{
|
||||
ID = mapping.GetNode("id").AsString();
|
||||
Name = Loc.GetString(mapping.GetNode("name").ToString());
|
||||
Objective = mapping.GetNode("objective").ToString();
|
||||
Antagonist = mapping.GetNode("antagonist").AsBool();
|
||||
SetPreference = mapping.GetNode("setPreference").AsBool();
|
||||
}
|
||||
}
|
||||
}
|
||||
84
Content.Shared/Roles/JobPrototype.cs
Normal file
84
Content.Shared/Roles/JobPrototype.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
|
||||
namespace Content.Shared.Jobs
|
||||
{
|
||||
/// <summary>
|
||||
/// Describes information for a single job on the station.
|
||||
/// </summary>
|
||||
[Prototype("job")]
|
||||
public class JobPrototype : IPrototype, IIndexedPrototype
|
||||
{
|
||||
public string ID { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of this job as displayed to players.
|
||||
/// </summary>
|
||||
public string Name { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether this job is a head.
|
||||
/// The job system will try to pick heads before other jobs on the same priority level.
|
||||
/// </summary>
|
||||
public bool IsHead { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The total amount of people that can start with this job round-start.
|
||||
/// </summary>
|
||||
public int SpawnPositions { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The total amount of positions available.
|
||||
/// </summary>
|
||||
public int TotalPositions { get; private set; }
|
||||
|
||||
public string StartingGear { get; private set; }
|
||||
|
||||
public string Icon { get; private set; }
|
||||
|
||||
public IReadOnlyCollection<string> Department { get; private set; }
|
||||
public IReadOnlyCollection<string> Access { get; private set; }
|
||||
|
||||
public void LoadFrom(YamlMappingNode mapping)
|
||||
{
|
||||
ID = mapping.GetNode("id").AsString();
|
||||
Name = Loc.GetString(mapping.GetNode("name").ToString());
|
||||
StartingGear = mapping.GetNode("startingGear").ToString();
|
||||
Department = mapping.GetNode("department").AllNodes.Select(i => i.ToString()).ToList();
|
||||
TotalPositions = mapping.GetNode("positions").AsInt();
|
||||
|
||||
if (mapping.TryGetNode("spawnPositions", out var positionsNode))
|
||||
{
|
||||
SpawnPositions = positionsNode.AsInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
SpawnPositions = TotalPositions;
|
||||
}
|
||||
|
||||
if (mapping.TryGetNode("head", out var headNode))
|
||||
{
|
||||
IsHead = headNode.AsBool();
|
||||
}
|
||||
|
||||
if (mapping.TryGetNode("access", out YamlSequenceNode accessNode))
|
||||
{
|
||||
Access = accessNode.Select(i => i.ToString()).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
Access = Array.Empty<string>();
|
||||
}
|
||||
|
||||
if (mapping.TryGetNode("icon", out var iconNode))
|
||||
{
|
||||
Icon = iconNode.AsString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
49
Content.Shared/Roles/StartingGearPrototype.cs
Normal file
49
Content.Shared/Roles/StartingGearPrototype.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines;
|
||||
|
||||
namespace Content.Shared.Jobs
|
||||
{
|
||||
[Prototype("startingGear")]
|
||||
public class StartingGearPrototype : IPrototype, IIndexedPrototype
|
||||
{
|
||||
private string _id;
|
||||
private Dictionary<Slots, string> _equipment;
|
||||
|
||||
public IReadOnlyDictionary<string, string> Inhand => _inHand;
|
||||
/// <summary>
|
||||
/// hand index, item prototype
|
||||
/// </summary>
|
||||
private Dictionary<string, string> _inHand;
|
||||
|
||||
[ViewVariables] public string ID => _id;
|
||||
|
||||
[ViewVariables] public IReadOnlyDictionary<Slots, string> Equipment => _equipment;
|
||||
|
||||
public void LoadFrom(YamlMappingNode mapping)
|
||||
{
|
||||
var serializer = YamlObjectSerializer.NewReader(mapping);
|
||||
|
||||
serializer.DataField(ref _id, "id", string.Empty);
|
||||
serializer.DataField(ref _inHand, "inhand", new Dictionary<string, string>(0));
|
||||
|
||||
var equipment = serializer.ReadDataField<Dictionary<string, string>>("equipment");
|
||||
|
||||
_equipment = equipment.ToDictionary(slotStr =>
|
||||
{
|
||||
var (key, _) = slotStr;
|
||||
if (!Enum.TryParse(key, true, out Slots slot))
|
||||
{
|
||||
throw new Exception($"{key} is an invalid equipment slot.");
|
||||
}
|
||||
|
||||
return slot;
|
||||
}, type => type.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user