Cooldown for status effects (#1109)
This commit is contained in:
committed by
GitHub
parent
1587efbe29
commit
cb5acf7cd3
@@ -66,21 +66,21 @@ namespace Content.Server.GameObjects
|
||||
throw new InvalidOperationException(); //these should all be below the crit value, possibly going over multiple thresholds at once?
|
||||
}
|
||||
var modifier = totaldamage / (critvalue / normalstates); //integer division floors towards zero
|
||||
statusEffectsComponent?.ChangeStatus(StatusEffect.Health,
|
||||
statusEffectsComponent?.ChangeStatusEffectIcon(StatusEffect.Health,
|
||||
"/Textures/Mob/UI/Human/human" + modifier + ".png");
|
||||
|
||||
overlayComponent?.ChangeOverlay(ScreenEffects.None);
|
||||
|
||||
return;
|
||||
case ThresholdType.Critical:
|
||||
statusEffectsComponent?.ChangeStatus(
|
||||
statusEffectsComponent?.ChangeStatusEffectIcon(
|
||||
StatusEffect.Health,
|
||||
"/Textures/Mob/UI/Human/humancrit-0.png");
|
||||
overlayComponent?.ChangeOverlay(ScreenEffects.GradientCircleMask);
|
||||
|
||||
return;
|
||||
case ThresholdType.Death:
|
||||
statusEffectsComponent?.ChangeStatus(
|
||||
statusEffectsComponent?.ChangeStatusEffectIcon(
|
||||
StatusEffect.Health,
|
||||
"/Textures/Mob/UI/Human/humandead.png");
|
||||
overlayComponent?.ChangeOverlay(ScreenEffects.CircleMask);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.GameObjects.Components.Mobs;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -8,25 +9,48 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
[ComponentReference(typeof(SharedStatusEffectsComponent))]
|
||||
public sealed class ServerStatusEffectsComponent : SharedStatusEffectsComponent
|
||||
{
|
||||
private readonly Dictionary<StatusEffect, string> _statusEffects = new Dictionary<StatusEffect, string>();
|
||||
private readonly Dictionary<StatusEffect, StatusEffectStatus> _statusEffects = new Dictionary<StatusEffect, StatusEffectStatus>();
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
return new StatusEffectComponentState(_statusEffects);
|
||||
}
|
||||
|
||||
public void ChangeStatus(StatusEffect effect, string icon)
|
||||
public void ChangeStatusEffectIcon(StatusEffect effect, string icon)
|
||||
{
|
||||
if (_statusEffects.TryGetValue(effect, out string value) && value == icon)
|
||||
if (_statusEffects.TryGetValue(effect, out var value) && value.Icon == icon)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_statusEffects[effect] = icon;
|
||||
_statusEffects[effect] = new StatusEffectStatus()
|
||||
{Icon = icon, Cooldown = value.Cooldown};
|
||||
Dirty();
|
||||
}
|
||||
|
||||
public void RemoveStatus(StatusEffect effect)
|
||||
public void ChangeStatusEffectCooldown(StatusEffect effect, ValueTuple<TimeSpan, TimeSpan> cooldown)
|
||||
{
|
||||
if (_statusEffects.TryGetValue(effect, out var value)
|
||||
&& value.Cooldown == cooldown)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_statusEffects[effect] = new StatusEffectStatus()
|
||||
{
|
||||
Icon = value.Icon, Cooldown = cooldown
|
||||
};
|
||||
Dirty();
|
||||
}
|
||||
|
||||
public void ChangeStatusEffect(StatusEffect effect, string icon, ValueTuple<TimeSpan, TimeSpan>? cooldown)
|
||||
{
|
||||
_statusEffects[effect] = new StatusEffectStatus()
|
||||
{Icon = icon, Cooldown = cooldown};
|
||||
Dirty();
|
||||
}
|
||||
|
||||
public void RemoveStatusEffect(StatusEffect effect)
|
||||
{
|
||||
if (!_statusEffects.Remove(effect))
|
||||
{
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace Content.Server.GameObjects
|
||||
{
|
||||
base.OnRemove();
|
||||
Owner.TryGetComponent(out ServerStatusEffectsComponent statusEffectsComponent);
|
||||
statusEffectsComponent?.RemoveStatus(StatusEffect.Health);
|
||||
statusEffectsComponent?.RemoveStatusEffect(StatusEffect.Health);
|
||||
|
||||
Owner.TryGetComponent(out ServerOverlayEffectsComponent overlayEffectsComponent);
|
||||
overlayEffectsComponent?.ChangeOverlay(ScreenEffects.None);
|
||||
|
||||
@@ -6,6 +6,7 @@ using Content.Server.Interfaces.GameObjects;
|
||||
using Content.Server.Mobs;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.GameObjects.Components.Mobs;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Shared.Audio;
|
||||
@@ -15,6 +16,7 @@ using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Timers;
|
||||
using Robust.Shared.Interfaces.Timing;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
@@ -39,7 +41,7 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
[ViewVariables]
|
||||
public TimeSpan? StunEnd => _lastStun == null
|
||||
? (TimeSpan?) null
|
||||
: _gameTiming.CurTime + TimeSpan.FromSeconds(_stunnedTimer + _knockdownTimer + _slowdownTimer);
|
||||
: _gameTiming.CurTime + (TimeSpan.FromSeconds(Math.Max(_stunnedTimer, Math.Max(_knockdownTimer, _slowdownTimer))));
|
||||
|
||||
private const int StunLevels = 8;
|
||||
|
||||
@@ -56,7 +58,8 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
|
||||
private float _walkModifierOverride = 0f;
|
||||
private float _runModifierOverride = 0f;
|
||||
private readonly string[] _texturesStunOverlay = new string[StunLevels];
|
||||
private string _stunTexture;
|
||||
private CancellationTokenSource _statusRemoveCancellation = new CancellationTokenSource();
|
||||
|
||||
[ViewVariables] public bool Stunned => _stunnedTimer > 0f;
|
||||
[ViewVariables] public bool KnockedDown => _knockdownTimer > 0f;
|
||||
@@ -73,16 +76,7 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
serializer.DataField(ref _slowdownCap, "slowdownCap", 20f);
|
||||
serializer.DataField(ref _helpInterval, "helpInterval", 1f);
|
||||
serializer.DataField(ref _helpKnockdownRemove, "helpKnockdownRemove", 1f);
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
for (var i = 0; i < StunLevels; i++)
|
||||
{
|
||||
_texturesStunOverlay[i] = $"/Textures/UserInterface/Inventory/cooldown-{i}.png";
|
||||
}
|
||||
serializer.DataField(ref _stunTexture, "stunTexture", "/Textures/Objects/Melee/stunbaton.rsi/stunbaton_off.png");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -100,6 +94,8 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
|
||||
_stunnedTimer = seconds;
|
||||
_lastStun = _gameTiming.CurTime;
|
||||
|
||||
SetStatusEffect();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -117,6 +113,8 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
|
||||
_knockdownTimer = seconds;
|
||||
_lastStun = _gameTiming.CurTime;
|
||||
|
||||
SetStatusEffect();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -150,6 +148,8 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
|
||||
if(Owner.TryGetComponent(out MovementSpeedModifierComponent movement))
|
||||
movement.RefreshMovementSpeedModifiers();
|
||||
|
||||
SetStatusEffect();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -174,9 +174,21 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
|
||||
_knockdownTimer -= _helpKnockdownRemove;
|
||||
|
||||
SetStatusEffect();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void SetStatusEffect()
|
||||
{
|
||||
if (!Owner.TryGetComponent(out ServerStatusEffectsComponent status))
|
||||
return;
|
||||
|
||||
status.ChangeStatusEffect(StatusEffect.Stun, _stunTexture, (StunStart == null || StunEnd == null) ? default : (StunStart.Value, StunEnd.Value));
|
||||
_statusRemoveCancellation.Cancel();
|
||||
_statusRemoveCancellation = new CancellationTokenSource();
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
{
|
||||
if (Stunned)
|
||||
@@ -214,33 +226,20 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
}
|
||||
}
|
||||
|
||||
if (!_lastStun.HasValue || !StunEnd.HasValue || !Owner.TryGetComponent(out ServerStatusEffectsComponent status))
|
||||
if (!StunStart.HasValue || !StunEnd.HasValue || !Owner.TryGetComponent(out ServerStatusEffectsComponent status))
|
||||
return;
|
||||
|
||||
var start = _lastStun.Value;
|
||||
var start = StunStart.Value;
|
||||
var end = StunEnd.Value;
|
||||
|
||||
var length = (end - start).TotalSeconds;
|
||||
var progress = (_gameTiming.CurTime - start).TotalSeconds;
|
||||
var ratio = (float)(progress / length);
|
||||
|
||||
var textureIndex = CalculateStunLevel(ratio);
|
||||
if (textureIndex == StunLevels)
|
||||
if (progress >= length)
|
||||
{
|
||||
Timer.Spawn(250, () => status.RemoveStatusEffect(StatusEffect.Stun), _statusRemoveCancellation.Token);
|
||||
_lastStun = null;
|
||||
status.RemoveStatus(StatusEffect.Stun);
|
||||
}
|
||||
else
|
||||
{
|
||||
status.ChangeStatus(StatusEffect.Stun, _texturesStunOverlay[textureIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
private static int CalculateStunLevel(float stunValue)
|
||||
{
|
||||
var val = stunValue.Clamp(0, 1);
|
||||
val *= StunLevels;
|
||||
return (int)Math.Floor(val);
|
||||
}
|
||||
|
||||
#region ActionBlockers
|
||||
|
||||
Reference in New Issue
Block a user