Antag Datums. Oh also minds. (#100)
AKA: Minds and there's a stupid basic roles framework.
This commit is contained in:
committed by
Acruid
parent
e8c4dc9a34
commit
cd4442b81e
@@ -78,6 +78,7 @@
|
|||||||
<Compile Include="GameObjects\Components\Items\Storage\StoreableComponent.cs" />
|
<Compile Include="GameObjects\Components\Items\Storage\StoreableComponent.cs" />
|
||||||
<Compile Include="GameObjects\Components\Items\Storage\ServerStorageComponent.cs" />
|
<Compile Include="GameObjects\Components\Items\Storage\ServerStorageComponent.cs" />
|
||||||
<Compile Include="GameObjects\Components\Items\Storage\ItemComponent.cs" />
|
<Compile Include="GameObjects\Components\Items\Storage\ItemComponent.cs" />
|
||||||
|
<Compile Include="GameObjects\Components\Mobs\MindComponent.cs" />
|
||||||
<Compile Include="GameObjects\Components\Power\PowerStorageComponent.cs" />
|
<Compile Include="GameObjects\Components\Power\PowerStorageComponent.cs" />
|
||||||
<Compile Include="GameObjects\Components\Power\PowerGeneratorComponent.cs" />
|
<Compile Include="GameObjects\Components\Power\PowerGeneratorComponent.cs" />
|
||||||
<Compile Include="GameObjects\Components\Power\PowerDevice.cs" />
|
<Compile Include="GameObjects\Components\Power\PowerDevice.cs" />
|
||||||
@@ -108,7 +109,12 @@
|
|||||||
<Compile Include="GameObjects\Components\Damage\ResistanceSet.cs" />
|
<Compile Include="GameObjects\Components\Damage\ResistanceSet.cs" />
|
||||||
<Compile Include="GameObjects\Components\Temperature\TemperatureComponent.cs" />
|
<Compile Include="GameObjects\Components\Temperature\TemperatureComponent.cs" />
|
||||||
<Compile Include="Interfaces\GameObjects\IOnDamageBehavior.cs" />
|
<Compile Include="Interfaces\GameObjects\IOnDamageBehavior.cs" />
|
||||||
|
<Compile Include="Mobs\Commands.cs" />
|
||||||
|
<Compile Include="Mobs\Mind.cs" />
|
||||||
|
<Compile Include="Mobs\Role.cs" />
|
||||||
|
<Compile Include="Mobs\Roles\Traitor.cs" />
|
||||||
<Compile Include="Placement\SpawnHelpers.cs" />
|
<Compile Include="Placement\SpawnHelpers.cs" />
|
||||||
|
<Compile Include="Players\PlayerData.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Interfaces\GameObjects\Components\Temperature\ITemperatureComponent.cs" />
|
<Compile Include="Interfaces\GameObjects\Components\Temperature\ITemperatureComponent.cs" />
|
||||||
<Compile Include="Interfaces\GameObjects\Components\Damage\IDamageableComponent.cs" />
|
<Compile Include="Interfaces\GameObjects\Components\Damage\IDamageableComponent.cs" />
|
||||||
@@ -153,4 +159,5 @@
|
|||||||
<Compile Include="GameObjects\Components\Construction\ConstructorComponent.cs" />
|
<Compile Include="GameObjects\Components\Construction\ConstructorComponent.cs" />
|
||||||
<Compile Include="GameObjects\Components\Construction\ConstructionComponent.cs" />
|
<Compile Include="GameObjects\Components\Construction\ConstructionComponent.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup />
|
||||||
</Project>
|
</Project>
|
||||||
@@ -28,11 +28,16 @@ using Content.Server.GameObjects.Components.Weapon.Melee;
|
|||||||
using Content.Server.GameObjects.Components.Materials;
|
using Content.Server.GameObjects.Components.Materials;
|
||||||
using Content.Server.GameObjects.Components.Stack;
|
using Content.Server.GameObjects.Components.Stack;
|
||||||
using Content.Server.GameObjects.Components.Construction;
|
using Content.Server.GameObjects.Components.Construction;
|
||||||
|
using Content.Server.Players;
|
||||||
|
using Content.Server.Mobs;
|
||||||
|
using Content.Server.GameObjects.Components.Mobs;
|
||||||
|
|
||||||
namespace Content.Server
|
namespace Content.Server
|
||||||
{
|
{
|
||||||
public class EntryPoint : GameServer
|
public class EntryPoint : GameServer
|
||||||
{
|
{
|
||||||
|
const string PlayerPrototypeName = "HumanMob_Content";
|
||||||
|
|
||||||
private IBaseServer _server;
|
private IBaseServer _server;
|
||||||
private IPlayerManager _players;
|
private IPlayerManager _players;
|
||||||
private IEntityManager entityManager;
|
private IEntityManager entityManager;
|
||||||
@@ -40,6 +45,8 @@ namespace Content.Server
|
|||||||
|
|
||||||
private bool _countdownStarted;
|
private bool _countdownStarted;
|
||||||
|
|
||||||
|
private GridLocalCoordinates SpawnPoint;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Init()
|
public override void Init()
|
||||||
{
|
{
|
||||||
@@ -52,7 +59,6 @@ namespace Content.Server
|
|||||||
|
|
||||||
_server.RunLevelChanged += HandleRunLevelChanged;
|
_server.RunLevelChanged += HandleRunLevelChanged;
|
||||||
_players.PlayerStatusChanged += HandlePlayerStatusChanged;
|
_players.PlayerStatusChanged += HandlePlayerStatusChanged;
|
||||||
_players.PlayerPrototypeName = "HumanMob_Content";
|
|
||||||
|
|
||||||
var factory = IoCManager.Resolve<IComponentFactory>();
|
var factory = IoCManager.Resolve<IComponentFactory>();
|
||||||
|
|
||||||
@@ -106,6 +112,8 @@ namespace Content.Server
|
|||||||
factory.Register<ConstructionComponent>();
|
factory.Register<ConstructionComponent>();
|
||||||
factory.Register<ConstructorComponent>();
|
factory.Register<ConstructorComponent>();
|
||||||
factory.RegisterIgnore("ConstructionGhost");
|
factory.RegisterIgnore("ConstructionGhost");
|
||||||
|
|
||||||
|
factory.Register<MindComponent>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -132,7 +140,7 @@ namespace Content.Server
|
|||||||
var newMap = mapMan.CreateMap();
|
var newMap = mapMan.CreateMap();
|
||||||
var grid = mapLoader.LoadBlueprint(newMap, "Maps/stationstation.yml");
|
var grid = mapLoader.LoadBlueprint(newMap, "Maps/stationstation.yml");
|
||||||
|
|
||||||
_players.FallbackSpawnPoint = new GridLocalCoordinates(Vector2.Zero, grid);
|
SpawnPoint = new GridLocalCoordinates(Vector2.Zero, grid);
|
||||||
|
|
||||||
var startTime = timing.RealTime;
|
var startTime = timing.RealTime;
|
||||||
var timeSpan = timing.RealTime - startTime;
|
var timeSpan = timing.RealTime - startTime;
|
||||||
@@ -152,10 +160,16 @@ namespace Content.Server
|
|||||||
|
|
||||||
private void HandlePlayerStatusChanged(object sender, SessionStatusEventArgs args)
|
private void HandlePlayerStatusChanged(object sender, SessionStatusEventArgs args)
|
||||||
{
|
{
|
||||||
|
var session = args.Session;
|
||||||
|
|
||||||
switch (args.NewStatus)
|
switch (args.NewStatus)
|
||||||
{
|
{
|
||||||
case SessionStatus.Connected:
|
case SessionStatus.Connected:
|
||||||
{
|
{
|
||||||
|
if (session.Data.ContentDataUncast == null)
|
||||||
|
{
|
||||||
|
session.Data.ContentDataUncast = new PlayerData(session.SessionId);
|
||||||
|
}
|
||||||
// timer time must be > tick length
|
// timer time must be > tick length
|
||||||
Timer.Spawn(250, args.Session.JoinLobby);
|
Timer.Spawn(250, args.Session.JoinLobby);
|
||||||
|
|
||||||
@@ -183,15 +197,22 @@ namespace Content.Server
|
|||||||
case SessionStatus.InGame:
|
case SessionStatus.InGame:
|
||||||
{
|
{
|
||||||
//TODO: Check for existing mob and re-attach
|
//TODO: Check for existing mob and re-attach
|
||||||
var session = args.Session;
|
var data = session.ContentData();
|
||||||
if (session.Data.AttachedEntityUid.HasValue
|
if (data.Mind == null)
|
||||||
&& entityManager.TryGetEntity(session.Data.AttachedEntityUid.Value, out var entity))
|
|
||||||
{
|
{
|
||||||
session.AttachToEntity(entity);
|
// No mind yet (new session), make a new one.
|
||||||
|
data.Mind = new Mind(session.SessionId);
|
||||||
|
var mob = SpawnPlayerMob();
|
||||||
|
data.Mind.TransferTo(mob);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_players.SpawnPlayerMob(args.Session);
|
if (data.Mind.CurrentMob == null)
|
||||||
|
{
|
||||||
|
var mob = SpawnPlayerMob();
|
||||||
|
data.Mind.TransferTo(mob);
|
||||||
|
}
|
||||||
|
session.AttachToEntity(data.Mind.CurrentEntity);
|
||||||
}
|
}
|
||||||
chatManager.DispatchMessage(ChatChannel.Server, "Gamemode: Player joined Game!", args.Session.SessionId);
|
chatManager.DispatchMessage(ChatChannel.Server, "Gamemode: Player joined Game!", args.Session.SessionId);
|
||||||
}
|
}
|
||||||
@@ -204,5 +225,10 @@ namespace Content.Server
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IEntity SpawnPlayerMob()
|
||||||
|
{
|
||||||
|
return entityManager.ForceSpawnEntityAt(PlayerPrototypeName, SpawnPoint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
63
Content.Server/GameObjects/Components/Mobs/MindComponent.cs
Normal file
63
Content.Server/GameObjects/Components/Mobs/MindComponent.cs
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Content.Server.Mobs;
|
||||||
|
using SS14.Server.GameObjects;
|
||||||
|
using SS14.Shared.GameObjects;
|
||||||
|
using SS14.Shared.Interfaces.GameObjects;
|
||||||
|
using SS14.Shared.Interfaces.Network;
|
||||||
|
using SS14.Shared.Log;
|
||||||
|
|
||||||
|
namespace Content.Server.GameObjects.Components.Mobs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Stores a <see cref="Server.Mobs.Mind"/> on a mob.
|
||||||
|
/// </summary>
|
||||||
|
public class MindComponent : Component
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override string Name => "Mind";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The mind controlling this mob. Can be null.
|
||||||
|
/// </summary>
|
||||||
|
public Mind Mind { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// True if we have a mind, false otherwise.
|
||||||
|
/// </summary>
|
||||||
|
public bool HasMind => Mind != null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Don't call this unless you know what the hell you're doing.
|
||||||
|
/// Use <see cref="Mind.TransferTo(IEntity)"/> instead.
|
||||||
|
/// If that doesn't cover it, make something to cover it.
|
||||||
|
/// </summary>
|
||||||
|
public void InternalEjectMind()
|
||||||
|
{
|
||||||
|
Mind = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Don't call this unless you know what the hell you're doing.
|
||||||
|
/// Use <see cref="Mind.TransferTo(IEntity)"/> instead.
|
||||||
|
/// If that doesn't cover it, make something to cover it.
|
||||||
|
/// </summary>
|
||||||
|
public void InternalAssignMind(Mind value)
|
||||||
|
{
|
||||||
|
Mind = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnRemove()
|
||||||
|
{
|
||||||
|
base.OnRemove();
|
||||||
|
|
||||||
|
if (HasMind)
|
||||||
|
{
|
||||||
|
Mind.TransferTo(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
113
Content.Server/Mobs/Commands.cs
Normal file
113
Content.Server/Mobs/Commands.cs
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Content.Server.Players;
|
||||||
|
using SS14.Server.Interfaces.Console;
|
||||||
|
using SS14.Server.Interfaces.Player;
|
||||||
|
using SS14.Shared.Interfaces.Reflection;
|
||||||
|
using SS14.Shared.IoC;
|
||||||
|
using SS14.Shared.Network;
|
||||||
|
|
||||||
|
namespace Content.Server.Mobs
|
||||||
|
{
|
||||||
|
public class MindInfoCommand : IClientCommand
|
||||||
|
{
|
||||||
|
public string Command => "mindinfo";
|
||||||
|
|
||||||
|
public string Description => "Lists info for the mind of a specific player.";
|
||||||
|
|
||||||
|
public string Help => "mindinfo <session ID>";
|
||||||
|
|
||||||
|
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
|
||||||
|
{
|
||||||
|
if (args.Length != 1)
|
||||||
|
{
|
||||||
|
shell.SendText(player, "Expected exactly 1 argument.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var mgr = IoCManager.Resolve<IPlayerManager>();
|
||||||
|
if (mgr.TryGetPlayerData(new NetSessionId(args[0]), out var data))
|
||||||
|
{
|
||||||
|
var mind = data.ContentData().Mind;
|
||||||
|
|
||||||
|
var builder = new StringBuilder();
|
||||||
|
builder.AppendFormat("player: {0}, mob: {1}\nroles: ", mind.SessionId, mind.CurrentMob?.Owner?.Uid);
|
||||||
|
foreach (var role in mind.AllRoles)
|
||||||
|
{
|
||||||
|
builder.AppendFormat("{0} ", role.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
shell.SendText(player, builder.ToString());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shell.SendText(player, "Can't find that mind");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AddRoleCommand : IClientCommand
|
||||||
|
{
|
||||||
|
public string Command => "addrole";
|
||||||
|
|
||||||
|
public string Description => "Adds a role to a player's mind.";
|
||||||
|
|
||||||
|
public string Help => "addrole <session ID> <Role Type>\nThat role type is the actual C# type name.";
|
||||||
|
|
||||||
|
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.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);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shell.SendText(player, "Can't find that mind");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class RemoveRoleCommand : IClientCommand
|
||||||
|
{
|
||||||
|
public string Command => "rmrole";
|
||||||
|
|
||||||
|
public string Description => "Removes a role from a player's mind.";
|
||||||
|
|
||||||
|
public string Help => "rmrole <session ID> <Role Type>\nThat role type is the actual C# type name.";
|
||||||
|
|
||||||
|
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.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);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shell.SendText(player, "Can't find that mind");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
199
Content.Server/Mobs/Mind.cs
Normal file
199
Content.Server/Mobs/Mind.cs
Normal file
@@ -0,0 +1,199 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Content.Server.GameObjects.Components.Mobs;
|
||||||
|
using SS14.Server.Interfaces.Player;
|
||||||
|
using SS14.Shared.Interfaces.GameObjects;
|
||||||
|
using SS14.Shared.IoC;
|
||||||
|
using SS14.Shared.Network;
|
||||||
|
|
||||||
|
namespace Content.Server.Mobs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A mind represents the IC "mind" of a player. Stores roles currently.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Think of it like this: if a player is supposed to have their memories,
|
||||||
|
/// their mind follows along.
|
||||||
|
///
|
||||||
|
/// Things such as respawning do not follow, because you're a new character.
|
||||||
|
/// Getting borged, cloned, turned into a catbeast, etc... will keep it following you.
|
||||||
|
/// </remarks>
|
||||||
|
public sealed class Mind
|
||||||
|
{
|
||||||
|
private readonly Dictionary<Type, Role> _roles = new Dictionary<Type, Role>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates the new mind attached to a specific player session.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sessionId">The session ID of the owning player.</param>
|
||||||
|
public Mind(NetSessionId sessionId)
|
||||||
|
{
|
||||||
|
SessionId = sessionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: This session should be able to be changed, probably.
|
||||||
|
/// <summary>
|
||||||
|
/// The session ID of the player owning this mind.
|
||||||
|
/// </summary>
|
||||||
|
public NetSessionId SessionId { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The component currently owned by this mind.
|
||||||
|
/// Can be null.
|
||||||
|
/// </summary>
|
||||||
|
public MindComponent CurrentMob { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The entity currently owned by this mind.
|
||||||
|
/// Can be null.
|
||||||
|
/// </summary>
|
||||||
|
public IEntity CurrentEntity => CurrentMob?.Owner;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An enumerable over all the roles this mind has.
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<Role> AllRoles => _roles.Values;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The session of the player owning this mind.
|
||||||
|
/// Can be null, in which case the player is currently not logged in.
|
||||||
|
/// </summary>
|
||||||
|
public IPlayerSession Session
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var playerMgr = IoCManager.Resolve<IPlayerManager>();
|
||||||
|
playerMgr.TryGetSessionById(SessionId, out var ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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>
|
||||||
|
/// <param name="t">The type of the role to give.</param>
|
||||||
|
/// <returns>The instance of the role.</returns>
|
||||||
|
/// <exception cref="ArgumentException">
|
||||||
|
/// Thrown if we already have a role with this type.
|
||||||
|
/// </exception>
|
||||||
|
public Role AddRole(Type t)
|
||||||
|
{
|
||||||
|
if (_roles.ContainsKey(t))
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"We already have this role: {t}");
|
||||||
|
}
|
||||||
|
|
||||||
|
var role = (Role)Activator.CreateInstance(t, this);
|
||||||
|
_roles[t] = 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>
|
||||||
|
/// <param name="t">The type of the role to remove.</param>
|
||||||
|
/// <exception cref="ArgumentException">
|
||||||
|
/// Thrown if we do not have this role.
|
||||||
|
/// </exception>
|
||||||
|
public void RemoveRole(Type t)
|
||||||
|
{
|
||||||
|
if (!_roles.ContainsKey(t))
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"We do not have this role: {t}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Transfer this mind's control over to a new entity.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">
|
||||||
|
/// The entity to control.
|
||||||
|
/// Can be null, in which case it will simply detach the mind from any entity.
|
||||||
|
/// </param>
|
||||||
|
/// <exception cref="ArgumentException">
|
||||||
|
/// Thrown if <paramref name="entity"/> is already owned by another mind.
|
||||||
|
/// </exception>
|
||||||
|
public void TransferTo(IEntity entity)
|
||||||
|
{
|
||||||
|
MindComponent component = null;
|
||||||
|
if (entity != null)
|
||||||
|
{
|
||||||
|
if (!entity.TryGetComponent(out component))
|
||||||
|
{
|
||||||
|
component = entity.AddComponent<MindComponent>();
|
||||||
|
}
|
||||||
|
else if (component.HasMind)
|
||||||
|
{
|
||||||
|
// TODO: Kick them out, maybe?
|
||||||
|
throw new ArgumentException("That entity already has a mind.", nameof(entity));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentMob?.InternalEjectMind();
|
||||||
|
CurrentMob = component;
|
||||||
|
CurrentMob?.InternalAssignMind(this);
|
||||||
|
|
||||||
|
// Player is CURRENTLY connected.
|
||||||
|
if (Session != null && CurrentMob != null)
|
||||||
|
{
|
||||||
|
Session.AttachToEntity(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
36
Content.Server/Mobs/Role.cs
Normal file
36
Content.Server/Mobs/Role.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
// Hey look,
|
||||||
|
// Antag Datums.
|
||||||
|
|
||||||
|
namespace Content.Server.Mobs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The Role is a basic building block for,
|
||||||
|
/// well, IC roles.
|
||||||
|
/// This can be anything and is not necessarily limited to antagonists.
|
||||||
|
/// </summary>
|
||||||
|
public abstract class Role
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The mind owning this role instance.
|
||||||
|
/// </summary>
|
||||||
|
public Mind Mind { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A friendly name for this role type.
|
||||||
|
/// </summary>
|
||||||
|
public abstract string Name { get; }
|
||||||
|
|
||||||
|
protected Role(Mind mind)
|
||||||
|
{
|
||||||
|
Mind = mind;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when a mind (player) first gets this role, to greet them.
|
||||||
|
/// </summary>
|
||||||
|
public virtual void Greet()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
24
Content.Server/Mobs/Roles/Traitor.cs
Normal file
24
Content.Server/Mobs/Roles/Traitor.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
using SS14.Server.Interfaces.Chat;
|
||||||
|
using SS14.Shared.Console;
|
||||||
|
using SS14.Shared.IoC;
|
||||||
|
|
||||||
|
namespace Content.Server.Mobs.Roles
|
||||||
|
{
|
||||||
|
public sealed class Traitor : Role
|
||||||
|
{
|
||||||
|
public Traitor(Mind mind) : base(mind)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Name => "Traitor";
|
||||||
|
|
||||||
|
public override void Greet()
|
||||||
|
{
|
||||||
|
base.Greet();
|
||||||
|
|
||||||
|
var chat = IoCManager.Resolve<IChatManager>();
|
||||||
|
chat.DispatchMessage(Mind.Session.ConnectedClient, ChatChannel.Server,
|
||||||
|
"You're a traitor. Go fuck something up. Or something. I don't care to be honest.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
47
Content.Server/Players/PlayerData.cs
Normal file
47
Content.Server/Players/PlayerData.cs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
using Content.Server.Mobs;
|
||||||
|
using SS14.Server.Interfaces.Player;
|
||||||
|
using SS14.Shared.Network;
|
||||||
|
|
||||||
|
namespace Content.Server.Players
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Content side for all data that tracks a player session.
|
||||||
|
/// Use <see cref="PlayerDataExt.ContentData(IPlayerData)"/> to retrieve this from an <see cref="IPlayerData"/>.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class PlayerData
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The session ID of the player owning this data.
|
||||||
|
/// </summary>
|
||||||
|
public NetSessionId SessionId { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The currently occupied mind of the player owning this data.
|
||||||
|
/// </summary>
|
||||||
|
public Mind Mind { get; set; }
|
||||||
|
|
||||||
|
public PlayerData(NetSessionId sessionId)
|
||||||
|
{
|
||||||
|
SessionId = sessionId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class PlayerDataExt
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the correctly cast instance of content player data from an engine player data storage.
|
||||||
|
/// </summary>
|
||||||
|
public static PlayerData ContentData(this IPlayerData data)
|
||||||
|
{
|
||||||
|
return (PlayerData)data.ContentDataUncast;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the correctly cast instance of content player data from an engine player data storage.
|
||||||
|
/// </summary>
|
||||||
|
public static PlayerData ContentData(this IPlayerSession session)
|
||||||
|
{
|
||||||
|
return session.Data.ContentData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
2
engine
2
engine
Submodule engine updated: d8a5a617fe...22fdca62bb
Reference in New Issue
Block a user