Objective Assignment Refactor (#11678)
This commit is contained in:
@@ -193,7 +193,7 @@ public sealed class TraitorRuleSystem : GameRuleSystem
|
|||||||
var difficulty = 0f;
|
var difficulty = 0f;
|
||||||
for (var pick = 0; pick < maxPicks && maxDifficulty > difficulty; pick++)
|
for (var pick = 0; pick < maxPicks && maxDifficulty > difficulty; pick++)
|
||||||
{
|
{
|
||||||
var objective = _objectivesManager.GetRandomObjective(traitorRole.Mind);
|
var objective = _objectivesManager.GetRandomObjective(traitorRole.Mind, "TraitorObjectiveGroups");
|
||||||
if (objective == null) continue;
|
if (objective == null) continue;
|
||||||
if (traitorRole.Mind.TryAddObjective(objective))
|
if (traitorRole.Mind.TryAddObjective(objective))
|
||||||
difficulty += objective.Difficulty;
|
difficulty += objective.Difficulty;
|
||||||
|
|||||||
@@ -2,14 +2,9 @@
|
|||||||
{
|
{
|
||||||
public interface IObjectivesManager
|
public interface IObjectivesManager
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Returns all objectives the provided mind is valid for.
|
|
||||||
/// </summary>
|
|
||||||
IEnumerable<ObjectivePrototype> GetAllPossibleObjectives(Mind.Mind mind);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a randomly picked objective the provided mind is valid for.
|
/// Returns a randomly picked objective the provided mind is valid for.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ObjectivePrototype? GetRandomObjective(Mind.Mind mind);
|
ObjectivePrototype? GetRandomObjective(Mind.Mind mind, string objectiveGroupProto);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ using Robust.Shared.Prototypes;
|
|||||||
|
|
||||||
namespace Content.Server.Objectives
|
namespace Content.Server.Objectives
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Prototype for objectives. Remember that to be assigned, it should be added to one or more objective groups in prototype. E.g. crew, traitor, wizard
|
||||||
|
/// </summary>
|
||||||
[Prototype("objective")]
|
[Prototype("objective")]
|
||||||
public sealed class ObjectivePrototype : IPrototype
|
public sealed class ObjectivePrototype : IPrototype
|
||||||
{
|
{
|
||||||
@@ -13,8 +16,6 @@ namespace Content.Server.Objectives
|
|||||||
|
|
||||||
[DataField("issuer")] public string Issuer { get; private set; } = "Unknown";
|
[DataField("issuer")] public string Issuer { get; private set; } = "Unknown";
|
||||||
|
|
||||||
[DataField("prob")] public float Probability { get; private set; } = 0.3f;
|
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public float Difficulty => _difficultyOverride ?? _conditions.Sum(c => c.Difficulty);
|
public float Difficulty => _difficultyOverride ?? _conditions.Sum(c => c.Difficulty);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Linq;
|
using Content.Server.Objectives.Interfaces;
|
||||||
using Content.Server.Objectives.Interfaces;
|
using Content.Shared.Random.Helpers;
|
||||||
|
using Content.Shared.Random;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
|
|
||||||
@@ -10,21 +11,31 @@ namespace Content.Server.Objectives
|
|||||||
[Dependency] private IPrototypeManager _prototypeManager = default!;
|
[Dependency] private IPrototypeManager _prototypeManager = default!;
|
||||||
[Dependency] private IRobustRandom _random = default!;
|
[Dependency] private IRobustRandom _random = default!;
|
||||||
|
|
||||||
public IEnumerable<ObjectivePrototype> GetAllPossibleObjectives(Mind.Mind mind)
|
public ObjectivePrototype? GetRandomObjective(Mind.Mind mind, string objectiveGroupProto)
|
||||||
{
|
{
|
||||||
return _prototypeManager.EnumeratePrototypes<ObjectivePrototype>().Where(objectivePrototype => objectivePrototype.CanBeAssigned(mind));
|
if (!_prototypeManager.TryIndex<WeightedRandomPrototype>(objectiveGroupProto, out var groups))
|
||||||
|
{
|
||||||
|
Logger.Error("Tried to get a random objective, but can't index WeightedRandomPrototype " + objectiveGroupProto);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObjectivePrototype? GetRandomObjective(Mind.Mind mind)
|
// yeah the old 'preventing infinite loops' thing wasn't super elegant either and it mislead people on what exactly it did
|
||||||
|
var tries = 0;
|
||||||
|
while (tries < 20)
|
||||||
{
|
{
|
||||||
var objectives = GetAllPossibleObjectives(mind).ToList();
|
var groupName = groups.Pick(_random);
|
||||||
_random.Shuffle(objectives);
|
|
||||||
|
|
||||||
//to prevent endless loops
|
if (!_prototypeManager.TryIndex<WeightedRandomPrototype>(groupName, out var group))
|
||||||
foreach (var objective in objectives)
|
|
||||||
{
|
{
|
||||||
if (!_random.Prob(objective.Probability)) continue;
|
Logger.Error("Couldn't index objective group prototype" + groupName);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_prototypeManager.TryIndex<ObjectivePrototype>(group.Pick(_random), out var objective)
|
||||||
|
&& objective.CanBeAssigned(mind))
|
||||||
return objective;
|
return objective;
|
||||||
|
else
|
||||||
|
tries++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
41
Resources/Prototypes/Objectives/objectiveGroups.yml
Normal file
41
Resources/Prototypes/Objectives/objectiveGroups.yml
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
# Traitor
|
||||||
|
- type: weightedRandom
|
||||||
|
id: TraitorObjectiveGroups
|
||||||
|
weights:
|
||||||
|
TraitorObjectiveGroupSteal: 1
|
||||||
|
TraitorObjectiveGroupKill: 1
|
||||||
|
TraitorObjectiveGroupState: 1 #As in, something about your character. Alive, dead, arrested, gained an ability...
|
||||||
|
TraitorObjectiveGroupSocial: 1 #Involves helping/harming others without killing them or stealing their stuff
|
||||||
|
|
||||||
|
- type: weightedRandom
|
||||||
|
id: TraitorObjectiveGroupSteal
|
||||||
|
weights:
|
||||||
|
CaptainIDStealObjective: 1
|
||||||
|
CMOHyposprayStealObjective: 1
|
||||||
|
RDHardsuitStealObjective: 1
|
||||||
|
NukeDiskStealObjective: 1
|
||||||
|
IDComputerBoardStealObjective: 1
|
||||||
|
MagbootsStealObjective: 1
|
||||||
|
SupplyConsoleBoardStealObjective: 1
|
||||||
|
CorgiMeatStealObjective: 1
|
||||||
|
CaptainGunStealObjective: 0.5
|
||||||
|
CaptainJetpackStealObjective: 0.5
|
||||||
|
|
||||||
|
- type: weightedRandom
|
||||||
|
id: TraitorObjectiveGroupKill
|
||||||
|
weights:
|
||||||
|
KillRandomObjective: 1
|
||||||
|
|
||||||
|
- type: weightedRandom
|
||||||
|
id: TraitorObjectiveGroupState
|
||||||
|
weights:
|
||||||
|
EscapeShuttleObjective: 1
|
||||||
|
DieObjective: 0.05
|
||||||
|
|
||||||
|
- type: weightedRandom
|
||||||
|
id: TraitorObjectiveGroupSocial
|
||||||
|
weights:
|
||||||
|
RandomTraitorAliveObjective: 1
|
||||||
|
RandomTraitorProgressObjective: 1
|
||||||
|
|
||||||
|
#Changeling, crew, wizard, when you code it...
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
id: CaptainIDStealObjective
|
id: CaptainIDStealObjective
|
||||||
issuer: syndicate
|
issuer: syndicate
|
||||||
difficultyOverride: 2.75
|
difficultyOverride: 2.75
|
||||||
prob: 0.2
|
|
||||||
requirements:
|
requirements:
|
||||||
- !type:TraitorRequirement {}
|
- !type:TraitorRequirement {}
|
||||||
- !type:IncompatibleConditionsRequirement
|
- !type:IncompatibleConditionsRequirement
|
||||||
@@ -42,7 +41,6 @@
|
|||||||
- type: objective
|
- type: objective
|
||||||
id: DieObjective
|
id: DieObjective
|
||||||
issuer: syndicate
|
issuer: syndicate
|
||||||
prob: 0.03
|
|
||||||
requirements:
|
requirements:
|
||||||
- !type:TraitorRequirement {}
|
- !type:TraitorRequirement {}
|
||||||
- !type:IncompatibleConditionsRequirement
|
- !type:IncompatibleConditionsRequirement
|
||||||
@@ -56,7 +54,6 @@
|
|||||||
id: CMOHyposprayStealObjective
|
id: CMOHyposprayStealObjective
|
||||||
issuer: syndicate
|
issuer: syndicate
|
||||||
difficultyOverride: 2.75
|
difficultyOverride: 2.75
|
||||||
prob: 0.2
|
|
||||||
requirements:
|
requirements:
|
||||||
- !type:TraitorRequirement {}
|
- !type:TraitorRequirement {}
|
||||||
- !type:IncompatibleConditionsRequirement
|
- !type:IncompatibleConditionsRequirement
|
||||||
@@ -73,7 +70,6 @@
|
|||||||
id: RDHardsuitStealObjective
|
id: RDHardsuitStealObjective
|
||||||
issuer: syndicate
|
issuer: syndicate
|
||||||
difficultyOverride: 2.75
|
difficultyOverride: 2.75
|
||||||
prob: 0.2
|
|
||||||
requirements:
|
requirements:
|
||||||
- !type:TraitorRequirement {}
|
- !type:TraitorRequirement {}
|
||||||
- !type:IncompatibleConditionsRequirement
|
- !type:IncompatibleConditionsRequirement
|
||||||
@@ -89,7 +85,6 @@
|
|||||||
- type: objective
|
- type: objective
|
||||||
id: NukeDiskStealObjective
|
id: NukeDiskStealObjective
|
||||||
issuer: syndicate
|
issuer: syndicate
|
||||||
prob: 0.2
|
|
||||||
requirements:
|
requirements:
|
||||||
- !type:TraitorRequirement {}
|
- !type:TraitorRequirement {}
|
||||||
- !type:IncompatibleConditionsRequirement
|
- !type:IncompatibleConditionsRequirement
|
||||||
@@ -116,7 +111,6 @@
|
|||||||
- type: objective
|
- type: objective
|
||||||
id: IDComputerBoardStealObjective
|
id: IDComputerBoardStealObjective
|
||||||
issuer: syndicate
|
issuer: syndicate
|
||||||
prob: 0.2
|
|
||||||
requirements:
|
requirements:
|
||||||
- !type:TraitorRequirement {}
|
- !type:TraitorRequirement {}
|
||||||
- !type:IncompatibleConditionsRequirement
|
- !type:IncompatibleConditionsRequirement
|
||||||
@@ -133,7 +127,6 @@
|
|||||||
id: MagbootsStealObjective
|
id: MagbootsStealObjective
|
||||||
issuer: syndicate
|
issuer: syndicate
|
||||||
difficultyOverride: 2.75
|
difficultyOverride: 2.75
|
||||||
prob: 0.2
|
|
||||||
requirements:
|
requirements:
|
||||||
- !type:TraitorRequirement {}
|
- !type:TraitorRequirement {}
|
||||||
- !type:IncompatibleConditionsRequirement
|
- !type:IncompatibleConditionsRequirement
|
||||||
@@ -149,7 +142,6 @@
|
|||||||
- type: objective
|
- type: objective
|
||||||
id: SupplyConsoleBoardStealObjective
|
id: SupplyConsoleBoardStealObjective
|
||||||
issuer: syndicate
|
issuer: syndicate
|
||||||
prob: 0.2
|
|
||||||
requirements:
|
requirements:
|
||||||
- !type:TraitorRequirement {}
|
- !type:TraitorRequirement {}
|
||||||
- !type:IncompatibleConditionsRequirement
|
- !type:IncompatibleConditionsRequirement
|
||||||
@@ -165,7 +157,6 @@
|
|||||||
- type: objective
|
- type: objective
|
||||||
id: CorgiMeatStealObjective
|
id: CorgiMeatStealObjective
|
||||||
issuer: syndicate
|
issuer: syndicate
|
||||||
prob: 0.2
|
|
||||||
requirements:
|
requirements:
|
||||||
- !type:TraitorRequirement {}
|
- !type:TraitorRequirement {}
|
||||||
- !type:IncompatibleConditionsRequirement
|
- !type:IncompatibleConditionsRequirement
|
||||||
@@ -182,7 +173,6 @@
|
|||||||
id: CaptainGunStealObjective
|
id: CaptainGunStealObjective
|
||||||
issuer: syndicate
|
issuer: syndicate
|
||||||
difficultyOverride: 2.75
|
difficultyOverride: 2.75
|
||||||
prob: 0.1
|
|
||||||
requirements:
|
requirements:
|
||||||
- !type:TraitorRequirement {}
|
- !type:TraitorRequirement {}
|
||||||
- !type:IncompatibleConditionsRequirement
|
- !type:IncompatibleConditionsRequirement
|
||||||
@@ -199,7 +189,6 @@
|
|||||||
id: CaptainJetpackStealObjective
|
id: CaptainJetpackStealObjective
|
||||||
issuer: syndicate
|
issuer: syndicate
|
||||||
difficultyOverride: 2.75
|
difficultyOverride: 2.75
|
||||||
prob: 0.1
|
|
||||||
requirements:
|
requirements:
|
||||||
- !type:TraitorRequirement {}
|
- !type:TraitorRequirement {}
|
||||||
- !type:IncompatibleConditionsRequirement
|
- !type:IncompatibleConditionsRequirement
|
||||||
|
|||||||
Reference in New Issue
Block a user