Move minds, roles, jobs and objectives to shared (#19679)
This commit is contained in:
43
Content.Shared/Objectives/Interfaces/IObjectiveCondition.cs
Normal file
43
Content.Shared/Objectives/Interfaces/IObjectiveCondition.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using Content.Shared.Mind;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Shared.Objectives.Interfaces
|
||||
{
|
||||
// TODO refactor all of this to be ecs
|
||||
public interface IObjectiveCondition
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns a copy of the IObjectiveCondition which is assigned to the mind.
|
||||
/// </summary>
|
||||
/// <param name="mindId">Mind id to assign to.</param>
|
||||
/// <param name="mind">Mind to assign to.</param>
|
||||
/// <returns>The new IObjectiveCondition.</returns>
|
||||
IObjectiveCondition GetAssigned(EntityUid mindId, MindComponent mind);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the title of the condition.
|
||||
/// </summary>
|
||||
string Title { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the description of the condition.
|
||||
/// </summary>
|
||||
string Description { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns a SpriteSpecifier to be used as an icon for the condition.
|
||||
/// </summary>
|
||||
SpriteSpecifier Icon { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current progress of the condition in % from 0 to 1.
|
||||
/// </summary>
|
||||
/// <returns>Current progress in %.</returns>
|
||||
float Progress { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns a difficulty of the condition.
|
||||
/// </summary>
|
||||
float Difficulty { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Content.Shared.Mind;
|
||||
|
||||
namespace Content.Shared.Objectives.Interfaces
|
||||
{
|
||||
// TODO refactor all of this to be ecs
|
||||
public interface IObjectiveRequirement
|
||||
{
|
||||
/// <summary>
|
||||
/// Checks whether or not the entity & its surroundings are valid to be given the objective.
|
||||
/// </summary>
|
||||
/// <returns>Returns true if objective can be given.</returns>
|
||||
bool CanBeAssigned(EntityUid mindId, MindComponent mind);
|
||||
}
|
||||
}
|
||||
56
Content.Shared/Objectives/Objective.cs
Normal file
56
Content.Shared/Objectives/Objective.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Objectives.Interfaces;
|
||||
|
||||
namespace Content.Shared.Objectives
|
||||
{
|
||||
public sealed class Objective : IEquatable<Objective>
|
||||
{
|
||||
[ViewVariables]
|
||||
public readonly EntityUid MindId;
|
||||
[ViewVariables]
|
||||
public readonly MindComponent Mind;
|
||||
[ViewVariables]
|
||||
public readonly ObjectivePrototype Prototype;
|
||||
private readonly List<IObjectiveCondition> _conditions = new();
|
||||
[ViewVariables]
|
||||
public IReadOnlyList<IObjectiveCondition> Conditions => _conditions;
|
||||
|
||||
public Objective(ObjectivePrototype prototype, EntityUid mindId, MindComponent mind)
|
||||
{
|
||||
Prototype = prototype;
|
||||
MindId = mindId;
|
||||
Mind = mind;
|
||||
foreach (var condition in prototype.Conditions)
|
||||
{
|
||||
_conditions.Add(condition.GetAssigned(mindId, mind));
|
||||
}
|
||||
}
|
||||
|
||||
public bool Equals(Objective? other)
|
||||
{
|
||||
if (other is null) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
if (!Equals(Mind, other.Mind) || !Equals(Prototype, other.Prototype)) return false;
|
||||
if (_conditions.Count != other._conditions.Count) return false;
|
||||
for (var i = 0; i < _conditions.Count; i++)
|
||||
{
|
||||
if (!_conditions[i].Equals(other._conditions[i])) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj)) return false;
|
||||
if (ReferenceEquals(this, obj)) return true;
|
||||
if (obj.GetType() != GetType()) return false;
|
||||
return Equals((Objective) obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(Mind, Prototype, _conditions);
|
||||
}
|
||||
}
|
||||
}
|
||||
63
Content.Shared/Objectives/ObjectivePrototype.cs
Normal file
63
Content.Shared/Objectives/ObjectivePrototype.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System.Linq;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Objectives.Interfaces;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.Objectives
|
||||
{
|
||||
/// <summary>
|
||||
/// Prototype for objectives. Remember that to be assigned, it should be added to one or more objective groups in prototype. E.g. crew, traitor, wizard
|
||||
/// </summary>
|
||||
[Prototype("objective")]
|
||||
public sealed class ObjectivePrototype : IPrototype
|
||||
{
|
||||
[ViewVariables]
|
||||
[IdDataField]
|
||||
public string ID { get; private set; } = default!;
|
||||
|
||||
[DataField("issuer")] public string Issuer { get; private set; } = "Unknown";
|
||||
|
||||
[ViewVariables]
|
||||
public float Difficulty => _difficultyOverride ?? _conditions.Sum(c => c.Difficulty);
|
||||
|
||||
[DataField("conditions", serverOnly: true)]
|
||||
private List<IObjectiveCondition> _conditions = new();
|
||||
[DataField("requirements")]
|
||||
private List<IObjectiveRequirement> _requirements = new();
|
||||
|
||||
[ViewVariables]
|
||||
public IReadOnlyList<IObjectiveCondition> Conditions => _conditions;
|
||||
|
||||
[DataField("canBeDuplicate")]
|
||||
public bool CanBeDuplicateAssignment { get; private set; }
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("difficultyOverride")]
|
||||
private float? _difficultyOverride = null;
|
||||
|
||||
public bool CanBeAssigned(EntityUid mindId, MindComponent mind)
|
||||
{
|
||||
foreach (var requirement in _requirements)
|
||||
{
|
||||
if (!requirement.CanBeAssigned(mindId, mind))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CanBeDuplicateAssignment)
|
||||
{
|
||||
foreach (var objective in mind.AllObjectives)
|
||||
{
|
||||
if (objective.Prototype.ID == ID)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public Objective GetObjective(EntityUid mindId, MindComponent mind)
|
||||
{
|
||||
return new Objective(this, mindId, mind);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user