Files
tbd-station-14/Content.Server/Objectives/Commands.cs
Paul Ritter 6602c8c972 Objectives (#2459)
* 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>
2020-11-22 18:38:07 +11:00

140 lines
4.7 KiB
C#

#nullable enable
using System.Linq;
using Content.Server.Administration;
using Content.Server.Players;
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
namespace Content.Server.Objectives
{
[AdminCommand(AdminFlags.Admin)]
public class AddObjectiveCommand : IClientCommand
{
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, IPlayerSession? player, string[] args)
{
if (args.Length != 2)
{
shell.SendText(player, "Expected exactly 2 arguments.");
return;
}
var mgr = IoCManager.Resolve<IPlayerManager>();
if (!mgr.TryGetPlayerDataByUsername(args[0], out var data))
{
shell.SendText(player, "Can't find the playerdata.");
return;
}
var mind = data.ContentData()?.Mind;
if (mind == null)
{
shell.SendText(player, "Can't find the mind.");
return;
}
if (!IoCManager.Resolve<IPrototypeManager>()
.TryIndex<ObjectivePrototype>(args[1], out var objectivePrototype))
{
shell.SendText(player, $"Can't find matching ObjectivePrototype {objectivePrototype}");
return;
}
if (!mind.TryAddObjective(objectivePrototype))
{
shell.SendText(player, "Objective requirements dont allow that objective to be added.");
}
}
}
[AdminCommand(AdminFlags.Admin)]
public class ListObjectivesCommand : IClientCommand
{
public string Command => "lsobjectives";
public string Description => "Lists all objectives in a players mind.";
public string Help => "lsobjectives [<username>]";
public void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
{
IPlayerData? data;
if (args.Length == 0 && player != null)
{
data = player.Data;
}
else if (player == null || !IoCManager.Resolve<IPlayerManager>().TryGetPlayerDataByUsername(args[0], out data))
{
shell.SendText(player, "Can't find the playerdata.");
return;
}
var mind = data.ContentData()?.Mind;
if (mind == null)
{
shell.SendText(player, "Can't find the mind.");
return;
}
shell.SendText(player, $"Objectives for player {data.UserId}:");
var objectives = mind.AllObjectives.ToList();
if (objectives.Count == 0)
{
shell.SendText(player, "None.");
}
for (var i = 0; i < objectives.Count; i++)
{
shell.SendText(player, $"- [{i}] {objectives[i]}");
}
}
}
[AdminCommand(AdminFlags.Admin)]
public class RemoveObjectiveCommand : IClientCommand
{
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, IPlayerSession? player, string[] args)
{
if (args.Length != 2)
{
shell.SendText(player, "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.SendText(player, "Can't find the mind.");
return;
}
if (int.TryParse(args[1], out var i))
{
shell.SendText(player,
mind.TryRemoveObjective(i)
? "Objective successfully removed!"
: "Objective removing failed. Maybe the index is out of bounds? Check lsobjectives!");
}
else
{
shell.SendText(player, $"Invalid index {args[1]}!");
}
}
else
{
shell.SendText(player, "Can't find the playerdata.");
}
}
}
}