Basis for the job system (#434)
* Add basic yaml Jobs file * Add Job Prototype * Rename Jobs to Job * Remove BaseJob * Add the Job class child of Role * Add code for spawning as an assistant. Not actually working, the job prototype can't be found. * Fix role instead of job left in yaml * Add starting gear support for job and the starting gear for assistant as an exemple * Link job with starting gear in yaml * Better naming and some error handling * Tweak error handling
This commit is contained in:
committed by
Pieter-Jan Briers
parent
480d3b26c4
commit
447db2e458
@@ -1,13 +1,17 @@
|
||||
using System.Text;
|
||||
using Content.Server.Mobs.Roles;
|
||||
using Content.Server.Players;
|
||||
using Content.Shared.Jobs;
|
||||
using Robust.Server.Interfaces.Console;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
using Robust.Shared.Interfaces.Reflection;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Mobs
|
||||
{
|
||||
|
||||
public class MindInfoCommand : IClientCommand
|
||||
{
|
||||
public string Command => "mindinfo";
|
||||
@@ -47,6 +51,10 @@ namespace Content.Server.Mobs
|
||||
|
||||
public class AddRoleCommand : IClientCommand
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private IPrototypeManager _prototypeManager;
|
||||
#pragma warning restore 649
|
||||
|
||||
public string Command => "addrole";
|
||||
|
||||
public string Description => "Adds a role to a player's mind.";
|
||||
@@ -65,9 +73,8 @@ namespace Content.Server.Mobs
|
||||
if (mgr.TryGetPlayerData(new NetSessionId(args[0]), out var data))
|
||||
{
|
||||
var mind = data.ContentData().Mind;
|
||||
var refl = IoCManager.Resolve<IReflectionManager>();
|
||||
var type = refl.LooseGetType(args[1]);
|
||||
mind.AddRole(type);
|
||||
var role = new Job(mind, _prototypeManager.Index<JobPrototype>(args[1]));
|
||||
mind.AddRole(role);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -78,6 +85,11 @@ namespace Content.Server.Mobs
|
||||
|
||||
public class RemoveRoleCommand : IClientCommand
|
||||
{
|
||||
|
||||
#pragma warning disable 649
|
||||
[Dependency] private IPrototypeManager _prototypeManager;
|
||||
#pragma warning restore 649
|
||||
|
||||
public string Command => "rmrole";
|
||||
|
||||
public string Description => "Removes a role from a player's mind.";
|
||||
@@ -96,9 +108,8 @@ namespace Content.Server.Mobs
|
||||
if (mgr.TryGetPlayerData(new NetSessionId(args[0]), out var data))
|
||||
{
|
||||
var mind = data.ContentData().Mind;
|
||||
var refl = IoCManager.Resolve<IReflectionManager>();
|
||||
var type = refl.LooseGetType(args[1]);
|
||||
mind.RemoveRole(type);
|
||||
var role = new Job(mind, _prototypeManager.Index<JobPrototype>(args[1]));
|
||||
mind.RemoveRole(role);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Content.Server.Mobs
|
||||
/// </remarks>
|
||||
public sealed class Mind
|
||||
{
|
||||
private readonly Dictionary<Type, Role> _roles = new Dictionary<Type, Role>();
|
||||
private readonly ISet<Role> _roles = new HashSet<Role>();
|
||||
|
||||
/// <summary>
|
||||
/// Creates the new mind attached to a specific player session.
|
||||
@@ -66,7 +66,7 @@ namespace Content.Server.Mobs
|
||||
/// An enumerable over all the roles this mind has.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public IEnumerable<Role> AllRoles => _roles.Values;
|
||||
public IEnumerable<Role> AllRoles => _roles;
|
||||
|
||||
/// <summary>
|
||||
/// The session of the player owning this mind.
|
||||
@@ -87,19 +87,6 @@ namespace Content.Server.Mobs
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gives this mind a new role.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the role to give.</typeparam>
|
||||
/// <returns>The instance of the role.</returns>
|
||||
/// <exception cref="ArgumentException">
|
||||
/// Thrown if we already have a role with this type.
|
||||
/// </exception>
|
||||
public T AddRole<T>() where T : Role
|
||||
{
|
||||
return (T)AddRole(typeof(T));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gives this mind a new role.
|
||||
/// </summary>
|
||||
@@ -108,31 +95,18 @@ namespace Content.Server.Mobs
|
||||
/// <exception cref="ArgumentException">
|
||||
/// Thrown if we already have a role with this type.
|
||||
/// </exception>
|
||||
public Role AddRole(Type t)
|
||||
public Role AddRole(Role role)
|
||||
{
|
||||
if (_roles.ContainsKey(t))
|
||||
if (_roles.Contains(role))
|
||||
{
|
||||
throw new ArgumentException($"We already have this role: {t}");
|
||||
throw new ArgumentException($"We already have this role: {role}");
|
||||
}
|
||||
|
||||
var role = (Role)Activator.CreateInstance(t, this);
|
||||
_roles[t] = role;
|
||||
_roles.Add(role);
|
||||
role.Greet();
|
||||
return role;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a role from this mind.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the role to remove.</typeparam>
|
||||
/// <exception cref="ArgumentException">
|
||||
/// Thrown if we do not have this role.
|
||||
/// </exception>
|
||||
public void RemoveRole<T>() where T : Role
|
||||
{
|
||||
RemoveRole(typeof(T));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a role from this mind.
|
||||
/// </summary>
|
||||
@@ -140,42 +114,16 @@ namespace Content.Server.Mobs
|
||||
/// <exception cref="ArgumentException">
|
||||
/// Thrown if we do not have this role.
|
||||
/// </exception>
|
||||
public void RemoveRole(Type t)
|
||||
public void RemoveRole(Role role)
|
||||
{
|
||||
if (!_roles.ContainsKey(t))
|
||||
if (!_roles.Contains(role))
|
||||
{
|
||||
throw new ArgumentException($"We do not have this role: {t}");
|
||||
throw new ArgumentException($"We do not have this role: {role}");
|
||||
}
|
||||
|
||||
// This can definitely get more complex removal hooks later,
|
||||
// when we need it.
|
||||
_roles.Remove(t);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a role of a certain type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the role to get.</typeparam>
|
||||
/// <returns>The role's instance.</returns>
|
||||
/// <exception cref="KeyNotFoundException">
|
||||
/// Thrown if we do not have a role of this type.
|
||||
/// </exception>
|
||||
public T GetRole<T>() where T : Role
|
||||
{
|
||||
return (T)_roles[typeof(T)];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a role of a certain type.
|
||||
/// </summary>
|
||||
/// <param name="t">The type of the role to get.</param>
|
||||
/// <returns>The role's instance.</returns>
|
||||
/// <exception cref="KeyNotFoundException">
|
||||
/// Thrown if we do not have a role of this type.
|
||||
/// </exception>
|
||||
public Role GetRole(Type t)
|
||||
{
|
||||
return _roles[t];
|
||||
_roles.Remove(role);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
35
Content.Server/Mobs/Roles/Job.cs
Normal file
35
Content.Server/Mobs/Roles/Job.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Interfaces.Chat;
|
||||
using Content.Shared.Jobs;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Mobs.Roles
|
||||
{
|
||||
public class Job : Role
|
||||
{
|
||||
private readonly JobPrototype _jobPrototype;
|
||||
|
||||
public override string Name { get; }
|
||||
|
||||
public String StartingGear => _jobPrototype.StartingGear;
|
||||
|
||||
public Job(Mind mind, JobPrototype jobPrototype) : base(mind)
|
||||
{
|
||||
_jobPrototype = jobPrototype;
|
||||
Name = jobPrototype.Name;
|
||||
}
|
||||
|
||||
public override void Greet()
|
||||
{
|
||||
base.Greet();
|
||||
|
||||
var chat = IoCManager.Resolve<IChatManager>();
|
||||
chat.DispatchServerMessage(
|
||||
Mind.Session,
|
||||
String.Format("You're a new {0}. Do your best!", Name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user