private void OnHandleState(EntityUid uid, StatusEffectsComponent component, ref ComponentHandleState args) { if (args.Current is not StatusEffectsComponentState state) { return; } component.AllowedEffects = new(state.AllowedEffects); // Remove non-existent effects. foreach (var effect in component.ActiveEffects.Keys) { if (!state.ActiveEffects.ContainsKey(effect)) { TryRemoveStatusEffect(uid, effect, component); } } foreach (var effect in state.ActiveEffects) { // don't bother with anything if we already have it if (component.ActiveEffects.ContainsKey(effect.Key)) { component.ActiveEffects[effect.Key] = effect.Value; continue; } var time = effect.Value.Cooldown.Item2 - effect.Value.Cooldown.Item1; //TODO: Not sure how to handle refresh here. TryAddStatusEffect(uid, effect.Key, time, true); } }
private void OnHandleState(EntityUid uid, StatusEffectsComponent component, ref ComponentHandleState args) { if (args.Current is StatusEffectsComponentState state) { component.AllowedEffects = state.AllowedEffects; foreach (var effect in state.ActiveEffects) { // don't bother with anything if we already have it if (component.ActiveEffects.ContainsKey(effect.Key)) { component.ActiveEffects[effect.Key] = effect.Value; continue; } var time = effect.Value.Cooldown.Item2 - effect.Value.Cooldown.Item1; TryAddStatusEffect(uid, effect.Key, time); } } }
private void OnGetState(EntityUid uid, StatusEffectsComponent component, ref ComponentGetState args) { args.State = new StatusEffectsComponentState(component.ActiveEffects, component.AllowedEffects); }
/// <summary> /// Finds the maximum cooldown among all status effects with the same alert /// </summary> /// <remarks> /// This is mostly for stuns, since Stun and Knockdown share an alert key. Other times this pretty much /// will not be useful. /// </remarks> private (TimeSpan, TimeSpan)? GetAlertCooldown(EntityUid uid, AlertType alert, StatusEffectsComponent status) { (TimeSpan, TimeSpan)? maxCooldown = null; foreach (var kvp in status.ActiveEffects) { var proto = _prototypeManager.Index <StatusEffectPrototype>(kvp.Key); if (proto.Alert == alert) { if (maxCooldown == null || kvp.Value.Cooldown.Item2 > maxCooldown.Value.Item2) { maxCooldown = kvp.Value.Cooldown; } } } return(maxCooldown); }
private void OnGetState(EntityUid uid, StatusEffectsComponent component, ref ComponentGetState args) { // Using new(...) To avoid mispredictions due to MergeImplicitData. This will mean the server-side code is // slightly slower, and really this function should just be overridden by the client... args.State = new StatusEffectsComponentState(new(component.ActiveEffects), new(component.AllowedEffects)); }