@@ -38,6 +38,8 @@ namespace Content.Client.Chat
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string DefaultChatFormat { get; set; }
|
public string DefaultChatFormat { get; set; }
|
||||||
|
|
||||||
|
public bool ReleaseFocusOnEnter { get; set; } = true;
|
||||||
|
|
||||||
protected override void Initialize()
|
protected override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
@@ -151,7 +153,11 @@ namespace Content.Client.Chat
|
|||||||
_inputIndex = -1;
|
_inputIndex = -1;
|
||||||
|
|
||||||
Input.Clear();
|
Input.Clear();
|
||||||
|
|
||||||
|
if (ReleaseFocusOnEnter)
|
||||||
|
{
|
||||||
Input.ReleaseKeyboardFocus();
|
Input.ReleaseKeyboardFocus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ using Robust.Shared.IoC;
|
|||||||
using Robust.Shared.Log;
|
using Robust.Shared.Log;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Content.Client.Utility;
|
||||||
using Content.Shared.GameObjects.Components.Mobs;
|
using Content.Shared.GameObjects.Components.Mobs;
|
||||||
using Robust.Client.Graphics.Overlays;
|
using Robust.Client.Graphics.Overlays;
|
||||||
|
|
||||||
@@ -67,7 +68,6 @@ namespace Content.Client.GameObjects
|
|||||||
{
|
{
|
||||||
base.OnAdd();
|
base.OnAdd();
|
||||||
|
|
||||||
IoCManager.InjectDependencies(this);
|
|
||||||
_window = new SpeciesWindow();
|
_window = new SpeciesWindow();
|
||||||
|
|
||||||
EffectsDictionary = new Dictionary<ScreenEffects, Overlay>()
|
EffectsDictionary = new Dictionary<ScreenEffects, Overlay>()
|
||||||
@@ -143,6 +143,8 @@ namespace Content.Client.GameObjects
|
|||||||
{
|
{
|
||||||
SizeFlagsHorizontal = SizeFlags.ShrinkCenter;
|
SizeFlagsHorizontal = SizeFlags.ShrinkCenter;
|
||||||
SizeFlagsVertical = SizeFlags.None;
|
SizeFlagsVertical = SizeFlags.None;
|
||||||
|
|
||||||
|
Texture = IoCManager.Resolve<IResourceCache>().GetTexture("/Textures/Mob/UI/Human/human0.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetIcon(HudStateChange changeMessage)
|
public void SetIcon(HudStateChange changeMessage)
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace Content.Client.UserInterface
|
|||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
var chatContainer = GetChild("Panel/VBoxContainer/HBoxContainer/LeftVBox");
|
var chatContainer = GetChild("Panel/VBoxContainer/HBoxContainer/LeftVBox");
|
||||||
Chat = new ChatBox();
|
Chat = new ChatBox {ReleaseFocusOnEnter = false};
|
||||||
chatContainer.AddChild(Chat);
|
chatContainer.AddChild(Chat);
|
||||||
Chat.SizeFlagsVertical = SizeFlags.FillExpand;
|
Chat.SizeFlagsVertical = SizeFlags.FillExpand;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,7 +141,10 @@
|
|||||||
<Compile Include="GameObjects\EntitySystems\WelderSystem.cs" />
|
<Compile Include="GameObjects\EntitySystems\WelderSystem.cs" />
|
||||||
<Compile Include="GameObjects\EntitySystems\TemperatureSystem.cs" />
|
<Compile Include="GameObjects\EntitySystems\TemperatureSystem.cs" />
|
||||||
<Compile Include="GameTicking\GamePreset.cs" />
|
<Compile Include="GameTicking\GamePreset.cs" />
|
||||||
|
<Compile Include="GameTicking\GamePresets\PresetDeathMatch.cs" />
|
||||||
<Compile Include="GameTicking\GamePresets\PresetTraitor.cs" />
|
<Compile Include="GameTicking\GamePresets\PresetTraitor.cs" />
|
||||||
|
<Compile Include="GameTicking\GameRule.cs" />
|
||||||
|
<Compile Include="GameTicking\GameRules\RuleDeathMatch.cs" />
|
||||||
<Compile Include="GameTicking\GameTicker.cs" />
|
<Compile Include="GameTicking\GameTicker.cs" />
|
||||||
<Compile Include="Interfaces\Chat\IChatCommand.cs" />
|
<Compile Include="Interfaces\Chat\IChatCommand.cs" />
|
||||||
<Compile Include="Interfaces\Chat\IChatManager.cs" />
|
<Compile Include="Interfaces\Chat\IChatManager.cs" />
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ namespace Content.Server.GameObjects
|
|||||||
void EnterState(IEntity entity);
|
void EnterState(IEntity entity);
|
||||||
|
|
||||||
void ExitState(IEntity entity);
|
void ExitState(IEntity entity);
|
||||||
|
|
||||||
|
bool IsConscious { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -28,6 +30,8 @@ namespace Content.Server.GameObjects
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsConscious => true;
|
||||||
|
|
||||||
bool IActionBlocker.CanInteract()
|
bool IActionBlocker.CanInteract()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
@@ -57,6 +61,8 @@ namespace Content.Server.GameObjects
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsConscious => false;
|
||||||
|
|
||||||
bool IActionBlocker.CanInteract()
|
bool IActionBlocker.CanInteract()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -96,6 +102,8 @@ namespace Content.Server.GameObjects
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsConscious => false;
|
||||||
|
|
||||||
bool IActionBlocker.CanInteract()
|
bool IActionBlocker.CanInteract()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -112,6 +112,24 @@ namespace Content.Server.GameObjects
|
|||||||
CurrentDamageState.EnterState(Owner);
|
CurrentDamageState.EnterState(Owner);
|
||||||
|
|
||||||
currentstate = threshold;
|
currentstate = threshold;
|
||||||
|
|
||||||
|
Owner.RaiseEvent(new MobDamageStateChangedMessage(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fired when <see cref="SpeciesComponent.CurrentDamageState"/> changes.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class MobDamageStateChangedMessage : EntitySystemMessage
|
||||||
|
{
|
||||||
|
public MobDamageStateChangedMessage(SpeciesComponent species)
|
||||||
|
{
|
||||||
|
Species = species;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The species component that was changed.
|
||||||
|
/// </summary>
|
||||||
|
public SpeciesComponent Species { get; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
18
Content.Server/GameTicking/GamePresets/PresetDeathMatch.cs
Normal file
18
Content.Server/GameTicking/GamePresets/PresetDeathMatch.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using Content.Server.GameTicking.GameRules;
|
||||||
|
using Content.Server.Interfaces.GameTicking;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
|
|
||||||
|
namespace Content.Server.GameTicking.GamePresets
|
||||||
|
{
|
||||||
|
public sealed class PresetDeathMatch : GamePreset
|
||||||
|
{
|
||||||
|
#pragma warning disable 649
|
||||||
|
[Dependency] private readonly IGameTicker _gameTicker;
|
||||||
|
#pragma warning restore 649
|
||||||
|
|
||||||
|
public override void Start()
|
||||||
|
{
|
||||||
|
_gameTicker.AddGameRule<RuleDeathMatch>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
Content.Server/GameTicking/GameRule.cs
Normal file
18
Content.Server/GameTicking/GameRule.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
|
namespace Content.Server.GameTicking
|
||||||
|
{
|
||||||
|
[PublicAPI]
|
||||||
|
public abstract class GameRule
|
||||||
|
{
|
||||||
|
public virtual void Added()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Removed()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
112
Content.Server/GameTicking/GameRules/RuleDeathMatch.cs
Normal file
112
Content.Server/GameTicking/GameRules/RuleDeathMatch.cs
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
using Content.Server.GameObjects;
|
||||||
|
using Content.Server.Interfaces.Chat;
|
||||||
|
using Content.Server.Interfaces.GameTicking;
|
||||||
|
using Robust.Server.Interfaces.Player;
|
||||||
|
using Robust.Server.Player;
|
||||||
|
using Robust.Shared.Enums;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
|
using Timer = Robust.Shared.Timers.Timer;
|
||||||
|
|
||||||
|
namespace Content.Server.GameTicking.GameRules
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Simple GameRule that will do a free-for-all death match.
|
||||||
|
/// Kill everybody else to win.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class RuleDeathMatch : GameRule, IEntityEventSubscriber
|
||||||
|
{
|
||||||
|
private static readonly TimeSpan DeadCheckDelay = TimeSpan.FromSeconds(5);
|
||||||
|
|
||||||
|
#pragma warning disable 649
|
||||||
|
[Dependency] private readonly IPlayerManager _playerManager;
|
||||||
|
[Dependency] private readonly IEntityManager _entityManager;
|
||||||
|
[Dependency] private readonly IChatManager _chatManager;
|
||||||
|
[Dependency] private readonly IGameTicker _gameTicker;
|
||||||
|
#pragma warning restore 649
|
||||||
|
|
||||||
|
private CancellationTokenSource _checkTimerCancel;
|
||||||
|
|
||||||
|
public override void Added()
|
||||||
|
{
|
||||||
|
_chatManager.DispatchServerAnnouncement("The game is now a death match. Kill everybody else to win!");
|
||||||
|
|
||||||
|
_entityManager.SubscribeEvent<MobDamageStateChangedMessage>(_onMobDamageStateChanged, this);
|
||||||
|
_playerManager.PlayerStatusChanged += PlayerManagerOnPlayerStatusChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Removed()
|
||||||
|
{
|
||||||
|
base.Removed();
|
||||||
|
|
||||||
|
_entityManager.UnsubscribeEvent<MobDamageStateChangedMessage>(this);
|
||||||
|
_playerManager.PlayerStatusChanged -= PlayerManagerOnPlayerStatusChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void _onMobDamageStateChanged(object sender, MobDamageStateChangedMessage message)
|
||||||
|
{
|
||||||
|
_runDelayedCheck();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void _checkForWinner()
|
||||||
|
{
|
||||||
|
_checkTimerCancel = null;
|
||||||
|
|
||||||
|
IPlayerSession winner = null;
|
||||||
|
foreach (var playerSession in _playerManager.GetAllPlayers())
|
||||||
|
{
|
||||||
|
if (playerSession.AttachedEntity == null
|
||||||
|
|| !playerSession.AttachedEntity.TryGetComponent(out SpeciesComponent species))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!species.CurrentDamageState.IsConscious)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (winner != null)
|
||||||
|
{
|
||||||
|
// Found a second person alive, nothing decided yet!
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
winner = playerSession;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (winner == null)
|
||||||
|
{
|
||||||
|
_chatManager.DispatchServerAnnouncement("Everybody is dead, it's a stalemate!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// We have a winner!
|
||||||
|
_chatManager.DispatchServerAnnouncement($"{winner} wins the death match!");
|
||||||
|
}
|
||||||
|
|
||||||
|
_chatManager.DispatchServerAnnouncement($"Restarting in 10 seconds.");
|
||||||
|
|
||||||
|
Timer.Spawn(TimeSpan.FromSeconds(10), () => _gameTicker.RestartRound());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PlayerManagerOnPlayerStatusChanged(object sender, SessionStatusEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.NewStatus == SessionStatus.Disconnected)
|
||||||
|
{
|
||||||
|
_runDelayedCheck();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void _runDelayedCheck()
|
||||||
|
{
|
||||||
|
_checkTimerCancel?.Cancel();
|
||||||
|
_checkTimerCancel = new CancellationTokenSource();
|
||||||
|
|
||||||
|
Timer.Spawn(DeadCheckDelay, _checkForWinner, _checkTimerCancel.Token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -79,6 +79,8 @@ namespace Content.Server.GameTicking
|
|||||||
|
|
||||||
private readonly Random _spawnRandom = new Random();
|
private readonly Random _spawnRandom = new Random();
|
||||||
|
|
||||||
|
[ViewVariables] private readonly List<GameRule> _gameRules = new List<GameRule>();
|
||||||
|
|
||||||
#pragma warning disable 649
|
#pragma warning disable 649
|
||||||
[Dependency] private IEntityManager _entityManager;
|
[Dependency] private IEntityManager _entityManager;
|
||||||
[Dependency] private IMapManager _mapManager;
|
[Dependency] private IMapManager _mapManager;
|
||||||
@@ -88,6 +90,7 @@ namespace Content.Server.GameTicking
|
|||||||
[Dependency] private IPlayerManager _playerManager;
|
[Dependency] private IPlayerManager _playerManager;
|
||||||
[Dependency] private IChatManager _chatManager;
|
[Dependency] private IChatManager _chatManager;
|
||||||
[Dependency] private IServerNetManager _netManager;
|
[Dependency] private IServerNetManager _netManager;
|
||||||
|
[Dependency] private IDynamicTypeFactory _dynamicTypeFactory;
|
||||||
#pragma warning restore 649
|
#pragma warning restore 649
|
||||||
|
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
@@ -139,6 +142,8 @@ namespace Content.Server.GameTicking
|
|||||||
{
|
{
|
||||||
_roundStartTimeUtc = DateTime.UtcNow + TimeSpan.FromSeconds(LobbyDuration);
|
_roundStartTimeUtc = DateTime.UtcNow + TimeSpan.FromSeconds(LobbyDuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_sendStatusToAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,12 +155,12 @@ namespace Content.Server.GameTicking
|
|||||||
RunLevel = GameRunLevel.InRound;
|
RunLevel = GameRunLevel.InRound;
|
||||||
|
|
||||||
// TODO: Allow other presets to be selected.
|
// TODO: Allow other presets to be selected.
|
||||||
var preset = new PresetTraitor();
|
var preset = _dynamicTypeFactory.CreateInstance<PresetTraitor>();
|
||||||
preset.Start();
|
preset.Start();
|
||||||
|
|
||||||
foreach (var (playerSession, ready) in _playersInLobby.ToList())
|
foreach (var (playerSession, ready) in _playersInLobby.ToList())
|
||||||
{
|
{
|
||||||
if (!ready)
|
if (LobbyEnabled && !ready)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -219,6 +224,30 @@ namespace Content.Server.GameTicking
|
|||||||
_netManager.ServerSendMessage(_getStatusMsg(player), player.ConnectedClient);
|
_netManager.ServerSendMessage(_getStatusMsg(player), player.ConnectedClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public T AddGameRule<T>() where T : GameRule, new()
|
||||||
|
{
|
||||||
|
var instance = _dynamicTypeFactory.CreateInstance<T>();
|
||||||
|
|
||||||
|
_gameRules.Add(instance);
|
||||||
|
instance.Added();
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveGameRule(GameRule rule)
|
||||||
|
{
|
||||||
|
if (_gameRules.Contains(rule))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rule.Removed();
|
||||||
|
|
||||||
|
_gameRules.Remove(rule);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<GameRule> ActiveGameRules => _gameRules;
|
||||||
|
|
||||||
private IEntity _spawnPlayerMob()
|
private IEntity _spawnPlayerMob()
|
||||||
{
|
{
|
||||||
var entity = _entityManager.ForceSpawnEntityAt(PlayerPrototypeName, _getLateJoinSpawnPoint());
|
var entity = _entityManager.ForceSpawnEntityAt(PlayerPrototypeName, _getLateJoinSpawnPoint());
|
||||||
@@ -290,6 +319,25 @@ namespace Content.Server.GameTicking
|
|||||||
{
|
{
|
||||||
unCastData.ContentData().WipeMind();
|
unCastData.ContentData().WipeMind();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear up any game rules.
|
||||||
|
foreach (var rule in _gameRules)
|
||||||
|
{
|
||||||
|
rule.Removed();
|
||||||
|
}
|
||||||
|
|
||||||
|
_gameRules.Clear();
|
||||||
|
|
||||||
|
// Move everybody currently in the server to lobby.
|
||||||
|
foreach (var player in _playerManager.GetAllPlayers())
|
||||||
|
{
|
||||||
|
if (_playersInLobby.ContainsKey(player))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
_playerJoinLobby(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _preRoundSetup()
|
private void _preRoundSetup()
|
||||||
@@ -334,7 +382,6 @@ namespace Content.Server.GameTicking
|
|||||||
|
|
||||||
case SessionStatus.InGame:
|
case SessionStatus.InGame:
|
||||||
{
|
{
|
||||||
//TODO: Check for existing mob and re-attach
|
|
||||||
var data = session.ContentData();
|
var data = session.ContentData();
|
||||||
if (data.Mind == null)
|
if (data.Mind == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using Content.Server.GameTicking;
|
using Content.Server.GameTicking;
|
||||||
using Robust.Server.Interfaces.Player;
|
using Robust.Server.Interfaces.Player;
|
||||||
using Robust.Server.Player;
|
using Robust.Server.Player;
|
||||||
@@ -27,5 +28,10 @@ namespace Content.Server.Interfaces.GameTicking
|
|||||||
void MakeObserve(IPlayerSession player);
|
void MakeObserve(IPlayerSession player);
|
||||||
void MakeJoinGame(IPlayerSession player);
|
void MakeJoinGame(IPlayerSession player);
|
||||||
void ToggleReady(IPlayerSession player, bool ready);
|
void ToggleReady(IPlayerSession player, bool ready);
|
||||||
|
|
||||||
|
// GameRule system.
|
||||||
|
T AddGameRule<T>() where T : GameRule, new();
|
||||||
|
void RemoveGameRule(GameRule rule);
|
||||||
|
IEnumerable<GameRule> ActiveGameRules { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Submodule RobustToolbox updated: c83ad3ab94...0340cecd6d
Reference in New Issue
Block a user