Objectives ecs rework (#19967)
Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using Content.Server.Administration;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Objectives;
|
||||
using Content.Shared.Objectives.Components;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.Prototypes;
|
||||
@@ -39,16 +39,17 @@ namespace Content.Server.Objectives.Commands
|
||||
}
|
||||
|
||||
if (!IoCManager.Resolve<IPrototypeManager>()
|
||||
.TryIndex<ObjectivePrototype>(args[1], out var objectivePrototype))
|
||||
.TryIndex<EntityPrototype>(args[1], out var proto) ||
|
||||
!proto.TryGetComponent<ObjectiveComponent>(out _))
|
||||
{
|
||||
shell.WriteLine($"Can't find matching ObjectivePrototype {objectivePrototype}");
|
||||
shell.WriteLine($"Can't find matching objective prototype {args[1]}");
|
||||
return;
|
||||
}
|
||||
|
||||
var mindSystem = _entityManager.System<SharedMindSystem>();
|
||||
if (!mindSystem.TryAddObjective(mindId, mind, objectivePrototype))
|
||||
if (!minds.TryAddObjective(mindId, mind, args[1]))
|
||||
{
|
||||
shell.WriteLine("Objective requirements dont allow that objective to be added.");
|
||||
// can fail for other reasons so dont pretend to be right
|
||||
shell.WriteLine("Failed to add the objective. Maybe requirements dont allow that objective to be added.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Linq;
|
||||
using Content.Server.Administration;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Objectives.Systems;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
|
||||
@@ -25,7 +26,7 @@ namespace Content.Server.Objectives.Commands
|
||||
}
|
||||
|
||||
var minds = _entities.System<SharedMindSystem>();
|
||||
if (!minds.TryGetMind(player, out _, out var mind))
|
||||
if (!minds.TryGetMind(player, out var mindId, out var mind))
|
||||
{
|
||||
shell.WriteError(LocalizationManager.GetString("shell-target-entity-does-not-have-message", ("missing", "mind")));
|
||||
return;
|
||||
@@ -38,9 +39,20 @@ namespace Content.Server.Objectives.Commands
|
||||
shell.WriteLine("None.");
|
||||
}
|
||||
|
||||
var objectivesSystem = _entities.System<SharedObjectivesSystem>();
|
||||
for (var i = 0; i < objectives.Count; i++)
|
||||
{
|
||||
shell.WriteLine($"- [{i}] {objectives[i].Conditions[0].Title}");
|
||||
var info = objectivesSystem.GetInfo(objectives[i], mindId, mind);
|
||||
if (info == null)
|
||||
{
|
||||
shell.WriteLine($"- [{i}] {objectives[i]} - INVALID");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
var progress = (int) (info.Value.Progress * 100f);
|
||||
shell.WriteLine($"- [{i}] {objectives[i]} ({info.Value.Title}) ({progress}%)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace Content.Server.Objectives.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
if (!minds.TryGetMind(session, out _, out var mind))
|
||||
if (!minds.TryGetMind(session, out var mindId, out var mind))
|
||||
{
|
||||
shell.WriteLine("Can't find the mind.");
|
||||
return;
|
||||
@@ -39,7 +39,7 @@ namespace Content.Server.Objectives.Commands
|
||||
if (int.TryParse(args[1], out var i))
|
||||
{
|
||||
var mindSystem = _entityManager.System<SharedMindSystem>();
|
||||
shell.WriteLine(mindSystem.TryRemoveObjective(mind, i)
|
||||
shell.WriteLine(mindSystem.TryRemoveObjective(mindId, mind, i)
|
||||
? "Objective successfully removed!"
|
||||
: "Objective removing failed. Maybe the index is out of bounds? Check lsobjectives!");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user