Ghost command, some other stuff

This commit is contained in:
zumorica
2020-03-03 20:37:26 +01:00
parent 055f09d501
commit 7f19381bec
9 changed files with 119 additions and 7 deletions

View File

@@ -69,8 +69,7 @@ namespace Content.Client.Observer
if (!(curState is GhostComponentState state)) return;
_canReturnToBody = state.CanReturnToBody;
if (_gui == null) return;
_gui.ReturnToBody.Disabled = !_canReturnToBody;
_gui?.Update();
}
}
}

View File

@@ -1,3 +1,4 @@
using System.Data;
using Content.Client.Observer;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
@@ -21,6 +22,13 @@ namespace Content.Client.UserInterface
ReturnToBody.OnPressed += (args) => { owner.SendReturnToBodyMessage(); };
AddChild(ReturnToBody);
Update();
}
public void Update()
{
ReturnToBody.Disabled = !_owner.CanReturnToBody;
}
}
}

View File

@@ -4,6 +4,7 @@ using Content.Server.GameTicking;
using Content.Server.Interfaces.GameTicking;
using Content.Shared;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Map;
using Robust.Shared.Timing;
namespace Content.IntegrationTests
@@ -54,6 +55,10 @@ namespace Content.IntegrationTests
{
}
public GridCoordinates GetLateJoinSpawnPoint() => GridCoordinates.InvalidGrid;
public GridCoordinates GetJobSpawnPoint(string jobId) => GridCoordinates.InvalidGrid;
public GridCoordinates GetObserverSpawnPoint() => GridCoordinates.InvalidGrid;
public T AddGameRule<T>() where T : GameRule, new()
{
return new T();

View File

@@ -75,7 +75,13 @@ namespace Content.Server.GameObjects
{
if (damageType == DamageType.Total)
{
throw new ArgumentException("Cannot take damage for DamageType.Total");
foreach (DamageType e in Enum.GetValues(typeof(DamageType)))
{
if (e == damageType) continue;
TakeDamage(e, amount, source, sourceMob);
}
return;
}
InitializeDamageType(damageType);

View File

@@ -38,5 +38,6 @@ namespace Content.Server.GameObjects.Components.Markers
Unset = 0,
LateJoin,
Job,
Observer,
}
}

View File

@@ -273,7 +273,7 @@ namespace Content.Server.GameTicking
private IEntity _spawnPlayerMob(Job job, bool lateJoin = true)
{
GridCoordinates coordinates = lateJoin ? _getLateJoinSpawnPoint() : _getJobSpawnPoint(job.Prototype.ID);
GridCoordinates coordinates = lateJoin ? GetLateJoinSpawnPoint() : GetJobSpawnPoint(job.Prototype.ID);
var entity = _entityManager.SpawnEntity(PlayerPrototypeName, coordinates);
if (entity.TryGetComponent(out InventoryComponent inventory))
{
@@ -299,11 +299,11 @@ namespace Content.Server.GameTicking
private IEntity _spawnObserverMob()
{
GridCoordinates coordinates = _getLateJoinSpawnPoint();
var coordinates = GetObserverSpawnPoint();
return _entityManager.SpawnEntity(ObserverPrototypeName, coordinates);
}
private GridCoordinates _getLateJoinSpawnPoint()
public GridCoordinates GetLateJoinSpawnPoint()
{
var location = _spawnPoint;
@@ -319,7 +319,7 @@ namespace Content.Server.GameTicking
return location;
}
private GridCoordinates _getJobSpawnPoint(string jobId)
public GridCoordinates GetJobSpawnPoint(string jobId)
{
var location = _spawnPoint;
@@ -336,6 +336,23 @@ namespace Content.Server.GameTicking
return location;
}
public GridCoordinates GetObserverSpawnPoint()
{
var location = _spawnPoint;
var possiblePoints = new List<GridCoordinates>();
foreach (var entity in _entityManager.GetEntities(new TypeEntityQuery(typeof(SpawnPointComponent))))
{
var point = entity.GetComponent<SpawnPointComponent>();
if (point.SpawnType == SpawnPointType.Observer)
possiblePoints.Add(entity.Transform.GridPosition);
}
if (possiblePoints.Count != 0) location = _robustRandom.Pick(possiblePoints);
return location;
}
/// <summary>
/// Cleanup that has to run to clear up anything from the previous round.
/// Stuff like wiping the previous map clean.

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using Content.Server.GameTicking;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Map;
using Robust.Shared.Timing;
namespace Content.Server.Interfaces.GameTicking
@@ -27,6 +28,10 @@ namespace Content.Server.Interfaces.GameTicking
void MakeJoinGame(IPlayerSession player);
void ToggleReady(IPlayerSession player, bool ready);
GridCoordinates GetLateJoinSpawnPoint();
GridCoordinates GetJobSpawnPoint(string jobId);
GridCoordinates GetObserverSpawnPoint();
// GameRule system.
T AddGameRule<T>() where T : GameRule, new();
void RemoveGameRule(GameRule rule);

View File

@@ -0,0 +1,67 @@
using Content.Server.GameObjects;
using Content.Server.Interfaces.GameTicking;
using Content.Server.Players;
using Content.Shared.GameObjects;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
namespace Content.Server.Observer
{
public class Ghost : IClientCommand
{
public string Command => "ghost";
public string Description => "Give up on life and become a ghost.";
public string Help => "ghost";
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
{
if (player == null)
{
shell.SendText((IPlayerSession) null, "Nah");
return;
}
var mind = player.ContentData().Mind;
GridCoordinates position;
var canReturn = player.AttachedEntity != null;
if (mind.VisitingEntity != null)
{
mind.UnVisit();
}
position = player.AttachedEntity?.Transform.GridPosition ?? IoCManager.Resolve<IGameTicker>().GetObserverSpawnPoint();
if (canReturn && player.AttachedEntity.TryGetComponent(out SpeciesComponent species))
{
switch (species.CurrentDamageState)
{
case DeadState _:
canReturn = true;
break;
case CriticalState _:
canReturn = true;
if (!player.AttachedEntity.TryGetComponent(out DamageableComponent damageable)) break;
damageable.TakeDamage(DamageType.Total, 100); // TODO: Use airloss/oxyloss instead
break;
default:
canReturn = false;
break;
}
}
var entityManager = IoCManager.Resolve<IEntityManager>();
var ghost = entityManager.SpawnEntity("MobObserver", position);
var ghostComponent = ghost.GetComponent<GhostComponent>();
ghostComponent.CanReturnToBody = canReturn;
if(canReturn)
mind.Visit(ghost);
else
mind.TransferTo(ghost);
}
}
}

View File

@@ -11,6 +11,7 @@
- ooc
- observe
- toggleready
- ghost
- Index: 50
Name: Moderator
@@ -26,6 +27,7 @@
- showtime
- observe
- toggleready
- ghost
- kick
- listplayers
- loc
@@ -44,6 +46,7 @@
- aghost
- observe
- toggleready
- ghost
- spawn
- delete
- tp
@@ -84,6 +87,7 @@
- aghost
- observe
- toggleready
- ghost
- spawn
- delete
- tp