Refactor minds to be entities with components, make roles components (#19591)

Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>
Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
This commit is contained in:
DrSmugleaf
2023-08-28 16:53:24 -07:00
committed by GitHub
parent e0ee397af7
commit 15c0211fb2
119 changed files with 1445 additions and 1289 deletions

View File

@@ -1,24 +1,26 @@
using System.Linq;
using Content.Server.GameTicking.Rules;
using Content.Server.Mind;
using Content.Server.Objectives.Interfaces;
using Content.Server.Roles.Jobs;
using Robust.Shared.Random;
using Robust.Shared.Utility;
using Content.Server.GameTicking.Rules;
using Content.Server.Roles;
namespace Content.Server.Objectives.Conditions
{
[DataDefinition]
public sealed partial class RandomTraitorProgressCondition : IObjectiveCondition
{
private Mind.Mind? _target;
// TODO ecs all of this
private EntityUid? _target;
public IObjectiveCondition GetAssigned(Mind.Mind mind)
public IObjectiveCondition GetAssigned(EntityUid mindId, MindComponent mind)
{
//todo shit of a fuck
var entityMgr = IoCManager.Resolve<IEntityManager>();
var traitors = entityMgr.EntitySysManager.GetEntitySystem<TraitorRuleSystem>().GetOtherTraitorsAliveAndConnected(mind).ToList();
List<TraitorRole> removeList = new();
var traitors = entityMgr.System<TraitorRuleSystem>().GetOtherTraitorMindsAliveAndConnected(mind).ToList();
List<EntityUid> removeList = new();
foreach (var traitor in traitors)
{
@@ -28,7 +30,7 @@ namespace Content.Server.Objectives.Conditions
{
if (condition is RandomTraitorProgressCondition)
{
removeList.Add(traitor);
removeList.Add(traitor.Id);
}
}
}
@@ -36,11 +38,11 @@ namespace Content.Server.Objectives.Conditions
foreach (var traitor in removeList)
{
traitors.Remove(traitor);
traitors.RemoveAll(t => t.Id == traitor);
}
if (traitors.Count == 0) return new EscapeShuttleCondition{}; //You were made a traitor by admins, and are the first/only.
return new RandomTraitorProgressCondition { _target = IoCManager.Resolve<IRobustRandom>().Pick(traitors).Mind };
return new RandomTraitorProgressCondition { _target = IoCManager.Resolve<IRobustRandom>().Pick(traitors).Id };
}
public string Title
@@ -48,13 +50,18 @@ namespace Content.Server.Objectives.Conditions
get
{
var targetName = string.Empty;
var jobName = _target?.CurrentJob?.Name ?? "Unknown";
var entities = IoCManager.Resolve<IEntityManager>();
var jobs = entities.System<JobSystem>();
var jobName = jobs.MindTryGetJobName(_target);
if (_target == null)
return Loc.GetString("objective-condition-other-traitor-progress-title", ("targetName", targetName), ("job", jobName));
if (_target.OwnedEntity is {Valid: true} owned)
targetName = IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(owned).EntityName;
if (entities.TryGetComponent(_target, out MindComponent? mind) &&
mind.OwnedEntity is {Valid: true} owned)
{
targetName = entities.GetComponent<MetaDataComponent>(owned).EntityName;
}
return Loc.GetString("objective-condition-other-traitor-progress-title", ("targetName", targetName), ("job", jobName));
}
@@ -66,9 +73,8 @@ namespace Content.Server.Objectives.Conditions
public float Progress
{
get {
var entMan = IoCManager.Resolve<IEntityManager>();
get
{
float total = 0f; // how much progress they have
float max = 0f; // how much progress is needed for 100%
@@ -78,12 +84,16 @@ namespace Content.Server.Objectives.Conditions
return 1f;
}
foreach (var objective in _target.AllObjectives)
var entities = IoCManager.Resolve<IEntityManager>();
if (entities.TryGetComponent(_target, out MindComponent? mind))
{
foreach (var condition in objective.Conditions)
foreach (var objective in mind.AllObjectives)
{
max++; // things can only be up to 100% complete yeah
total += condition.Progress;
foreach (var condition in objective.Conditions)
{
max++; // things can only be up to 100% complete yeah
total += condition.Progress;
}
}
}