* temp commit to save progress * adds objectives * refactors mind.addobjective a bit * better names for my testobjectives which i'll remove later on anyways * nullable errors * some misc fixes * no sorted or set, what was i thinking here? * removes unused imports * added commands * fully implements stealcondition * started uiwork * moved prototypeicon to engine * removes objective class & uiwork * refactors ui to only update when opened adds progresstexturerect * adds some margin * removes some testing code * ignores objectiveprototypes on clientside * fixes * removes using statements for exp * gets the job * always show issuer * locs & _ * giving commands some love * Update Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterBar.cs Co-authored-by: Exp <theexp111@gmail.com> * makes commands use new thingy * string interpolation * good catch exp * loc'd * linq gone * runtime * moves function from engine * oopsie * Update Content.Server/Objectives/Conditions/StealCondition.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * makes messages directed * base call & validation * shuffle once * No? Money down! Co-authored-by: Paul <ritter.paul1+git@googlemail.com> Co-authored-by: Exp <theexp111@gmail.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
54 lines
1.8 KiB
C#
54 lines
1.8 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Content.Server.Mobs;
|
|
using Content.Server.Objectives.Interfaces;
|
|
using Robust.Shared.Interfaces.Random;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Random;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Server.Objectives
|
|
{
|
|
public class ObjectivesManager : IObjectivesManager
|
|
{
|
|
[Dependency] private IPrototypeManager _prototypeManager = default!;
|
|
[Dependency] private IRobustRandom _random = default!;
|
|
|
|
public ObjectivePrototype[] GetAllPossibleObjectives(Mind mind)
|
|
{
|
|
return _prototypeManager.EnumeratePrototypes<ObjectivePrototype>().Where(objectivePrototype => objectivePrototype.CanBeAssigned(mind)).ToArray();
|
|
}
|
|
|
|
public ObjectivePrototype[] GetRandomObjectives(Mind mind, float maxDifficulty = 3)
|
|
{
|
|
var objectives = GetAllPossibleObjectives(mind);
|
|
|
|
//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)
|
|
{
|
|
if (!_random.Prob(objective.Probability)) continue;
|
|
|
|
result.Add(objective);
|
|
currentDifficulty += objective.Difficulty;
|
|
if (currentDifficulty >= maxDifficulty) break;
|
|
}
|
|
}
|
|
|
|
if (currentDifficulty > maxDifficulty) //will almost always happen
|
|
{
|
|
result.Pop();
|
|
}
|
|
|
|
return result.ToArray();
|
|
}
|
|
}
|
|
}
|