* basic implementation

* minor fixes

* objectives temp commit

* proper onstart bind

* changes all conditions to be bound to a mind-instance

* oops

* oops v2

* adds possiblity to enable duplicate assignment of objective
equal objectives are unable to be added

* minor fixes, adds greentext

* refactors incompatability to be defined by requirements

* fixes a wrong whitespace

* minor fix

* addressed reviews v1

* address reviews v2

Co-authored-by: Exp <theexp111@gmail.com>

* final sweep

* adds/refactors traitor&sss cvars

* Update Content.Server/Mobs/Mind.cs

* never trust github web

* adds datasets & makes codewords use them

* addresses exp's reviews

* addressed zumos reviews

Co-authored-by: Paul <ritter.paul1+git@googlemail.com>
Co-authored-by: Exp <theexp111@gmail.com>
This commit is contained in:
Paul Ritter
2020-12-01 17:05:19 +01:00
committed by GitHub
parent 602f37e70c
commit f7c09fbd7e
28 changed files with 1875 additions and 107 deletions

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
#nullable enable
using System.Collections.Generic;
using System.Linq;
using Content.Server.Mobs;
using Content.Server.Objectives.Interfaces;
@@ -15,39 +16,24 @@ namespace Content.Server.Objectives
[Dependency] private IPrototypeManager _prototypeManager = default!;
[Dependency] private IRobustRandom _random = default!;
public ObjectivePrototype[] GetAllPossibleObjectives(Mind mind)
public List<ObjectivePrototype> GetAllPossibleObjectives(Mind mind)
{
return _prototypeManager.EnumeratePrototypes<ObjectivePrototype>().Where(objectivePrototype => objectivePrototype.CanBeAssigned(mind)).ToArray();
return _prototypeManager.EnumeratePrototypes<ObjectivePrototype>().Where(objectivePrototype => objectivePrototype.CanBeAssigned(mind)).ToList();
}
public ObjectivePrototype[] GetRandomObjectives(Mind mind, float maxDifficulty = 3)
public ObjectivePrototype? GetRandomObjective(Mind mind)
{
var objectives = GetAllPossibleObjectives(mind);
_random.Shuffle(objectives);
//to prevent endless loops
if(objectives.Length == 0 || objectives.Sum(o => o.Difficulty) == 0f) return objectives;
var result = new List<ObjectivePrototype>();
var currentDifficulty = 0f;
_random.Shuffle(objectives);
while (currentDifficulty < maxDifficulty)
foreach (var objective in objectives)
{
foreach (var objective in objectives)
{
if (!_random.Prob(objective.Probability)) continue;
result.Add(objective);
currentDifficulty += objective.Difficulty;
if (currentDifficulty >= maxDifficulty) break;
}
if (!_random.Prob(objective.Probability)) continue;
return objective;
}
if (currentDifficulty > maxDifficulty) //will almost always happen
{
result.Pop();
}
return result.ToArray();
return null;
}
}
}