Re-organize all projects (#4166)
This commit is contained in:
55
Content.Server/Objectives/Commands/AddObjectiveCommand.cs
Normal file
55
Content.Server/Objectives/Commands/AddObjectiveCommand.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
#nullable enable
|
||||
using Content.Server.Administration;
|
||||
using Content.Server.Players;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Objectives.Commands
|
||||
{
|
||||
[AdminCommand(AdminFlags.Admin)]
|
||||
public class AddObjectiveCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "addobjective";
|
||||
public string Description => "Adds an objective to the player's mind.";
|
||||
public string Help => "addobjective <username> <objectiveID>";
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length != 2)
|
||||
{
|
||||
shell.WriteLine("Expected exactly 2 arguments.");
|
||||
return;
|
||||
}
|
||||
|
||||
var mgr = IoCManager.Resolve<IPlayerManager>();
|
||||
if (!mgr.TryGetPlayerDataByUsername(args[0], out var data))
|
||||
{
|
||||
shell.WriteLine("Can't find the playerdata.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var mind = data.ContentData()?.Mind;
|
||||
if (mind == null)
|
||||
{
|
||||
shell.WriteLine("Can't find the mind.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IoCManager.Resolve<IPrototypeManager>()
|
||||
.TryIndex<ObjectivePrototype>(args[1], out var objectivePrototype))
|
||||
{
|
||||
shell.WriteLine($"Can't find matching ObjectivePrototype {objectivePrototype}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mind.TryAddObjective(objectivePrototype))
|
||||
{
|
||||
shell.WriteLine("Objective requirements dont allow that objective to be added.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
52
Content.Server/Objectives/Commands/ListObjectivesCommand.cs
Normal file
52
Content.Server/Objectives/Commands/ListObjectivesCommand.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
#nullable enable
|
||||
using System.Linq;
|
||||
using Content.Server.Administration;
|
||||
using Content.Server.Players;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Objectives.Commands
|
||||
{
|
||||
[AdminCommand(AdminFlags.Admin)]
|
||||
public class ListObjectivesCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "lsobjectives";
|
||||
public string Description => "Lists all objectives in a players mind.";
|
||||
public string Help => "lsobjectives [<username>]";
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
var player = shell.Player as IPlayerSession;
|
||||
IPlayerData? data;
|
||||
if (args.Length == 0 && player != null)
|
||||
{
|
||||
data = player.Data;
|
||||
}
|
||||
else if (player == null || !IoCManager.Resolve<IPlayerManager>().TryGetPlayerDataByUsername(args[0], out data))
|
||||
{
|
||||
shell.WriteLine("Can't find the playerdata.");
|
||||
return;
|
||||
}
|
||||
|
||||
var mind = data.ContentData()?.Mind;
|
||||
if (mind == null)
|
||||
{
|
||||
shell.WriteLine("Can't find the mind.");
|
||||
return;
|
||||
}
|
||||
|
||||
shell.WriteLine($"Objectives for player {data.UserId}:");
|
||||
var objectives = mind.AllObjectives.ToList();
|
||||
if (objectives.Count == 0)
|
||||
{
|
||||
shell.WriteLine("None.");
|
||||
}
|
||||
for (var i = 0; i < objectives.Count; i++)
|
||||
{
|
||||
shell.WriteLine($"- [{i}] {objectives[i]}");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
52
Content.Server/Objectives/Commands/RemoveObjectiveCommand.cs
Normal file
52
Content.Server/Objectives/Commands/RemoveObjectiveCommand.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
#nullable enable
|
||||
using Content.Server.Administration;
|
||||
using Content.Server.Players;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Objectives.Commands
|
||||
{
|
||||
[AdminCommand(AdminFlags.Admin)]
|
||||
public class RemoveObjectiveCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "rmobjective";
|
||||
public string Description => "Removes an objective from the player's mind.";
|
||||
public string Help => "rmobjective <username> <index>";
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length != 2)
|
||||
{
|
||||
shell.WriteLine("Expected exactly 2 arguments.");
|
||||
return;
|
||||
}
|
||||
|
||||
var mgr = IoCManager.Resolve<IPlayerManager>();
|
||||
if (mgr.TryGetPlayerDataByUsername(args[0], out var data))
|
||||
{
|
||||
var mind = data.ContentData()?.Mind;
|
||||
if (mind == null)
|
||||
{
|
||||
shell.WriteLine("Can't find the mind.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (int.TryParse(args[1], out var i))
|
||||
{
|
||||
shell.WriteLine(mind.TryRemoveObjective(i)
|
||||
? "Objective successfully removed!"
|
||||
: "Objective removing failed. Maybe the index is out of bounds? Check lsobjectives!");
|
||||
}
|
||||
else
|
||||
{
|
||||
shell.WriteLine($"Invalid index {args[1]}!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
shell.WriteLine("Can't find the playerdata.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
#nullable enable
|
||||
using Content.Server.Mobs;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using Content.Shared.GameObjects.Components.Mobs.State;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
@@ -13,9 +11,9 @@ namespace Content.Server.Objectives.Conditions
|
||||
[DataDefinition]
|
||||
public class DieCondition : IObjectiveCondition
|
||||
{
|
||||
private Mind? _mind;
|
||||
private Mind.Mind? _mind;
|
||||
|
||||
public IObjectiveCondition GetAssigned(Mind mind)
|
||||
public IObjectiveCondition GetAssigned(Mind.Mind mind)
|
||||
{
|
||||
return new DieCondition {_mind = mind};
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#nullable enable
|
||||
using Content.Server.Mobs;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using Content.Shared.GameObjects.Components.Mobs.State;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -9,8 +7,8 @@ namespace Content.Server.Objectives.Conditions
|
||||
{
|
||||
public abstract class KillPersonCondition : IObjectiveCondition
|
||||
{
|
||||
protected Mind? Target;
|
||||
public abstract IObjectiveCondition GetAssigned(Mind mind);
|
||||
protected Mind.Mind? Target;
|
||||
public abstract IObjectiveCondition GetAssigned(Mind.Mind mind);
|
||||
|
||||
public string Title => Loc.GetString("Kill {0}", Target?.OwnedEntity?.Name ?? "");
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using System.Linq;
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
using Content.Server.Mobs;
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using Content.Shared.GameObjects.Components.Mobs.State;
|
||||
using Content.Shared.MobState;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -15,7 +14,7 @@ namespace Content.Server.Objectives.Conditions
|
||||
[DataDefinition]
|
||||
public class KillRandomPersonCondition : KillPersonCondition
|
||||
{
|
||||
public override IObjectiveCondition GetAssigned(Mind mind)
|
||||
public override IObjectiveCondition GetAssigned(Mind.Mind mind)
|
||||
{
|
||||
var entityMgr = IoCManager.Resolve<IEntityManager>();
|
||||
var allHumans = entityMgr.ComponentManager.EntityQuery<MindComponent>(true).Where(mc =>
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#nullable enable
|
||||
using Content.Server.Mobs;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using Content.Shared.GameObjects.Components.Mobs.State;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
@@ -13,9 +11,9 @@ namespace Content.Server.Objectives.Conditions
|
||||
[DataDefinition]
|
||||
public class StayAliveCondition : IObjectiveCondition
|
||||
{
|
||||
private Mind? _mind;
|
||||
private Mind.Mind? _mind;
|
||||
|
||||
public IObjectiveCondition GetAssigned(Mind mind)
|
||||
public IObjectiveCondition GetAssigned(Mind.Mind mind)
|
||||
{
|
||||
return new StayAliveCondition {_mind = mind};
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using Content.Server.Containers;
|
||||
using Content.Server.GameObjects;
|
||||
using Content.Server.Mobs;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Containers;
|
||||
@@ -19,11 +19,11 @@ namespace Content.Server.Objectives.Conditions
|
||||
[DataDefinition]
|
||||
public class StealCondition : IObjectiveCondition, ISerializationHooks
|
||||
{
|
||||
private Mind? _mind;
|
||||
private Mind.Mind? _mind;
|
||||
[DataField("prototype")] private string _prototypeId = string.Empty;
|
||||
[DataField("amount")] private int _amount = 1;
|
||||
|
||||
public IObjectiveCondition GetAssigned(Mind mind)
|
||||
public IObjectiveCondition GetAssigned(Mind.Mind mind)
|
||||
{
|
||||
return new StealCondition
|
||||
{
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using Content.Server.Mobs;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Objectives.Interfaces
|
||||
@@ -12,7 +11,7 @@ namespace Content.Server.Objectives.Interfaces
|
||||
/// </summary>
|
||||
/// <param name="mind">Mind to assign to.</param>
|
||||
/// <returns>The new IObjectiveCondition.</returns>
|
||||
IObjectiveCondition GetAssigned(Mind mind);
|
||||
IObjectiveCondition GetAssigned(Mind.Mind mind);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the title of the condition.
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using Content.Server.Mobs;
|
||||
|
||||
namespace Content.Server.Objectives.Interfaces
|
||||
namespace Content.Server.Objectives.Interfaces
|
||||
{
|
||||
public interface IObjectiveRequirement
|
||||
{
|
||||
@@ -8,6 +6,6 @@ namespace Content.Server.Objectives.Interfaces
|
||||
/// Checks whether or not the entity & its surroundings are valid to be given the objective.
|
||||
/// </summary>
|
||||
/// <returns>Returns true if objective can be given.</returns>
|
||||
bool CanBeAssigned(Mind mind);
|
||||
bool CanBeAssigned(Mind.Mind mind);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Mobs;
|
||||
|
||||
namespace Content.Server.Objectives.Interfaces
|
||||
{
|
||||
@@ -8,11 +7,11 @@ namespace Content.Server.Objectives.Interfaces
|
||||
/// <summary>
|
||||
/// Returns all objectives the provided mind is valid for.
|
||||
/// </summary>
|
||||
IEnumerable<ObjectivePrototype> GetAllPossibleObjectives(Mind mind);
|
||||
IEnumerable<ObjectivePrototype> GetAllPossibleObjectives(Mind.Mind mind);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a randomly picked objective the provided mind is valid for.
|
||||
/// </summary>
|
||||
ObjectivePrototype? GetRandomObjective(Mind mind);
|
||||
ObjectivePrototype? GetRandomObjective(Mind.Mind mind);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Mobs;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
@@ -9,14 +8,14 @@ namespace Content.Server.Objectives
|
||||
public class Objective : IEquatable<Objective>
|
||||
{
|
||||
[ViewVariables]
|
||||
public readonly Mind Mind;
|
||||
public readonly Mind.Mind Mind;
|
||||
[ViewVariables]
|
||||
public readonly ObjectivePrototype Prototype;
|
||||
private readonly List<IObjectiveCondition> _conditions = new();
|
||||
[ViewVariables]
|
||||
public IReadOnlyList<IObjectiveCondition> Conditions => _conditions;
|
||||
|
||||
public Objective(ObjectivePrototype prototype, Mind mind)
|
||||
public Objective(ObjectivePrototype prototype, Mind.Mind mind)
|
||||
{
|
||||
Prototype = prototype;
|
||||
Mind = mind;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#nullable enable
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.Mobs;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
@@ -39,7 +38,7 @@ namespace Content.Server.Objectives
|
||||
[DataField("difficultyOverride")]
|
||||
private float? _difficultyOverride = null;
|
||||
|
||||
public bool CanBeAssigned(Mind mind)
|
||||
public bool CanBeAssigned(Mind.Mind mind)
|
||||
{
|
||||
foreach (var requirement in _requirements)
|
||||
{
|
||||
@@ -57,7 +56,7 @@ namespace Content.Server.Objectives
|
||||
return true;
|
||||
}
|
||||
|
||||
public Objective GetObjective(Mind mind)
|
||||
public Objective GetObjective(Mind.Mind mind)
|
||||
{
|
||||
return new(this, mind);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#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;
|
||||
@@ -14,12 +13,12 @@ namespace Content.Server.Objectives
|
||||
[Dependency] private IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private IRobustRandom _random = default!;
|
||||
|
||||
public IEnumerable<ObjectivePrototype> GetAllPossibleObjectives(Mind mind)
|
||||
public IEnumerable<ObjectivePrototype> GetAllPossibleObjectives(Mind.Mind mind)
|
||||
{
|
||||
return _prototypeManager.EnumeratePrototypes<ObjectivePrototype>().Where(objectivePrototype => objectivePrototype.CanBeAssigned(mind));
|
||||
}
|
||||
|
||||
public ObjectivePrototype? GetRandomObjective(Mind mind)
|
||||
public ObjectivePrototype? GetRandomObjective(Mind.Mind mind)
|
||||
{
|
||||
var objectives = GetAllPossibleObjectives(mind).ToList();
|
||||
_random.Shuffle(objectives);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Mobs;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
@@ -11,7 +10,7 @@ namespace Content.Server.Objectives.Requirements
|
||||
[DataField("conditions")]
|
||||
private readonly List<string> _incompatibleConditions = new();
|
||||
|
||||
public bool CanBeAssigned(Mind mind)
|
||||
public bool CanBeAssigned(Mind.Mind mind)
|
||||
{
|
||||
foreach (var objective in mind.AllObjectives)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Mobs;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
@@ -11,7 +10,7 @@ namespace Content.Server.Objectives.Requirements
|
||||
[DataField("objectives")]
|
||||
private readonly List<string> _incompatibleObjectives = new();
|
||||
|
||||
public bool CanBeAssigned(Mind mind)
|
||||
public bool CanBeAssigned(Mind.Mind mind)
|
||||
{
|
||||
foreach (var objective in mind.AllObjectives)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Content.Server.Mobs;
|
||||
using Content.Server.Mobs.Roles.Traitor;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using Content.Server.Objectives.Interfaces;
|
||||
using Content.Server.Traitor;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
@@ -10,7 +9,7 @@ namespace Content.Server.Objectives.Requirements
|
||||
[DataDefinition]
|
||||
public class TraitorRequirement : IObjectiveRequirement
|
||||
{
|
||||
public bool CanBeAssigned(Mind mind)
|
||||
public bool CanBeAssigned(Mind.Mind mind)
|
||||
{
|
||||
return mind.HasRole<TraitorRole>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user