2022-05-13 00:59:03 -07:00
using System.Linq ;
2023-08-30 21:46:11 -07:00
using Content.Shared.Mind ;
using Content.Shared.Objectives.Interfaces ;
2020-11-22 08:38:07 +01:00
using Robust.Shared.Prototypes ;
2023-08-30 21:46:11 -07:00
namespace Content.Shared.Objectives
2020-11-22 08:38:07 +01:00
{
2022-11-16 15:58:47 -05:00
/// <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>
2020-11-22 08:38:07 +01:00
[Prototype("objective")]
2022-02-16 00:23:23 -07:00
public sealed class ObjectivePrototype : IPrototype
2020-11-22 08:38:07 +01:00
{
[ViewVariables]
2023-01-19 03:56:45 +01:00
[IdDataField]
2023-08-22 18:14:33 -07:00
public string ID { get ; private set ; } = default ! ;
2020-11-22 08:38:07 +01:00
2022-11-16 20:22:11 +01:00
[DataField("issuer")] public string Issuer { get ; private set ; } = "Unknown" ;
2021-03-05 01:08:38 +01:00
2020-11-22 08:38:07 +01:00
[ViewVariables]
2020-12-01 17:05:19 +01:00
public float Difficulty = > _difficultyOverride ? ? _conditions . Sum ( c = > c . Difficulty ) ;
2020-11-22 08:38:07 +01:00
2023-08-30 21:46:11 -07:00
[DataField("conditions", serverOnly: true)]
2020-11-27 11:00:49 +01:00
private List < IObjectiveCondition > _conditions = new ( ) ;
2021-03-05 01:08:38 +01:00
[DataField("requirements")]
2020-11-27 11:00:49 +01:00
private List < IObjectiveRequirement > _requirements = new ( ) ;
2020-11-22 08:38:07 +01:00
2020-12-01 17:05:19 +01:00
[ViewVariables]
public IReadOnlyList < IObjectiveCondition > Conditions = > _conditions ;
2021-03-05 01:08:38 +01:00
[DataField("canBeDuplicate")]
2020-12-01 17:05:19 +01:00
public bool CanBeDuplicateAssignment { get ; private set ; }
2020-11-22 08:38:07 +01:00
[ViewVariables(VVAccess.ReadWrite)]
2021-03-05 01:08:38 +01:00
[DataField("difficultyOverride")]
2020-11-22 08:38:07 +01:00
private float? _difficultyOverride = null ;
2023-08-28 16:53:24 -07:00
public bool CanBeAssigned ( EntityUid mindId , MindComponent mind )
2020-11-22 08:38:07 +01:00
{
foreach ( var requirement in _requirements )
{
2023-08-28 16:53:24 -07:00
if ( ! requirement . CanBeAssigned ( mindId , mind ) )
return false ;
2020-11-22 08:38:07 +01:00
}
2020-12-01 17:05:19 +01:00
if ( ! CanBeDuplicateAssignment )
{
foreach ( var objective in mind . AllObjectives )
{
2023-08-28 16:53:24 -07:00
if ( objective . Prototype . ID = = ID )
return false ;
2020-12-01 17:05:19 +01:00
}
}
2020-11-22 08:38:07 +01:00
return true ;
}
2023-08-28 16:53:24 -07:00
public Objective GetObjective ( EntityUid mindId , MindComponent mind )
2020-12-01 17:05:19 +01:00
{
2023-08-28 16:53:24 -07:00
return new Objective ( this , mindId , mind ) ;
2020-11-22 08:38:07 +01:00
}
}
}