Change components to use timer component (#2426)

* Change components to use timer component

* Fix old usages of tokens
This commit is contained in:
DrSmugleaf
2020-10-30 05:02:49 +01:00
committed by GitHub
parent c86c378198
commit 37e97ca89f
24 changed files with 59 additions and 35 deletions

View File

@@ -7,6 +7,7 @@ using Content.Shared.Physics;
using Robust.Client.Audio.Midi;
using Robust.Shared.Audio.Midi;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC;
@@ -173,7 +174,7 @@ namespace Content.Client.GameObjects.Components.Instruments
var renderer = _renderer;
// We dispose of the synth two seconds from now to allow the last notes to stop from playing.
Timer.Spawn(2000, () => { renderer?.Dispose(); });
Owner.SpawnTimer(2000, () => { renderer?.Dispose(); });
_renderer = null;
_midiEventBuffer.Clear();

View File

@@ -5,6 +5,7 @@ using Content.Shared.GameObjects.Components.Sound;
using Content.Shared.Physics;
using Robust.Client.GameObjects.EntitySystems;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.Interfaces.Random;
@@ -53,7 +54,7 @@ namespace Content.Client.GameObjects.Components.Sound
{
if (!schedule.Play) return;
Timer.Spawn((int) schedule.Delay + (_random.Next((int) schedule.RandomDelay)),() =>
Owner.SpawnTimer((int) schedule.Delay + (_random.Next((int) schedule.RandomDelay)),() =>
{
if (!schedule.Play) return; // We make sure this hasn't changed.
if (_audioSystem == null) _audioSystem = EntitySystem.Get<AudioSystem>();

View File

@@ -7,6 +7,7 @@ using Robust.Client.Interfaces.Graphics;
using Robust.Client.Interfaces.Graphics.Overlays;
using Robust.Client.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
@@ -83,7 +84,7 @@ namespace Content.Client.GameObjects.Components.Weapons
}
_cancelToken = new CancellationTokenSource();
Timer.Spawn((int) duration * 1000, DisableOverlay, _cancelToken.Token);
Owner.SpawnTimer((int) duration * 1000, DisableOverlay, _cancelToken.Token);
}
private void DisableOverlay()

View File

@@ -6,6 +6,7 @@ using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.GameObjects.EntitySystemMessages;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.Timing;
@@ -95,7 +96,7 @@ namespace Content.Client.GameObjects.EntitySystems
var newColor = Color.Red * originalColor;
sprite.Color = newColor;
Timer.Spawn(100, () =>
hitEntity.SpawnTimer(100, () =>
{
// Only reset back to the original color if something else didn't change the color in the mean time.
if (sprite.Color == newColor)

View File

@@ -16,6 +16,7 @@ using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
@@ -205,7 +206,7 @@ namespace Content.Server.GameObjects.Components.Atmos
Owner.PopupMessage(Loc.GetString("You stop, drop, and roll!"));
stunnable.Paralyze(2f);
Timer.Spawn(2000, () =>
Owner.SpawnTimer(2000, () =>
{
_resisting = false;
FireStacks -= 2f;

View File

@@ -29,6 +29,7 @@ using Robust.Shared.Audio;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
@@ -165,7 +166,7 @@ namespace Content.Server.GameObjects.Components.Disposal
_automaticEngageToken = new CancellationTokenSource();
Timer.Spawn(_automaticEngageTime, () =>
Owner.SpawnTimer(_automaticEngageTime, () =>
{
if (!TryFlush())
{
@@ -260,7 +261,7 @@ namespace Content.Server.GameObjects.Components.Disposal
if (Engaged && CanFlush())
{
Timer.Spawn(_flushDelay, () => TryFlush());
Owner.SpawnTimer(_flushDelay, () => TryFlush());
}
}

View File

@@ -13,6 +13,7 @@ using Robust.Server.GameObjects;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
@@ -310,7 +311,7 @@ namespace Content.Server.GameObjects.Components.Doors
PowerWiresPulsed = true;
_powerWiresPulsedTimerCancel.Cancel();
_powerWiresPulsedTimerCancel = new CancellationTokenSource();
Timer.Spawn(PowerWiresTimeout,
Owner.SpawnTimer(PowerWiresTimeout,
() => PowerWiresPulsed = false,
_powerWiresPulsedTimerCancel.Token);
break;

View File

@@ -23,6 +23,7 @@ using Robust.Server.GameObjects.EntitySystems;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Maths;
@@ -249,7 +250,7 @@ namespace Content.Server.GameObjects.Components.Doors
occluder.Enabled = false;
}
Timer.Spawn(OpenTimeOne, async () =>
Owner.SpawnTimer(OpenTimeOne, async () =>
{
if (Owner.TryGetComponent(out AirtightComponent? airtight))
{
@@ -319,7 +320,7 @@ namespace Content.Server.GameObjects.Components.Doors
stun.Paralyze(DoorStunTime);
// If we hit someone, open up after stun (opens right when stun ends)
Timer.Spawn(TimeSpan.FromSeconds(DoorStunTime) - OpenTimeOne - OpenTimeTwo, Open);
Owner.SpawnTimer(TimeSpan.FromSeconds(DoorStunTime) - OpenTimeOne - OpenTimeTwo, Open);
break;
}
}
@@ -402,7 +403,7 @@ namespace Content.Server.GameObjects.Components.Doors
occluder.Enabled = true;
}
Timer.Spawn(CloseTimeOne, async () =>
Owner.SpawnTimer(CloseTimeOne, async () =>
{
if (shouldCheckCrush && _canCrush)
{
@@ -435,7 +436,7 @@ namespace Content.Server.GameObjects.Components.Doors
return;
SetAppearance(DoorVisualState.Deny);
Timer.Spawn(DenyTime, () =>
Owner.SpawnTimer(DenyTime, () =>
{
SetAppearance(DoorVisualState.Closed);
}, _cancellationTokenSource.Token);

View File

@@ -14,6 +14,7 @@ using Robust.Server.GameObjects.EntitySystems;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
@@ -254,7 +255,7 @@ namespace Content.Server.GameObjects.Components.Fluids
_evaporationToken = new CancellationTokenSource();
// KYS to evaporate
Timer.Spawn(TimeSpan.FromSeconds(_evaporateTime), Evaporate, _evaporationToken.Token);
Owner.SpawnTimer(TimeSpan.FromSeconds(_evaporateTime), Evaporate, _evaporationToken.Token);
}
private void UpdateSlip()

View File

@@ -1,6 +1,7 @@
using Content.Server.GameObjects.Components.Items.Storage;
using Robust.Server.GameObjects.Components.Container;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Timers;
@@ -67,7 +68,7 @@ namespace Content.Server.GameObjects.Components.GUI
switch (message)
{
case ContainerContentsModifiedMessage contentsModified:
Timer.Spawn(0, DropIdAndPocketsIfWeNoLongerHaveAUniform);
Owner.SpawnTimer(0, DropIdAndPocketsIfWeNoLongerHaveAUniform);
break;
}
}

View File

@@ -26,6 +26,7 @@ using Robust.Server.GameObjects.EntitySystems;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
@@ -312,7 +313,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
(_currentCookTimerTime == (uint)recipeToCook.CookTime);
SetAppearance(MicrowaveVisualState.Cooking);
_audioSystem.PlayFromEntity(_startCookingSound, Owner, AudioParams.Default);
Timer.Spawn((int)(_currentCookTimerTime * _cookTimeMultiplier), (Action)(() =>
Owner.SpawnTimer((int)(_currentCookTimerTime * _cookTimeMultiplier), (Action)(() =>
{
if (_lostPower)
{

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Threading;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC;
@@ -67,7 +68,7 @@ namespace Content.Server.GameObjects.Components.Markers
{
TokenSource?.Cancel();
TokenSource = new CancellationTokenSource();
Timer.SpawnRepeating(TimeSpan.FromSeconds(IntervalSeconds), OnTimerFired, TokenSource.Token);
Owner.SpawnRepeatingTimer(TimeSpan.FromSeconds(IntervalSeconds), OnTimerFired, TokenSource.Token);
}
private void OnTimerFired()

View File

@@ -9,6 +9,7 @@ using Content.Shared.GameObjects.Components.Damage;
using Content.Shared.GameObjects.EntitySystems;
using Robust.Server.GameObjects.Components.UserInterface;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC;
@@ -135,7 +136,7 @@ namespace Content.Server.GameObjects.Components.Mobs
else
{
var spawnPosition = Owner.Transform.Coordinates;
Timer.Spawn(0, () =>
Owner.SpawnTimer(0, () =>
{
// Async this so that we don't throw if the grid we're on is being deleted.
var mapMan = IoCManager.Resolve<IMapManager>();

View File

@@ -5,6 +5,7 @@ using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.Interfaces.GameObjects.Components;
using NFluidsynth;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC;
@@ -101,7 +102,7 @@ namespace Content.Server.GameObjects.Components.Mobs
if (progress >= length)
{
Timer.Spawn(250, () => status.RemoveStatusEffect(StatusEffect.Stun), StatusRemoveCancellation.Token);
Owner.SpawnTimer(250, () => status.RemoveStatusEffect(StatusEffect.Stun), StatusRemoveCancellation.Token);
LastStun = null;
}
}

View File

@@ -6,6 +6,7 @@ using Robust.Server.GameObjects;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Serialization;
@@ -58,7 +59,7 @@ namespace Content.Server.GameObjects.Components.Portal
if (_aliveTime > 0)
{
Timer.Spawn(TimeSpan.FromSeconds(_aliveTime), () => Owner.Delete());
Owner.SpawnTimer(TimeSpan.FromSeconds(_aliveTime), () => Owner.Delete());
}
}
@@ -138,7 +139,7 @@ namespace Content.Server.GameObjects.Components.Portal
otherPortal.TryChangeState(PortalState.RecentlyTeleported);
Timer.Spawn(TimeSpan.FromSeconds(_overallPortalCooldown), () =>
Owner.SpawnTimer(TimeSpan.FromSeconds(_overallPortalCooldown), () =>
{
_onCooldown = false;
TryChangeState(PortalState.Pending);
@@ -168,7 +169,7 @@ namespace Content.Server.GameObjects.Components.Portal
// To stop spam teleporting. Could potentially look at adding a timer to flush this from the portal
ImmuneEntities.Add(entity);
_connectingTeleporter.GetComponent<PortalComponent>().ImmuneEntities.Add(entity);
Timer.Spawn(TimeSpan.FromSeconds(_individualPortalCooldown), () => ReleaseCooldown(entity));
Owner.SpawnTimer(TimeSpan.FromSeconds(_individualPortalCooldown), () => ReleaseCooldown(entity));
StartCooldown();
}

View File

@@ -8,6 +8,7 @@ using Robust.Server.GameObjects.EntitySystems;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Random;
@@ -125,14 +126,14 @@ namespace Content.Server.GameObjects.Components.Portal
return;
}
Timer.Spawn(TimeSpan.FromSeconds(_chargeTime), () => Teleport(user, mapCoords.Position));
Owner.SpawnTimer(TimeSpan.FromSeconds(_chargeTime), () => Teleport(user, mapCoords.Position));
StartCooldown();
}
public void StartCooldown()
{
SetState(ItemTeleporterState.Cooldown);
Timer.Spawn(TimeSpan.FromSeconds(_chargeTime + _cooldown), () => SetState(ItemTeleporterState.Off));
Owner.SpawnTimer(TimeSpan.FromSeconds(_chargeTime + _cooldown), () => SetState(ItemTeleporterState.Off));
if (_cooldownSound != null)
{
var soundPlayer = EntitySystem.Get<AudioSystem>();
@@ -212,7 +213,7 @@ namespace Content.Server.GameObjects.Components.Portal
}
// Seemed easier to just start the cd timer at the same time
Timer.Spawn(TimeSpan.FromSeconds(_chargeTime), () => Teleport(user, targetVector));
Owner.SpawnTimer(TimeSpan.FromSeconds(_chargeTime), () => Teleport(user, targetVector));
StartCooldown();
}

View File

@@ -3,6 +3,7 @@ using Content.Shared.Damage;
using Content.Shared.Physics;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.GameObjects.EntitySystemMessages;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
@@ -94,7 +95,7 @@ namespace Content.Server.GameObjects.Components.Projectiles
EntitySystem.Get<AudioSystem>().PlayAtCoords(_soundHitWall, user.Transform.Coordinates.Offset(offset));
}
Timer.Spawn((int) _deathTime.TotalMilliseconds, () =>
Owner.SpawnTimer((int) _deathTime.TotalMilliseconds, () =>
{
if (!Owner.Deleted)
{

View File

@@ -5,6 +5,7 @@ using Content.Shared.GameObjects.Components.Damage;
using Content.Shared.Physics;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Physics;
@@ -102,7 +103,7 @@ namespace Content.Server.GameObjects.Components.Projectiles
private void StartStopTimer()
{
Timer.Spawn((int) (DefaultThrowTime * 1000), MaybeStopThrow);
Owner.SpawnTimer((int) (DefaultThrowTime * 1000), MaybeStopThrow);
}
private void MaybeStopThrow()

View File

@@ -16,6 +16,7 @@ using Robust.Server.GameObjects.Components.UserInterface;
using Robust.Server.Interfaces.GameObjects;
using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.Timers;
using Robust.Shared.ViewVariables;
@@ -124,7 +125,7 @@ namespace Content.Server.GameObjects.Components.Research
State = LatheState.Producing;
SetAppearance(LatheVisualState.Producing);
Timer.Spawn(recipe.CompleteTime, () =>
Owner.SpawnTimer(recipe.CompleteTime, () =>
{
Producing = false;
_producingRecipe = null;
@@ -195,7 +196,7 @@ namespace Content.Server.GameObjects.Components.Research
break;
}
Timer.Spawn(InsertionTime, () =>
Owner.SpawnTimer(InsertionTime, () =>
{
State = LatheState.Base;
SetAppearance(LatheVisualState.Idle);

View File

@@ -7,6 +7,7 @@ using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
@@ -117,7 +118,7 @@ namespace Content.Server.GameObjects.Components.Stack
if (stack.AvailableSpace == 0)
{
Timer.Spawn(300, () => popupPos.PopupMessage(eventArgs.User, "Stack is now full."));
Owner.SpawnTimer(300, () => popupPos.PopupMessage(eventArgs.User, "Stack is now full."));
}
return true;

View File

@@ -2,6 +2,7 @@
using System.Threading;
using Content.Shared.GameObjects.Components.Items;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC;
using Robust.Shared.Serialization;
@@ -46,7 +47,7 @@ namespace Content.Server.GameObjects.Components.Timing
cancellationTokenSource = new CancellationTokenSource();
Timer.Spawn(TimeSpan.FromSeconds(Delay), () => ActiveDelay = false, cancellationTokenSource.Token);
Owner.SpawnTimer(TimeSpan.FromSeconds(Delay), () => ActiveDelay = false, cancellationTokenSource.Token);
_lastUseTime = IoCManager.Resolve<IGameTiming>().CurTime;

View File

@@ -14,6 +14,7 @@ using Robust.Server.GameObjects.EntitySystems;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC;
@@ -184,7 +185,7 @@ namespace Content.Server.GameObjects.Components.VendingMachines
UserInterface?.SendMessage(new VendingMachineInventoryMessage(Inventory));
TrySetVisualState(VendingMachineVisualState.Eject);
Timer.Spawn(_animationDuration, () =>
Owner.SpawnTimer(_animationDuration, () =>
{
_ejecting = false;
TrySetVisualState(VendingMachineVisualState.Normal);
@@ -198,7 +199,7 @@ namespace Content.Server.GameObjects.Components.VendingMachines
{
TrySetVisualState(VendingMachineVisualState.Deny);
//TODO: This duration should be a distinct value specific to the deny animation
Timer.Spawn(_animationDuration, () =>
Owner.SpawnTimer(_animationDuration, () =>
{
TrySetVisualState(VendingMachineVisualState.Normal);
});

View File

@@ -8,6 +8,7 @@ using Robust.Server.GameObjects;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
@@ -107,7 +108,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
int animLayer = sprite.AddLayerWithState("flashing");
_flashing = true;
Timer.Spawn(400, () =>
Owner.SpawnTimer(400, () =>
{
sprite.RemoveLayer(animLayer);
_flashing = false;

View File

@@ -4,6 +4,7 @@ using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Timers;
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC;
using Robust.Shared.Serialization;
@@ -225,7 +226,7 @@ namespace Content.Shared.GameObjects.Components.Mobs
}
_canHelp = false;
Timer.Spawn((int) _helpInterval * 1000, () => _canHelp = true);
Owner.SpawnTimer((int) _helpInterval * 1000, () => _canHelp = true);
KnockdownTimer -= _helpKnockdownRemove;