Files
tbd-station-14/Content.Server/Objectives/ObjectivesManager.cs
Acruid ca4fd649fe Massive Namespace Cleanup (#3120)
* Engine namespace changes.

* Automated remove redundant using statements.

* Simplified Graphics namespace.

* Apparently the container system stores full type names in the map file.😞 This updates those names.

* API Changes to LocalizationManager.LoadCulture.

* Update submodule to v0.3.2
2021-02-11 01:13:03 -08:00

38 lines
1.1 KiB
C#

#nullable enable
using System.Collections.Generic;
using System.Linq;
using Content.Server.Mobs;
using Content.Server.Objectives.Interfaces;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
namespace Content.Server.Objectives
{
public class ObjectivesManager : IObjectivesManager
{
[Dependency] private IPrototypeManager _prototypeManager = default!;
[Dependency] private IRobustRandom _random = default!;
public IEnumerable<ObjectivePrototype> GetAllPossibleObjectives(Mind mind)
{
return _prototypeManager.EnumeratePrototypes<ObjectivePrototype>().Where(objectivePrototype => objectivePrototype.CanBeAssigned(mind));
}
public ObjectivePrototype? GetRandomObjective(Mind mind)
{
var objectives = GetAllPossibleObjectives(mind).ToList();
_random.Shuffle(objectives);
//to prevent endless loops
foreach (var objective in objectives)
{
if (!_random.Prob(objective.Probability)) continue;
return objective;
}
return null;
}
}
}