Make DoAfter visible to all (#2183)

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2020-10-10 22:59:17 +11:00
committed by GitHub
parent 5aa866548b
commit aba9b0e3f9
5 changed files with 217 additions and 227 deletions

View File

@@ -2,11 +2,7 @@
using System.Collections.Generic;
using Content.Server.GameObjects.EntitySystems.DoAfter;
using Content.Shared.GameObjects.Components;
using Robust.Server.GameObjects;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Network;
namespace Content.Server.GameObjects.Components
{
@@ -20,30 +16,15 @@ namespace Content.Server.GameObjects.Components
// we'll just send them the index. Doesn't matter if it wraps around.
private byte _runningIndex;
public override void HandleMessage(ComponentMessage message, IComponent? component)
public override ComponentState GetComponentState()
{
base.HandleMessage(message, component);
switch (message)
{
case PlayerAttachedMsg _:
UpdateClient();
break;
}
}
// Only sending data to the relevant client (at least, other clients don't need to know about do_after for now).
private void UpdateClient()
{
if (!TryGetConnectedClient(out var connectedClient))
{
return;
}
foreach (var (doAfter, id) in _doAfters)
var toAdd = new List<ClientDoAfter>();
foreach (var doAfter in DoAfters)
{
// THE ALMIGHTY PYRAMID
var message = new DoAfterMessage(
id,
var clientDoAfter = new ClientDoAfter(
_doAfters[doAfter],
doAfter.UserGrid,
doAfter.TargetGrid,
doAfter.StartTime,
@@ -51,65 +32,27 @@ namespace Content.Server.GameObjects.Components
doAfter.EventArgs.BreakOnUserMove,
doAfter.EventArgs.BreakOnTargetMove,
doAfter.EventArgs.Target?.Uid ?? EntityUid.Invalid);
SendNetworkMessage(message, connectedClient);
}
}
private bool TryGetConnectedClient(out INetChannel? connectedClient)
{
connectedClient = null;
if (!Owner.TryGetComponent(out IActorComponent? actorComponent))
{
return false;
toAdd.Add(clientDoAfter);
}
connectedClient = actorComponent.playerSession.ConnectedClient;
if (!connectedClient.IsConnected)
{
return false;
}
return true;
return new DoAfterComponentState(toAdd);
}
public void Add(DoAfter doAfter)
{
_doAfters.Add(doAfter, _runningIndex);
if (TryGetConnectedClient(out var connectedClient))
{
var message = new DoAfterMessage(
_runningIndex,
doAfter.UserGrid,
doAfter.TargetGrid,
doAfter.StartTime,
doAfter.EventArgs.Delay,
doAfter.EventArgs.BreakOnUserMove,
doAfter.EventArgs.BreakOnTargetMove,
doAfter.EventArgs.Target?.Uid ?? EntityUid.Invalid);
SendNetworkMessage(message, connectedClient);
}
_runningIndex++;
Dirty();
}
public void Cancelled(DoAfter doAfter)
{
if (!_doAfters.TryGetValue(doAfter, out var index))
{
return;
}
if (TryGetConnectedClient(out var connectedClient))
{
var message = new CancelledDoAfterMessage(index);
SendNetworkMessage(message, connectedClient);
}
_doAfters.Remove(doAfter);
SendNetworkMessage(new CancelledDoAfterMessage(index));
}
/// <summary>
@@ -120,9 +63,7 @@ namespace Content.Server.GameObjects.Components
public void Finished(DoAfter doAfter)
{
if (!_doAfters.ContainsKey(doAfter))
{
return;
}
_doAfters.Remove(doAfter);
}