Move minds, roles, jobs and objectives to shared (#19679)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Content.Server.Administration;
|
||||
using Content.Server.Mind;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Objectives;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.Prototypes;
|
||||
@@ -30,7 +31,7 @@ namespace Content.Server.Objectives.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
var minds = _entityManager.System<MindSystem>();
|
||||
var minds = _entityManager.System<SharedMindSystem>();
|
||||
if (!minds.TryGetMind(data, out var mindId, out var mind))
|
||||
{
|
||||
shell.WriteLine("Can't find the mind.");
|
||||
@@ -44,7 +45,7 @@ namespace Content.Server.Objectives.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
var mindSystem = _entityManager.System<MindSystem>();
|
||||
var mindSystem = _entityManager.System<SharedMindSystem>();
|
||||
if (!mindSystem.TryAddObjective(mindId, mind, objectivePrototype))
|
||||
{
|
||||
shell.WriteLine("Objective requirements dont allow that objective to be added.");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Administration;
|
||||
using Content.Server.Mind;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Mind;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Content.Server.Objectives.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
var minds = _entities.System<MindSystem>();
|
||||
var minds = _entities.System<SharedMindSystem>();
|
||||
if (!minds.TryGetMind(player, out _, out var mind))
|
||||
{
|
||||
shell.WriteError(LocalizationManager.GetString("shell-target-entity-does-not-have-message", ("missing", "mind")));
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Content.Server.Administration;
|
||||
using Content.Server.Mind;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Mind;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Content.Server.Objectives.Commands
|
||||
}
|
||||
|
||||
var mgr = IoCManager.Resolve<IPlayerManager>();
|
||||
var minds = _entityManager.System<MindSystem>();
|
||||
var minds = _entityManager.System<SharedMindSystem>();
|
||||
if (!mgr.TryGetSessionByUsername(args[0], out var session))
|
||||
{
|
||||
shell.WriteLine("Can't find the playerdata.");
|
||||
@@ -38,7 +38,7 @@ namespace Content.Server.Objectives.Commands
|
||||
|
||||
if (int.TryParse(args[1], out var i))
|
||||
{
|
||||
var mindSystem = _entityManager.System<MindSystem>();
|
||||
var mindSystem = _entityManager.System<SharedMindSystem>();
|
||||
shell.WriteLine(mindSystem.TryRemoveObjective(mind, i)
|
||||
? "Objective successfully removed!"
|
||||
: "Objective removing failed. Maybe the index is out of bounds? Check lsobjectives!");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Content.Server.Mind;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Objectives.Interfaces;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Content.Server.Objectives.Conditions
|
||||
get
|
||||
{
|
||||
var entityManager = IoCManager.Resolve<EntityManager>();
|
||||
var mindSystem = entityManager.System<MindSystem>();
|
||||
var mindSystem = entityManager.System<SharedMindSystem>();
|
||||
return _mind == null || mindSystem.IsCharacterDeadIc(_mind) ? 1f : 0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Content.Server.Mind;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using Content.Server.Shuttles.Systems;
|
||||
using Content.Shared.Cuffs.Components;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Objectives.Interfaces;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Content.Server.Objectives.Conditions
|
||||
{
|
||||
get {
|
||||
var entMan = IoCManager.Resolve<IEntityManager>();
|
||||
var mindSystem = entMan.System<MindSystem>();
|
||||
var mindSystem = entMan.System<SharedMindSystem>();
|
||||
|
||||
if (_mind?.OwnedEntity == null
|
||||
|| !entMan.TryGetComponent<TransformComponent>(_mind.OwnedEntity, out var xform))
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using Content.Server.Mind;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using Content.Server.Roles.Jobs;
|
||||
using Content.Server.Shuttles.Systems;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Mobs.Systems;
|
||||
using Content.Shared.Objectives.Interfaces;
|
||||
using Content.Shared.Roles.Jobs;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -13,8 +13,8 @@ namespace Content.Server.Objectives.Conditions
|
||||
{
|
||||
// TODO refactor all of this to be ecs
|
||||
protected IEntityManager EntityManager => IoCManager.Resolve<IEntityManager>();
|
||||
protected MindSystem Minds => EntityManager.System<MindSystem>();
|
||||
protected JobSystem Jobs => EntityManager.System<JobSystem>();
|
||||
protected SharedMindSystem Minds => EntityManager.System<SharedMindSystem>();
|
||||
protected SharedJobSystem Jobs => EntityManager.System<SharedJobSystem>();
|
||||
protected MobStateSystem MobStateSystem => EntityManager.System<MobStateSystem>();
|
||||
protected EntityUid? TargetMindId;
|
||||
protected MindComponent? TargetMind => EntityManager.GetComponentOrNull<MindComponent>(TargetMindId);
|
||||
@@ -52,7 +52,7 @@ namespace Content.Server.Objectives.Conditions
|
||||
return 1f;
|
||||
|
||||
var entMan = IoCManager.Resolve<EntityManager>();
|
||||
var mindSystem = entMan.System<MindSystem>();
|
||||
var mindSystem = entMan.System<SharedMindSystem>();
|
||||
if (mindSystem.IsCharacterDeadIc(TargetMind))
|
||||
return 1f;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Mind;
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Mind.Components;
|
||||
using Content.Shared.Mobs.Components;
|
||||
using Content.Shared.Objectives.Interfaces;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Objectives.Conditions;
|
||||
@@ -17,7 +17,7 @@ public sealed partial class KillRandomHeadCondition : KillPersonCondition
|
||||
|
||||
var allHumans = EntityManager.EntityQuery<MindContainerComponent>(true).Where(mc =>
|
||||
{
|
||||
var entity = EntityManager.GetComponentOrNull<MindComponent>(mc.Mind)?.OwnedEntity;
|
||||
var entity = EntityManagerExt.GetComponentOrNull<MindComponent>(EntityManager, (EntityUid?) mc.Mind)?.OwnedEntity;
|
||||
|
||||
if (entity == default)
|
||||
return false;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using Content.Server.Mind;
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using Content.Shared.Humanoid;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Mind.Components;
|
||||
using Content.Shared.Mobs.Components;
|
||||
using Content.Shared.Objectives.Interfaces;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Objectives.Conditions;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Linq;
|
||||
using Content.Server.GameTicking.Rules;
|
||||
using Content.Server.Mind;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using Content.Server.Roles.Jobs;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Objectives.Interfaces;
|
||||
using Content.Shared.Roles.Jobs;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Content.Server.Objectives.Conditions
|
||||
{
|
||||
var entityMgr = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
var traitors = entityMgr.System<TraitorRuleSystem>().GetOtherTraitorMindsAliveAndConnected(mind).ToList();
|
||||
var traitors = Enumerable.ToList<(EntityUid Id, MindComponent Mind)>(entityMgr.System<TraitorRuleSystem>().GetOtherTraitorMindsAliveAndConnected(mind));
|
||||
|
||||
if (traitors.Count == 0)
|
||||
return new EscapeShuttleCondition(); //You were made a traitor by admins, and are the first/only.
|
||||
@@ -30,7 +30,7 @@ namespace Content.Server.Objectives.Conditions
|
||||
{
|
||||
var targetName = string.Empty;
|
||||
var ents = IoCManager.Resolve<IEntityManager>();
|
||||
var jobs = ents.System<JobSystem>();
|
||||
var jobs = ents.System<SharedJobSystem>();
|
||||
var jobName = jobs.MindTryGetJobName(_targetMind);
|
||||
|
||||
if (_targetMind == null)
|
||||
@@ -55,7 +55,7 @@ namespace Content.Server.Objectives.Conditions
|
||||
get
|
||||
{
|
||||
var entityManager = IoCManager.Resolve<EntityManager>();
|
||||
var mindSystem = entityManager.System<MindSystem>();
|
||||
var mindSystem = entityManager.System<SharedMindSystem>();
|
||||
return !entityManager.TryGetComponent(_targetMind, out MindComponent? mind) ||
|
||||
!mindSystem.IsCharacterDeadIc(mind)
|
||||
? 1f
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Linq;
|
||||
using Content.Server.GameTicking.Rules;
|
||||
using Content.Server.Mind;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using Content.Server.Roles.Jobs;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Objectives.Interfaces;
|
||||
using Content.Shared.Roles.Jobs;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace Content.Server.Objectives.Conditions
|
||||
{
|
||||
var targetName = string.Empty;
|
||||
var entities = IoCManager.Resolve<IEntityManager>();
|
||||
var jobs = entities.System<JobSystem>();
|
||||
var jobs = entities.System<SharedJobSystem>();
|
||||
var jobName = jobs.MindTryGetJobName(_targetMind);
|
||||
|
||||
if (_targetMind == null)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Content.Server.Mind;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Objectives.Interfaces;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
using Content.Server.Mind;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Objectives.Interfaces
|
||||
{
|
||||
// TODO refactor all of this to be ecs
|
||||
public interface IObjectiveCondition : IEquatable<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; }
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using Content.Server.Mind;
|
||||
|
||||
namespace Content.Server.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);
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
using Content.Server.Mind;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
|
||||
namespace Content.Server.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Mind;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.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")]
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Server.Mind;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Objectives;
|
||||
using Content.Shared.Random;
|
||||
using Content.Shared.Random.Helpers;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Content.Server.Mind;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Objectives.Interfaces;
|
||||
|
||||
namespace Content.Server.Objectives.Requirements
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Content.Server.Mind;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Objectives.Interfaces;
|
||||
|
||||
namespace Content.Server.Objectives.Requirements
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Content.Server.GameTicking.Rules;
|
||||
using Content.Server.Mind;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Objectives.Interfaces;
|
||||
|
||||
namespace Content.Server.Objectives.Requirements
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Content.Server.Mind;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using Content.Server.Roles.Jobs;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Objectives.Interfaces;
|
||||
using Content.Shared.Roles;
|
||||
using Content.Shared.Roles.Jobs;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.Objectives.Requirements
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Server.Mind;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using Content.Server.Roles;
|
||||
using Content.Server.Roles;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Objectives.Interfaces;
|
||||
using Content.Shared.Roles;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Content.Server.Objectives.Requirements
|
||||
@@ -11,7 +12,7 @@ namespace Content.Server.Objectives.Requirements
|
||||
{
|
||||
public bool CanBeAssigned(EntityUid mindId, MindComponent mind)
|
||||
{
|
||||
var roleSystem = IoCManager.Resolve<IEntityManager>().System<RoleSystem>();
|
||||
var roleSystem = IoCManager.Resolve<IEntityManager>().System<SharedRoleSystem>();
|
||||
return roleSystem.MindHasRole<TraitorRoleComponent>(mindId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user